Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-2196 Add field 'From' to composer #2306

Merged
merged 7 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/lib/presentation/extensions/color_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ extension AppColor on Color {
static const colorButtonBorder = Color(0xFFD5D7E0);
static const colorScrollbarTrackColor = Color(0xFFF4EFF4);
static const colorScrollbarThumbColor = Color(0xFFD8E1EB);
static const colorDropDownTitleComposer = Color(0xFF79747E);
static const colorDropDownItemTitleComposer = Color(0xFF0A0A0A);

static const mapGradientColor = [
[Color(0xFF21D4FD), Color(0xFFB721FF)],
Expand Down
74 changes: 62 additions & 12 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:collection/collection.dart';
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:file_picker/file_picker.dart';
import 'package:filesize/filesize.dart';
import 'package:fk_user_agent/fk_user_agent.dart';
Expand Down Expand Up @@ -58,6 +59,7 @@ import 'package:tmail_ui_user/features/composer/presentation/model/save_to_draft
import 'package:tmail_ui_user/features/composer/presentation/model/save_to_draft_view_event.dart';
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
import 'package:tmail_ui_user/features/composer/presentation/styles/composer_style.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/from_composer_bottom_sheet_builder.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
import 'package:tmail_ui_user/features/email/domain/state/transform_html_email_content_state.dart';
Expand Down Expand Up @@ -109,9 +111,12 @@ class ComposerController extends BaseController {
final bccAddressExpandMode = ExpandMode.EXPAND.obs;
final emailContentsViewState = Rxn<Either<Failure, Success>>();
final hasRequestReadReceipt = false.obs;
final fromRecipientState = PrefixRecipientState.disabled.obs;
final ccRecipientState = PrefixRecipientState.disabled.obs;
final bccRecipientState = PrefixRecipientState.disabled.obs;
final isSendEmailLoading = false.obs;
final identitySelected = Rxn<Identity>();
final listFromIdentities = RxList<Identity>();

final LocalFilePickerInteractor _localFilePickerInteractor;
final DeviceInfoPlugin _deviceInfoPlugin;
Expand All @@ -136,23 +141,27 @@ class ComposerController extends BaseController {
final toEmailAddressController = TextEditingController();
final ccEmailAddressController = TextEditingController();
final bccEmailAddressController = TextEditingController();
final searchIdentitiesInputController = TextEditingController();

final GlobalKey<TagsEditorState> keyToEmailTagEditor = GlobalKey<TagsEditorState>();
final GlobalKey<TagsEditorState> keyCcEmailTagEditor = GlobalKey<TagsEditorState>();
final GlobalKey<TagsEditorState> keyBccEmailTagEditor = GlobalKey<TagsEditorState>();
final GlobalKey headerEditorMobileWidgetKey = GlobalKey();
final GlobalKey<DropdownButton2State> identityDropdownKey = GlobalKey<DropdownButton2State>();
final double defaultPaddingCoordinateYCursorEditor = 8;

FocusNode? subjectEmailInputFocusNode;
FocusNode? toAddressFocusNode;
FocusNode? ccAddressFocusNode;
FocusNode? bccAddressFocusNode;
FocusNode? searchIdentitiesFocusNode;

final RichTextController keyboardRichTextController = RichTextController();

final ScrollController scrollController = ScrollController();
final ScrollController scrollControllerEmailAddress = ScrollController();
final ScrollController scrollControllerAttachment = ScrollController();
final ScrollController scrollControllerIdentities = ScrollController();

final _saveToDraftEventController = StreamController<SaveToDraftViewEvent>();
Stream<SaveToDraftViewEvent> get _saveToDraftEventStream => _saveToDraftEventController.stream;
Expand All @@ -164,7 +173,6 @@ class ComposerController extends BaseController {
double? maxWithEditor;
EmailId? _emailIdEditing;
bool isAttachmentCollapsed = false;
Identity? identitySelected;

late Worker uploadInlineImageWorker;
late Worker dashboardViewStateWorker;
Expand Down Expand Up @@ -227,6 +235,8 @@ class ComposerController extends BaseController {
ccAddressFocusNode = null;
bccAddressFocusNode?.dispose();
bccAddressFocusNode = null;
searchIdentitiesFocusNode?.dispose();
searchIdentitiesFocusNode = null;
subjectEmailInputController.dispose();
toEmailAddressController.dispose();
ccEmailAddressController.dispose();
Expand All @@ -238,6 +248,7 @@ class ComposerController extends BaseController {
scrollControllerEmailAddress.removeListener(_scrollControllerEmailAddressListener);
scrollControllerEmailAddress.dispose();
scrollControllerAttachment.dispose();
scrollControllerIdentities.dispose();
_saveToDraftStreamSubscription.cancel();
_saveToDraftEventController.close();
super.dispose();
Expand Down Expand Up @@ -366,6 +377,7 @@ class ComposerController extends BaseController {
);
ccAddressFocusNode = FocusNode();
bccAddressFocusNode = FocusNode();
searchIdentitiesFocusNode = FocusNode();

subjectEmailInputFocusNode?.addListener(() {
log('ComposerController::createFocusNodeInput():subjectEmailInputFocusNode: ${subjectEmailInputFocusNode?.hasFocus}');
Expand Down Expand Up @@ -414,7 +426,7 @@ class ComposerController extends BaseController {
}

void onLoadCompletedMobileEditorAction(HtmlEditorApi editorApi, WebUri? url) {
if (identitySelected == null) {
if (identitySelected.value == null) {
_getAllIdentities();
}
}
Expand Down Expand Up @@ -552,10 +564,13 @@ class ComposerController extends BaseController {
void _handleGetAllIdentitiesSuccess(GetAllIdentitiesSuccess success) async {
final listIdentitiesMayDeleted = success.identities?.toListMayDeleted() ?? [];
if (listIdentitiesMayDeleted.isNotEmpty) {
listFromIdentities.value = listIdentitiesMayDeleted;
await _selectIdentity(listIdentitiesMayDeleted.first);
}

_autoFocusFieldWhenLauncher();
if (fromRecipientState.value == PrefixRecipientState.disabled) {
_autoFocusFieldWhenLauncher();
}
}

void _initEmailAddress({
Expand Down Expand Up @@ -663,17 +678,17 @@ class ComposerController extends BaseController {
}
) async {
Set<EmailAddress> listFromEmailAddress = {EmailAddress(null, userProfile.email)};
if (identitySelected?.email?.isNotEmpty == true) {
if (identitySelected.value?.email?.isNotEmpty == true) {
listFromEmailAddress = {
EmailAddress(
identitySelected?.name,
identitySelected?.email
identitySelected.value?.name,
identitySelected.value?.email
)
};
}
Set<EmailAddress> listReplyToEmailAddress = {EmailAddress(null, userProfile.email)};
if (identitySelected?.replyTo?.isNotEmpty == true) {
listReplyToEmailAddress = identitySelected!.replyTo!;
if (identitySelected.value?.replyTo?.isNotEmpty == true) {
listReplyToEmailAddress = identitySelected.value!.replyTo!;
}

final attachments = <EmailBodyPart>{};
Expand Down Expand Up @@ -931,7 +946,7 @@ class ComposerController extends BaseController {
: EmailRequest(
email: createdEmail,
sentMailboxId: mailboxDashBoardController.mapDefaultMailboxIdByRole[PresentationMailbox.roleSent],
identityId: identitySelected?.id,
identityId: identitySelected.value?.id,
emailIdDestroyed: arguments.emailActionType == EmailActionType.editDraft
? arguments.presentationEmail?.id
: null,
Expand Down Expand Up @@ -1502,6 +1517,9 @@ class ComposerController extends BaseController {

void addEmailAddressType(PrefixEmailAddress prefixEmailAddress) {
switch(prefixEmailAddress) {
case PrefixEmailAddress.from:
fromRecipientState.value = PrefixRecipientState.enabled;
break;
case PrefixEmailAddress.cc:
ccRecipientState.value = PrefixRecipientState.enabled;
break;
Expand Down Expand Up @@ -1672,8 +1690,8 @@ class ComposerController extends BaseController {
}

Future<void> _selectIdentity(Identity? newIdentity) async {
final formerIdentity = identitySelected;
identitySelected = newIdentity;
final formerIdentity = identitySelected.value;
identitySelected.value = newIdentity;
if (newIdentity != null) {
await _applyIdentityForAllFieldComposer(formerIdentity, newIdentity);
}
Expand Down Expand Up @@ -1927,7 +1945,7 @@ class ComposerController extends BaseController {
richTextWebController.editorController.setFullScreen();
onChangeTextEditorWeb(initContent);
richTextWebController.setEnableCodeView();
if (identitySelected == null) {
if (identitySelected.value == null) {
_getAllIdentities();
}
}
Expand Down Expand Up @@ -2135,4 +2153,36 @@ class ComposerController extends BaseController {
}
}
}

Future<void> onChangeIdentity(Identity? newIdentity) async {
await _selectIdentity(newIdentity);
}

void _searchIdentities(String searchText) {
if (searchText.isEmpty) {
_getAllIdentities();
} else {
listFromIdentities.value = listFromIdentities
.where((identity) => identity.name?.toLowerCase().contains(searchText.toLowerCase()) == true)
.toList();
}
}

void openSelectIdentityBottomSheet(BuildContext context) {
(
FromComposerBottomSheetBuilder(
context,
_imagePaths,
listFromIdentities,
scrollControllerIdentities,
searchIdentitiesInputController
)
..onCloseAction(() => popBack())
..onChangeIdentityAction((identity) {
onChangeIdentity(identity);
popBack();
})
..onTextSearchChangedAction((searchText) => _searchIdentities(searchText))
).build();
}
}
23 changes: 23 additions & 0 deletions lib/features/composer/presentation/composer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import 'package:tmail_ui_user/features/composer/presentation/styles/mobile_app_b
import 'package:tmail_ui_user/features/composer/presentation/view/mobile/mobile_container_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/view/mobile/mobile_editor_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/view/mobile/tablet_container_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/from_composer_mobile_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/from_composer_drop_down_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/insert_image_loading_bar_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/mobile_attachment_composer_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/app_bar_composer_widget.dart';
Expand Down Expand Up @@ -98,9 +100,19 @@ class ComposerView extends GetWidget<ComposerController> {
children: [
Obx(() => Column(
children: [
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
FromComposerMobileWidget(
selectedIdentity: controller.identitySelected.value,
imagePaths: _imagePaths,
responsiveUtils: _responsiveUtils,
margin: ComposerStyle.mobileRecipientMargin,
padding: ComposerStyle.mobileRecipientPadding,
onTap: () => controller.openSelectIdentityBottomSheet(context)
),
RecipientComposerWidget(
prefix: PrefixEmailAddress.to,
listEmailAddress: controller.listToEmailAddress,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
expandMode: controller.toAddressExpandMode.value,
Expand Down Expand Up @@ -238,9 +250,20 @@ class ComposerView extends GetWidget<ComposerController> {
children: [
Obx(() => Column(
children: [
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
FromComposerDropDownWidget(
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
padding: ComposerStyle.mobileRecipientPadding,
margin: ComposerStyle.mobileRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
),
RecipientComposerWidget(
prefix: PrefixEmailAddress.to,
listEmailAddress: controller.listToEmailAddress,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
expandMode: controller.toAddressExpandMode.value,
Expand Down
37 changes: 37 additions & 0 deletions lib/features/composer/presentation/composer_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:tmail_ui_user/features/composer/presentation/view/web/desktop_re
import 'package:tmail_ui_user/features/composer/presentation/view/web/mobile_responsive_container_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/view/web/tablet_responsive_container_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/view/web/web_editor_view.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/mobile/from_composer_mobile_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/from_composer_drop_down_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/insert_image_loading_bar_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/desktop_app_bar_composer_widget.dart';
import 'package:tmail_ui_user/features/composer/presentation/widgets/web/attachment_composer_widget.dart';
Expand Down Expand Up @@ -72,9 +74,22 @@ class ComposerView extends GetWidget<ComposerController> {
controller: controller.scrollControllerEmailAddress,
child: Obx(() => Column(
children: [
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
Tooltip(
message: controller.identitySelected.value?.email ?? '',
child: FromComposerMobileWidget(
selectedIdentity: controller.identitySelected.value,
imagePaths: _imagePaths,
responsiveUtils: _responsiveUtils,
margin: ComposerStyle.mobileRecipientMargin,
padding: ComposerStyle.mobileRecipientPadding,
onTap: () => controller.openSelectIdentityBottomSheet(context)
),
),
RecipientComposerWidget(
prefix: PrefixEmailAddress.to,
listEmailAddress: controller.listToEmailAddress,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
expandMode: controller.toAddressExpandMode.value,
Expand Down Expand Up @@ -242,9 +257,20 @@ class ComposerView extends GetWidget<ComposerController> {
controller: controller.scrollControllerEmailAddress,
child: Obx(() => Column(
children: [
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
FromComposerDropDownWidget(
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
padding: ComposerStyle.desktopRecipientPadding,
margin: ComposerStyle.desktopRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
),
RecipientComposerWidget(
prefix: PrefixEmailAddress.to,
listEmailAddress: controller.listToEmailAddress,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
expandMode: controller.toAddressExpandMode.value,
Expand Down Expand Up @@ -464,9 +490,20 @@ class ComposerView extends GetWidget<ComposerController> {
controller: controller.scrollControllerEmailAddress,
child: Obx(() => Column(
children: [
if (controller.fromRecipientState.value == PrefixRecipientState.enabled)
FromComposerDropDownWidget(
items: controller.listFromIdentities,
itemSelected: controller.identitySelected.value,
dropdownKey: controller.identityDropdownKey,
imagePaths: _imagePaths,
padding: ComposerStyle.tabletRecipientPadding,
margin: ComposerStyle.tabletRecipientMargin,
onChangeIdentity: controller.onChangeIdentity,
),
RecipientComposerWidget(
prefix: PrefixEmailAddress.to,
listEmailAddress: controller.listToEmailAddress,
fromState: controller.fromRecipientState.value,
ccState: controller.ccRecipientState.value,
bccState: controller.bccRecipientState.value,
expandMode: controller.toAddressExpandMode.value,
Expand Down
Loading
Loading