Skip to content

Commit

Permalink
TF-3372 Handling error for empty trash failure
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdat committed Dec 31, 2024
1 parent 7b4f692 commit 145a3f9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/features/base/mixin/mailbox_action_handler_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mixin MailboxActionHandlerMixin {
..onConfirmAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id);
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id, totalEmails: mailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand All @@ -156,7 +156,7 @@ mixin MailboxActionHandlerMixin {
..onConfirmButtonAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (mailbox.countTotalEmails > 0) {
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id);
dashboardController.emptySpamFolderAction(spamFolderId: mailbox.id, totalEmails: mailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,12 +1396,14 @@ class MailboxDashBoardController extends ReloadableController
onCancelSelectionEmail?.call();

final trashMailboxId = trashFolderId ?? mapDefaultMailboxIdByRole[PresentationMailbox.roleTrash];
final trashMailbox = mapMailboxById[trashMailboxId];
final totalEmailsInTrash = totalEmails == 0 ? trashMailbox?.countTotalEmails : totalEmails;
if (sessionCurrent != null && accountId.value != null && trashMailboxId != null) {
consumeState(_emptyTrashFolderInteractor.execute(
sessionCurrent!,
accountId.value!,
trashMailboxId,
totalEmails,
totalEmailsInTrash ?? 0,
_progressStateController
));
}
Expand Down Expand Up @@ -2458,7 +2460,7 @@ class MailboxDashBoardController extends ReloadableController
..onConfirmAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (spamMailbox.countTotalEmails > 0) {
emptySpamFolderAction(spamFolderId: spamMailbox.id);
emptySpamFolderAction(spamFolderId: spamMailbox.id, totalEmails: spamMailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand All @@ -2483,7 +2485,7 @@ class MailboxDashBoardController extends ReloadableController
..onConfirmButtonAction(AppLocalizations.of(context).delete_all, () {
popBack();
if (spamMailbox.countTotalEmails > 0) {
emptySpamFolderAction(spamFolderId: spamMailbox.id);
emptySpamFolderAction(spamFolderId: spamMailbox.id, totalEmails: spamMailbox.countTotalEmails);
} else {
appToast.showToastWarningMessage(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ThreadIsolateWorker {
fun1: _emptyMailboxFolderAction,
notification: (value) {
if (value is List<EmailId>) {
log('ThreadIsolateWorker::emptyMailboxFolder(): onUpdateProgress ${value.length / totalEmails}');
log('ThreadIsolateWorker::emptyMailboxFolder(): processed ${value.length} - totalEmails $totalEmails');
onProgressController.add(Right<Failure, Success>(EmptyingFolderState(
mailboxId, value.length, totalEmails
)));
Expand Down
8 changes: 7 additions & 1 deletion lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2024-10-31T13:18:32.336494",
"@@last_modified": "2024-12-31T12:11:05.777668",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
Expand Down Expand Up @@ -3970,6 +3970,12 @@
"placeholders_order": [],
"placeholders": {}
},
"emptyTrashFolderFailed": "Empty trash folder failed",
"@emptyTrashFolderFailed": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"markAsSpamFailed": "Mark as spam failed",
"@markAsSpamFailed": {
"type": "text",
Expand Down
6 changes: 6 additions & 0 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4162,6 +4162,12 @@ class AppLocalizations {
name: 'emptySpamFolderFailed');
}

String get emptyTrashFolderFailed {
return Intl.message(
'Empty trash folder failed',
name: 'emptyTrashFolderFailed');
}

String get markAsSpamFailed {
return Intl.message(
'Mark as spam failed',
Expand Down
3 changes: 3 additions & 0 deletions lib/main/utils/toast_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_ex
import 'package:tmail_ui_user/features/starting_page/domain/state/sign_in_twake_workplace_state.dart';
import 'package:tmail_ui_user/features/starting_page/domain/state/sign_up_twake_workplace_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_spam_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/empty_trash_folder_state.dart';
import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
Expand Down Expand Up @@ -63,6 +64,8 @@ class ToastManager {
?? AppLocalizations.of(currentContext!).unknownError;
} else if (failure is EmptySpamFolderFailure) {
message = AppLocalizations.of(currentContext!).emptySpamFolderFailed;
} else if (failure is EmptyTrashFolderFailure) {
message = AppLocalizations.of(currentContext!).emptyTrashFolderFailed;
} else if (failure is MoveMultipleEmailToMailboxFailure
&& failure.emailActionType == EmailActionType.moveToSpam
&& failure.moveAction == MoveAction.moving) {
Expand Down

0 comments on commit 145a3f9

Please sign in to comment.