Skip to content

Commit

Permalink
TF-2646 Handle mark all as Spam/UnSpam for selection emails
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Dec 13, 2024
1 parent b05496c commit 0922b53
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3262,6 +3262,52 @@ class MailboxDashBoardController extends ReloadableController
);
}

Future<void> 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<void> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
)
],
Expand Down Expand Up @@ -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;
}
}
}
16 changes: 16 additions & 0 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 14 additions & 0 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
}
2 changes: 2 additions & 0 deletions model/lib/email/email_action_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ enum EmailActionType {
moveAllToTrash,
deleteAllPermanently,
markAllAsStarred,
markAllAsSpam,
allUnSpam,
}

0 comments on commit 0922b53

Please sign in to comment.