TF-4195 Implement add a Label to an email
This commit is contained in:
@@ -44,16 +44,16 @@ class PopupSubmenuController {
|
||||
|
||||
_submenuEntry = OverlayEntry(
|
||||
builder: (_) {
|
||||
return Positioned(
|
||||
left: finalLeft,
|
||||
return PositionedDirectional(
|
||||
start: finalLeft,
|
||||
top: anchor.top,
|
||||
child: MouseRegion(
|
||||
onExit: (_) => hide(),
|
||||
child: Material(
|
||||
elevation: 8,
|
||||
color: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: submenuWidth,
|
||||
@@ -66,7 +66,7 @@ class PopupSubmenuController {
|
||||
},
|
||||
);
|
||||
|
||||
Overlay.of(context).insert(_submenuEntry!);
|
||||
Overlay.maybeOf(context)?.insert(_submenuEntry!);
|
||||
}
|
||||
|
||||
void hide() {
|
||||
|
||||
@@ -35,6 +35,7 @@ import 'package:tmail_ui_user/features/email/domain/model/event_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/send_receipt_to_sender_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/view_entire_message_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_accept_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_counter_accept_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_maybe_state.dart';
|
||||
@@ -48,6 +49,7 @@ import 'package:tmail_ui_user/features/email/domain/state/parse_calendar_event_s
|
||||
import 'package:tmail_ui_user/features/email/domain/state/print_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/send_receipt_to_sender_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/unsubscribe_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/add_a_label_to_an_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_counter_accept_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart';
|
||||
@@ -65,6 +67,7 @@ import 'package:tmail_ui_user/features/email/presentation/bindings/calendar_even
|
||||
import 'package:tmail_ui_user/features/email/presentation/bindings/mdn_interactor_bindings.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/calendar_attendee_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/calendar_organizer_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/handle_label_for_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/handle_mail_action_by_shortcut_action_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/handle_open_attachment_list_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/update_attendance_status_extension.dart';
|
||||
@@ -125,6 +128,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
RejectCalendarEventInteractor? _rejectCalendarEventInteractor;
|
||||
AcceptCounterCalendarEventInteractor? _acceptCounterCalendarEventInteractor;
|
||||
ThreadDetailController? _threadDetailController;
|
||||
AddALabelToAnEmailInteractor? addALabelToAnEmailInteractor;
|
||||
|
||||
final emailContents = RxnString();
|
||||
final attachments = <Attachment>[].obs;
|
||||
@@ -240,6 +244,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_handlePrintEmailSuccess(success);
|
||||
} else if (success is CalendarEventReplySuccess) {
|
||||
calendarEventSuccess(success);
|
||||
} else if (success is AddALabelToAnEmailSuccess) {
|
||||
handleAddLabelToEmailSuccess(success);
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
@@ -257,6 +263,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_showMessageWhenEmailPrintingFailed(failure);
|
||||
} else if (failure is CalendarEventReplyFailure) {
|
||||
_calendarEventFailure(failure);
|
||||
} else if (failure is AddALabelToAnEmailFailure) {
|
||||
handleAddLabelToEmailFailure(failure);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
@@ -1551,9 +1559,4 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_threadDetailController?.onNextMobile();
|
||||
}
|
||||
}
|
||||
|
||||
bool get isLabelFeatureEnabled {
|
||||
return mailboxDashBoardController.isLabelCapabilitySupported &&
|
||||
mailboxDashBoardController.labelController.isLabelSettingEnabled.isTrue;
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import 'package:tmail_ui_user/features/base/widget/optional_expanded.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/optional_scroll.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/calendar_event_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/handle_label_for_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/handle_on_iframe_click_in_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/validate_display_free_busy_message_extension.dart';
|
||||
@@ -106,6 +107,12 @@ class EmailView extends GetWidget<SingleEmailController> {
|
||||
labels: controller.mailboxDashBoardController.labelController.labels,
|
||||
openBottomSheetContextMenu: controller.mailboxDashBoardController.openBottomSheetContextMenu,
|
||||
openPopupMenu: controller.mailboxDashBoardController.openPopupMenuActionGroup,
|
||||
onSelectLabelAction: (label, isSelected) =>
|
||||
controller.toggleLabelToEmail(
|
||||
presentationEmail.id!,
|
||||
label,
|
||||
isSelected,
|
||||
),
|
||||
);
|
||||
},
|
||||
supportBackAction: !isInsideThreadDetailView,
|
||||
@@ -313,6 +320,12 @@ class EmailView extends GetWidget<SingleEmailController> {
|
||||
labels: controller.mailboxDashBoardController.labelController.labels,
|
||||
openBottomSheetContextMenu: controller.mailboxDashBoardController.openBottomSheetContextMenu,
|
||||
openPopupMenu: controller.mailboxDashBoardController.openPopupMenuActionGroup,
|
||||
onSelectLabelAction: (label, isSelected) =>
|
||||
controller.toggleLabelToEmail(
|
||||
presentationEmail.id!,
|
||||
label,
|
||||
isSelected,
|
||||
),
|
||||
),
|
||||
onToggleThreadDetailCollapseExpand: onToggleThreadDetailCollapseExpand,
|
||||
mailboxContain: presentationEmail.findMailboxContain(
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/extensions/email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/email_loaded.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/map_keywords_extension.dart';
|
||||
|
||||
extension EmailLoadedExtension on EmailLoaded {
|
||||
EmailLoaded addEmailKeyword({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
if (emailCurrent == null || emailCurrent?.id != emailId) {
|
||||
return this;
|
||||
}
|
||||
final newKeyword = emailCurrent?.keywords?.withKeyword(keyword);
|
||||
final updatedEmail = emailCurrent?.copyWith(keywords: newKeyword);
|
||||
return copyWith(emailCurrent: updatedEmail);
|
||||
}
|
||||
|
||||
EmailLoaded removeEmailKeyword({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
if (emailCurrent == null || emailCurrent?.id != emailId) {
|
||||
return this;
|
||||
}
|
||||
final newKeyword = emailCurrent?.keywords?.withoutKeyword(keyword);
|
||||
final updatedEmail = emailCurrent?.copyWith(keywords: newKeyword);
|
||||
return copyWith(emailCurrent: updatedEmail);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:labels/extensions/label_extension.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/add_a_label_to_an_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/email_loaded_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/labels/domain/exceptions/label_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/extensions/presentation_email_map_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/extensions/list_email_in_thread_detail_info_extension.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
|
||||
extension HandleLabelForEmailExtension on SingleEmailController {
|
||||
bool get isLabelFeatureEnabled {
|
||||
return mailboxDashBoardController.isLabelCapabilitySupported &&
|
||||
mailboxDashBoardController.labelController.isLabelSettingEnabled.isTrue;
|
||||
}
|
||||
|
||||
void toggleLabelToEmail(EmailId emailId, Label label, bool isSelected) {
|
||||
if (isSelected) {
|
||||
final accountId = mailboxDashBoardController.accountId.value;
|
||||
|
||||
_addALabelToAnEmail(
|
||||
accountId: accountId,
|
||||
emailId: emailId,
|
||||
label: label,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _addALabelToAnEmail({
|
||||
required AccountId? accountId,
|
||||
required Label label,
|
||||
required EmailId emailId,
|
||||
}) {
|
||||
final labelDisplay = label.safeDisplayName;
|
||||
|
||||
if (accountId == null) {
|
||||
consumeState(
|
||||
Stream.value(
|
||||
Left(AddALabelToAnEmailFailure(
|
||||
exception: NotFoundAccountIdException(),
|
||||
labelDisplay: labelDisplay,
|
||||
)),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final labelKeyword = label.keyword;
|
||||
if (labelKeyword == null) {
|
||||
consumeState(
|
||||
Stream.value(Left(
|
||||
AddALabelToAnEmailFailure(
|
||||
exception: LabelKeywordIsNull(),
|
||||
labelDisplay: labelDisplay,
|
||||
),
|
||||
)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
addALabelToAnEmailInteractor = getBinding<AddALabelToAnEmailInteractor>();
|
||||
if (addALabelToAnEmailInteractor != null) {
|
||||
consumeState(addALabelToAnEmailInteractor!.execute(
|
||||
accountId,
|
||||
emailId,
|
||||
labelKeyword,
|
||||
label.safeDisplayName,
|
||||
));
|
||||
} else {
|
||||
consumeState(
|
||||
Stream.value(
|
||||
Left(AddALabelToAnEmailFailure(
|
||||
exception: LabelInteractorIsNull(),
|
||||
labelDisplay: labelDisplay,
|
||||
)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void handleAddLabelToEmailSuccess(AddALabelToAnEmailSuccess success) {
|
||||
toastManager.showMessageSuccess(success);
|
||||
|
||||
_autoSyncLabelToSelectedEmailOnMemory(
|
||||
emailId: success.emailId,
|
||||
labelKeyword: success.labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
void handleAddLabelToEmailFailure(AddALabelToAnEmailFailure failure) {
|
||||
toastManager.showMessageFailure(failure);
|
||||
}
|
||||
|
||||
void _autoSyncLabelToSelectedEmailOnMemory({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier labelKeyword,
|
||||
}) {
|
||||
if (PlatformInfo.isMobile && !isThreadDetailEnabled) {
|
||||
_updateLabelInEmailWithThreadDisabledOnMobile(
|
||||
emailId: emailId,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
} else {
|
||||
_updateLabelInEmailWithThreadEnabled(
|
||||
emailId: emailId,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateLabelInEmailWithThreadDisabledOnMobile({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier labelKeyword,
|
||||
}) {
|
||||
final selectedEmail = mailboxDashBoardController.selectedEmail.value;
|
||||
final selectedEmailId = selectedEmail?.id;
|
||||
if (selectedEmail == null ||
|
||||
selectedEmailId == null ||
|
||||
selectedEmailId != emailId) {
|
||||
return;
|
||||
}
|
||||
|
||||
mailboxDashBoardController.selectedEmail.value =
|
||||
selectedEmail.addKeyword(labelKeyword);
|
||||
|
||||
final emailLoaded = currentEmailLoaded.value;
|
||||
if (emailLoaded != null) {
|
||||
currentEmailLoaded.value = emailLoaded.addEmailKeyword(
|
||||
emailId: emailId,
|
||||
keyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
mailboxDashBoardController.updateEmailFlagByEmailIds(
|
||||
[emailId],
|
||||
isLabelAdded: true,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
void _updateLabelInEmailWithThreadEnabled({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier labelKeyword,
|
||||
}) {
|
||||
final controller = threadDetailController;
|
||||
if (controller == null) return;
|
||||
|
||||
final currentEmailId = currentEmail?.id;
|
||||
if (currentEmailId == null || currentEmailId != emailId) return;
|
||||
|
||||
controller.emailIdsPresentation.value =
|
||||
controller.emailIdsPresentation.addEmailKeywordById(
|
||||
emailId: emailId,
|
||||
keyword: labelKeyword,
|
||||
);
|
||||
|
||||
controller.emailsInThreadDetailInfo.value =
|
||||
controller.emailsInThreadDetailInfo.addEmailKeywordById(
|
||||
emailId: emailId,
|
||||
keyword: labelKeyword,
|
||||
);
|
||||
|
||||
final emailLoaded = controller.currentEmailLoaded.value;
|
||||
if (emailLoaded != null) {
|
||||
controller.currentEmailLoaded.value = emailLoaded.addEmailKeyword(
|
||||
emailId: emailId,
|
||||
keyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
|
||||
mailboxDashBoardController.updateEmailFlagByEmailIds(
|
||||
[emailId],
|
||||
isLabelAdded: true,
|
||||
labelKeyword: labelKeyword,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -168,4 +169,16 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
label.keyword != null && enabledKeywords.contains(label.keyword))
|
||||
.toList();
|
||||
}
|
||||
|
||||
PresentationEmail addKeyword(KeyWordIdentifier keyword) {
|
||||
return copyWith(
|
||||
keywords: keywords.withKeyword(keyword),
|
||||
);
|
||||
}
|
||||
|
||||
PresentationEmail removeKeyword(KeyWordIdentifier keyword) {
|
||||
return copyWith(
|
||||
keywords: keywords.withoutKeyword(keyword),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,20 @@ class EmailLoaded with EquatableMixin {
|
||||
this.emailCurrent,
|
||||
});
|
||||
|
||||
EmailLoaded copyWith({
|
||||
String? htmlContent,
|
||||
List<Attachment>? attachments,
|
||||
List<Attachment>? inlineImages,
|
||||
Email? emailCurrent,
|
||||
}) {
|
||||
return EmailLoaded(
|
||||
htmlContent: htmlContent ?? this.htmlContent,
|
||||
attachments: attachments ?? this.attachments,
|
||||
inlineImages: inlineImages ?? this.inlineImages,
|
||||
emailCurrent: emailCurrent ?? this.emailCurrent,
|
||||
);
|
||||
}
|
||||
|
||||
SMimeSignatureStatus? get sMimeStatus => emailCurrent?.sMimeStatus;
|
||||
|
||||
@override
|
||||
|
||||
+13
-2
@@ -52,6 +52,7 @@ import 'package:tmail_ui_user/features/email/presentation/model/popup_menu_item_
|
||||
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/email_address_bottom_sheet_builder.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/widgets/email_address_dialog_builder.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_item_context_menu.dart';
|
||||
import 'package:tmail_ui_user/features/labels/presentation/widgets/label_list_context_menu.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_actions.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/create_new_email_rule_filter_request.dart';
|
||||
@@ -490,6 +491,7 @@ class EmailActionReactor {
|
||||
required OpenBottomSheetContextMenuAction openBottomSheetContextMenu,
|
||||
required OpenPopupMenuActionGroup openPopupMenu,
|
||||
List<Label>? labels,
|
||||
OnSelectLabelAction? onSelectLabelAction,
|
||||
}) {
|
||||
if (currentContext == null) return;
|
||||
|
||||
@@ -563,6 +565,8 @@ class EmailActionReactor {
|
||||
useGroupedActions: true,
|
||||
);
|
||||
} else {
|
||||
final submenuController = PopupSubmenuController();
|
||||
|
||||
final popupMenuItemEmailActions = moreActions.map((actionType) {
|
||||
return PopupMenuItemEmailAction(
|
||||
actionType,
|
||||
@@ -575,11 +579,15 @@ class EmailActionReactor {
|
||||
imagePaths: imagePaths,
|
||||
presentationEmail: presentationEmail,
|
||||
labels: labels,
|
||||
onSelectLabelAction: (label, isSelected) {
|
||||
onSelectLabelAction?.call(label, isSelected);
|
||||
submenuController.hide();
|
||||
popBack();
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
final submenuController = PopupSubmenuController();
|
||||
|
||||
final popupMenuWidget = PopupMenuActionGroupWidget(
|
||||
actions: popupMenuItemEmailActions,
|
||||
@@ -602,12 +610,15 @@ class EmailActionReactor {
|
||||
required ImagePaths imagePaths,
|
||||
required PresentationEmail presentationEmail,
|
||||
required List<Label>? labels,
|
||||
OnSelectLabelAction? onSelectLabelAction,
|
||||
}) {
|
||||
if (actionType == EmailActionType.labelAs) {
|
||||
if (actionType == EmailActionType.labelAs && labels?.isNotEmpty == true) {
|
||||
return LabelListContextMenu(
|
||||
labelList: labels ?? [],
|
||||
presentationEmail: presentationEmail,
|
||||
imagePaths: imagePaths,
|
||||
onSelectLabelAction: (label, isSelected) =>
|
||||
onSelectLabelAction?.call(label, isSelected),
|
||||
);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -6,16 +6,20 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:labels/extensions/label_extension.dart';
|
||||
import 'package:labels/model/label.dart';
|
||||
|
||||
typedef OnSelectLabelAction = void Function(Label label, bool isSelected);
|
||||
|
||||
class LabelItemContextMenu extends StatelessWidget {
|
||||
final Label label;
|
||||
final ImagePaths imagePaths;
|
||||
final bool isSelected;
|
||||
final OnSelectLabelAction onSelectLabelAction;
|
||||
|
||||
const LabelItemContextMenu({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.imagePaths,
|
||||
required this.isSelected,
|
||||
required this.onSelectLabelAction,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -23,7 +27,7 @@ class LabelItemContextMenu extends StatelessWidget {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
onTap: () => onSelectLabelAction(label, !isSelected),
|
||||
child: Container(
|
||||
height: 48,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
@@ -48,7 +52,7 @@ class LabelItemContextMenu extends StatelessWidget {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: ThemeUtils.textStyleBodyBody3(color: Colors.black),
|
||||
),
|
||||
)
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -9,12 +9,14 @@ class LabelListContextMenu extends StatelessWidget {
|
||||
final PresentationEmail presentationEmail;
|
||||
final List<Label> labelList;
|
||||
final ImagePaths imagePaths;
|
||||
final OnSelectLabelAction onSelectLabelAction;
|
||||
|
||||
const LabelListContextMenu({
|
||||
super.key,
|
||||
required this.labelList,
|
||||
required this.presentationEmail,
|
||||
required this.imagePaths,
|
||||
required this.onSelectLabelAction,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -24,13 +26,14 @@ class LabelListContextMenu extends StatelessWidget {
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: labelList.length,
|
||||
itemBuilder: (context, index) {
|
||||
itemBuilder: (_, index) {
|
||||
final label = labelList[index];
|
||||
final isSelected = emailLabels.contains(label);
|
||||
return LabelItemContextMenu(
|
||||
label: label,
|
||||
imagePaths: imagePaths,
|
||||
isSelected: isSelected,
|
||||
onSelectLabelAction: onSelectLabelAction,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
+8
-1
@@ -14,11 +14,14 @@ extension UpdateCurrentEmailsFlagsExtension on MailboxDashBoardController {
|
||||
MarkStarAction? markStarAction,
|
||||
bool markAsAnswered = false,
|
||||
bool markAsForwarded = false,
|
||||
bool isLabelAdded = false,
|
||||
KeyWordIdentifier? labelKeyword,
|
||||
}) {
|
||||
if (readAction == null &&
|
||||
markStarAction == null &&
|
||||
!markAsAnswered &&
|
||||
!markAsForwarded) {
|
||||
!markAsForwarded &&
|
||||
labelKeyword == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,6 +63,10 @@ extension UpdateCurrentEmailsFlagsExtension on MailboxDashBoardController {
|
||||
if (markAsForwarded) {
|
||||
_updateKeyword(email, KeyWordIdentifier.emailForwarded, true);
|
||||
}
|
||||
|
||||
if (labelKeyword != null) {
|
||||
_updateKeyword(email, labelKeyword, isLabelAdded);
|
||||
}
|
||||
}
|
||||
|
||||
currentEmails.refresh();
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
|
||||
extension MapKeywordsExtension on Map<KeyWordIdentifier, bool> {
|
||||
|
||||
Map<String, bool> toMapString() => Map.fromIterables(keys.map((keyword) => keyword.value), values);
|
||||
extension MapKeywordsExtension on Map<KeyWordIdentifier, bool>? {
|
||||
Map<String, bool> toMapString() => Map.fromIterables(
|
||||
this?.keys.map((keyword) => keyword.value) ?? {},
|
||||
this?.values ?? [],
|
||||
);
|
||||
|
||||
List<KeyWordIdentifier> get enabledKeywords =>
|
||||
entries.where((e) => e.value).map((e) => e.key).toList();
|
||||
}
|
||||
this?.entries.where((e) => e.value).map((e) => e.key).toList() ?? [];
|
||||
|
||||
Map<KeyWordIdentifier, bool> withKeyword(KeyWordIdentifier keyword) {
|
||||
return Map<KeyWordIdentifier, bool>.from(this ?? {})..[keyword] = true;
|
||||
}
|
||||
|
||||
Map<KeyWordIdentifier, bool> withoutKeyword(KeyWordIdentifier keyword) {
|
||||
return Map<KeyWordIdentifier, bool>.from(this ?? {})..remove(keyword);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/presentation_email_extension.dart';
|
||||
|
||||
extension PresentationEmailMapExtension on Map<EmailId, PresentationEmail?> {
|
||||
Map<EmailId, PresentationEmail?> addEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((id, email) {
|
||||
if (id != emailId || email == null) {
|
||||
return MapEntry(id, email);
|
||||
}
|
||||
return MapEntry(id, email.addKeyword(keyword));
|
||||
});
|
||||
}
|
||||
|
||||
Map<EmailId, PresentationEmail?> removeEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((id, email) {
|
||||
if (id != emailId || email == null) {
|
||||
return MapEntry(id, email);
|
||||
}
|
||||
return MapEntry(id, email.removeKeyword(keyword));
|
||||
});
|
||||
}
|
||||
}
|
||||
+28
@@ -1,4 +1,6 @@
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:tmail_ui_user/features/thread/data/extensions/map_keywords_extension.dart';
|
||||
import 'package:tmail_ui_user/features/thread_detail/domain/model/email_in_thread_detail_info.dart';
|
||||
|
||||
extension ListEmailInThreadDetailInfoExtension on List<EmailInThreadDetailInfo> {
|
||||
@@ -7,4 +9,30 @@ extension ListEmailInThreadDetailInfoExtension on List<EmailInThreadDetailInfo>
|
||||
: where((email) => email.isValidToDisplay)
|
||||
.map((email) => email.emailId)
|
||||
.toList();
|
||||
|
||||
List<EmailInThreadDetailInfo> addEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((email) {
|
||||
if (email.emailId != emailId) {
|
||||
return email;
|
||||
}
|
||||
final newKeywords = email.keywords.withKeyword(keyword);
|
||||
return email.copyWith(keywords: newKeywords);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
List<EmailInThreadDetailInfo> removeEmailKeywordById({
|
||||
required EmailId emailId,
|
||||
required KeyWordIdentifier keyword,
|
||||
}) {
|
||||
return map((email) {
|
||||
if (email.emailId != emailId) {
|
||||
return email;
|
||||
}
|
||||
final newKeywords = email.keywords.withoutKeyword(keyword);
|
||||
return email.copyWith(keywords: newKeywords);
|
||||
}).toList();
|
||||
}
|
||||
}
|
||||
@@ -5295,5 +5295,25 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"addLabelToEmailSuccessfullyMessage": "Email added to the \"{labelName}\" label",
|
||||
"@addLabelToEmailSuccessfullyMessage": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"labelName"
|
||||
],
|
||||
"placeholders": {
|
||||
"labelName": {}
|
||||
}
|
||||
},
|
||||
"addLabelToEmailFailureMessage": "Cannot add email to the \"{labelName}\" label",
|
||||
"@addLabelToEmailFailureMessage": {
|
||||
"type": "text",
|
||||
"placeholders_order": [
|
||||
"labelName"
|
||||
],
|
||||
"placeholders": {
|
||||
"labelName": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5626,4 +5626,20 @@ class AppLocalizations {
|
||||
name: 'labelAs',
|
||||
);
|
||||
}
|
||||
|
||||
String addLabelToEmailSuccessfullyMessage(String labelName) {
|
||||
return Intl.message(
|
||||
'Email added to the "$labelName" label',
|
||||
name: 'addLabelToEmailSuccessfullyMessage',
|
||||
args: [labelName],
|
||||
);
|
||||
}
|
||||
|
||||
String addLabelToEmailFailureMessage(String labelName) {
|
||||
return Intl.message(
|
||||
'Cannot add email to the "$labelName" label',
|
||||
name: 'addLabelToEmailFailureMessage',
|
||||
args: [labelName],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reply_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart';
|
||||
import 'package:tmail_ui_user/features/download/domain/state/parse_email_by_blob_id_state.dart';
|
||||
@@ -201,6 +202,9 @@ class ToastManager {
|
||||
} else if (failure is CreateNewLabelFailure) {
|
||||
message = message ??
|
||||
appLocalizations.createNewLabelFailure;
|
||||
} else if (failure is AddALabelToAnEmailFailure) {
|
||||
message = message ??
|
||||
appLocalizations.addLabelToEmailFailureMessage(failure.labelDisplay);
|
||||
}
|
||||
log('ToastManager::showMessageFailure: Message: $message');
|
||||
if (message?.trim().isNotEmpty == true) {
|
||||
@@ -268,6 +272,10 @@ class ToastManager {
|
||||
message = appLocalizations.createLabelSuccessfullyMessage(
|
||||
success.newLabel.safeDisplayName,
|
||||
);
|
||||
} else if (success is AddALabelToAnEmailSuccess) {
|
||||
message = appLocalizations.addLabelToEmailSuccessfullyMessage(
|
||||
success.labelDisplay,
|
||||
);
|
||||
}
|
||||
log('ToastManager::showMessageSuccess: Message: $message');
|
||||
if (message?.trim().isNotEmpty == true) {
|
||||
|
||||
Reference in New Issue
Block a user