diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 7a0fa0c948..047fe16c95 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -3262,6 +3262,52 @@ class MailboxDashBoardController extends ReloadableController ); } + Future maskAllAsSpamSelectionAllEmails( + BuildContext context, + Session session, + AccountId accountId, + PresentationMailbox currentMailbox + ) async { + final spamMailboxId = getMailboxIdByRole(PresentationMailbox.roleSpam); + + if (spamMailboxId == null) return; + + final spamMailboxPath = mapMailboxById[spamMailboxId]?.getDisplayName(context) ?? ''; + + consumeState(_moveAllSelectionAllEmailsInteractor.execute( + session, + accountId, + currentMailbox.id, + spamMailboxId, + spamMailboxPath, + currentMailbox.countTotalEmails, + _moveAllSelectionAllEmailsStreamController + )); + } + + Future allUnSpamSelectionAllEmails( + BuildContext context, + Session session, + AccountId accountId, + PresentationMailbox currentMailbox + ) async { + final inboxMailboxId = getMailboxIdByRole(PresentationMailbox.roleInbox); + + if (inboxMailboxId == null) return; + + final inboxMailboxPath = mapMailboxById[inboxMailboxId]?.getDisplayName(context) ?? ''; + + consumeState(_moveAllSelectionAllEmailsInteractor.execute( + session, + accountId, + currentMailbox.id, + inboxMailboxId, + inboxMailboxPath, + currentMailbox.countTotalEmails, + _moveAllSelectionAllEmailsStreamController + )); + } + @override void onClose() { if (PlatformInfo.isWeb) { diff --git a/lib/features/mailbox_dashboard/presentation/widgets/top_bar_thread_selection.dart b/lib/features/mailbox_dashboard/presentation/widgets/top_bar_thread_selection.dart index ee9f844613..739c15f869 100644 --- a/lib/features/mailbox_dashboard/presentation/widgets/top_bar_thread_selection.dart +++ b/lib/features/mailbox_dashboard/presentation/widgets/top_bar_thread_selection.dart @@ -95,24 +95,15 @@ class TopBarThreadSelection extends StatelessWidget{ ) ), TMailButtonWidget.fromIcon( - icon: isAllSpam ? imagePaths.icNotSpam : imagePaths.icSpam, + icon: _getIconForMoveToSpam(), backgroundColor: Colors.transparent, iconSize: 24, - tooltipMessage: isAllSpam - ? AppLocalizations.of(context).un_spam - : AppLocalizations.of(context).mark_as_spam, + tooltipMessage: _getTooltipMessageForMoveToSpam(context), onTapActionCallback: () { - if (isAllSpam) { - onEmailActionTypeAction?.call( - List.from(listEmail), - EmailActionType.unSpam - ); - } else { - onEmailActionTypeAction?.call( - List.from(listEmail.listEmailCanSpam(mapMailbox)), - EmailActionType.moveToSpam - ); - } + onEmailActionTypeAction?.call( + List.from(listEmail.listEmailCanSpam(mapMailbox)), + _getActionTypeForMoveToSpam() + ); } ) ], @@ -268,4 +259,36 @@ class TopBarThreadSelection extends StatelessWidget{ : EmailActionType.markAsStarred; } } + + String _getIconForMoveToSpam() { + if (isSelectAllEmailsEnabled) { + return selectedMailbox?.isSpam == true ? imagePaths.icNotSpam : imagePaths.icSpam; + } else { + return isAllSpam ? imagePaths.icNotSpam : imagePaths.icSpam; + } + } + + String _getTooltipMessageForMoveToSpam(BuildContext context) { + if (isSelectAllEmailsEnabled) { + return selectedMailbox?.isSpam == true + ? AppLocalizations.of(context).allUnSpam + : AppLocalizations.of(context).markAllAsSpam; + } else { + return isAllSpam + ? AppLocalizations.of(context).un_spam + : AppLocalizations.of(context).mark_as_spam; + } + } + + EmailActionType _getActionTypeForMoveToSpam() { + if (isSelectAllEmailsEnabled) { + return selectedMailbox?.isSpam == true + ? EmailActionType.allUnSpam + : EmailActionType.markAllAsSpam; + } else { + return isAllSpam + ? EmailActionType.unSpam + : EmailActionType.moveToSpam; + } + } } \ No newline at end of file diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index ef55e11e5b..bc83a5a4f3 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -1538,6 +1538,22 @@ class ThreadController extends BaseController with EmailActionController, PopupM selectedMailbox.countTotalEmails ); break; + case EmailActionType.markAllAsSpam: + mailboxDashBoardController.maskAllAsSpamSelectionAllEmails( + context, + _session!, + _accountId!, + selectedMailbox, + ); + break; + case EmailActionType.allUnSpam: + mailboxDashBoardController.allUnSpamSelectionAllEmails( + context, + _session!, + _accountId!, + selectedMailbox, + ); + break; default: break; } diff --git a/lib/main/localizations/app_localizations.dart b/lib/main/localizations/app_localizations.dart index 6a9bea9eb9..3a10860b92 100644 --- a/lib/main/localizations/app_localizations.dart +++ b/lib/main/localizations/app_localizations.dart @@ -4599,4 +4599,18 @@ class AppLocalizations { args: [reason] ); } + + String get allUnSpam { + return Intl.message( + 'All UnSpam', + name: 'allUnSpam', + ); + } + + String get markAllAsSpam { + return Intl.message( + 'Mark all as spam', + name: 'markAllAsSpam', + ); + } } \ No newline at end of file diff --git a/model/lib/email/email_action_type.dart b/model/lib/email/email_action_type.dart index aaea2bb6f6..f9063818a4 100644 --- a/model/lib/email/email_action_type.dart +++ b/model/lib/email/email_action_type.dart @@ -35,4 +35,6 @@ enum EmailActionType { moveAllToTrash, deleteAllPermanently, markAllAsStarred, + markAllAsSpam, + allUnSpam, } \ No newline at end of file