From f99451bb7fa4c9e026c4419617c7ea65aefb432b Mon Sep 17 00:00:00 2001 From: DatDang Date: Thu, 2 Jan 2025 15:11:36 +0700 Subject: [PATCH] TF-3385 Clean up ThreadController and SearchEmailController ever listener --- .../mailbox_dashboard_controller.dart | 43 +++++++++++- .../presentation/search_email_controller.dart | 67 +------------------ .../presentation/thread_controller.dart | 66 +----------------- 3 files changed, 42 insertions(+), 134 deletions(-) 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 25db5e08d2..63914b9fb6 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -55,6 +55,7 @@ import 'package:tmail_ui_user/features/email/domain/state/delete_multiple_emails import 'package:tmail_ui_user/features/email/domain/state/delete_sending_email_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/get_restored_deleted_message_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart'; +import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/move_to_mailbox_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/restore_deleted_message_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/store_sending_email_state.dart'; @@ -97,7 +98,9 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/download/download_controller.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/search_controller.dart' as search; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/delete_emails_in_mailbox_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/set_error_extension.dart'; +import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/mixin/user_setting_popup_menu_mixin.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart'; @@ -366,18 +369,20 @@ class MailboxDashBoardController extends ReloadableController } else if (success is UpdateVacationSuccess) { _handleUpdateVacationSuccess(success); } else if (success is MarkAsMultipleEmailReadAllSuccess) { - _markAsReadSelectedMultipleEmailSuccess(success.readActions); + _markAsReadSelectedMultipleEmailSuccess(success.readActions, success.emailIds); } else if (success is MarkAsMultipleEmailReadHasSomeEmailFailure) { - _markAsReadSelectedMultipleEmailSuccess(success.readActions); + _markAsReadSelectedMultipleEmailSuccess(success.readActions, success.successEmailIds); } else if (success is MarkAsStarMultipleEmailAllSuccess) { _markAsStarMultipleEmailSuccess( success.markStarAction, success.countMarkStarSuccess, + success.emailIds, ); } else if (success is MarkAsStarMultipleEmailHasSomeEmailFailure) { _markAsStarMultipleEmailSuccess( success.markStarAction, success.countMarkStarSuccess, + success.successEmailIds, ); } else if (success is MoveMultipleEmailToMailboxAllSuccess || success is MoveMultipleEmailToMailboxHasSomeEmailFailure) { @@ -415,6 +420,11 @@ class MailboxDashBoardController extends ReloadableController goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache)); } else if (success is GetIdentityCacheOnWebSuccess) { goToSettings(); + } else if (success is MarkAsStarEmailSuccess) { + updateEmailFlagByEmailIds( + [success.emailId], + markStarAction: success.markStarAction, + ); } } @@ -899,6 +909,10 @@ class MailboxDashBoardController extends ReloadableController } void _deleteEmailPermanentlySuccess(DeleteEmailPermanentlySuccess success) { + handleDeleteEmailsInMailbox( + emailIds: [success.emailId], + affectedMailboxId: success.mailboxId, + ); if (currentOverlayContext != null && currentContext != null) { appToast.showToastSuccessMessage( currentOverlayContext!, @@ -958,7 +972,8 @@ class MailboxDashBoardController extends ReloadableController } } - void _markAsReadSelectedMultipleEmailSuccess(ReadActions readActions) { + void _markAsReadSelectedMultipleEmailSuccess(ReadActions readActions, List emailIds) { + updateEmailFlagByEmailIds(emailIds, readAction: readActions); if (currentContext != null && currentOverlayContext != null) { final message = readActions == ReadActions.markAsUnread ? AppLocalizations.of(currentContext!).marked_message_toast(AppLocalizations.of(currentContext!).unread) @@ -975,6 +990,10 @@ class MailboxDashBoardController extends ReloadableController } void _markAsReadEmailSuccess(MarkAsEmailReadSuccess success) { + updateEmailFlagByEmailIds( + [success.emailId], + readAction: success.readActions, + ); if (currentContext != null && currentOverlayContext != null && success.markReadAction == MarkReadAction.swipeOnThread) { @@ -1025,7 +1044,9 @@ class MailboxDashBoardController extends ReloadableController void _markAsStarMultipleEmailSuccess( MarkStarAction markStarAction, int countMarkStarSuccess, + List emailIds, ) { + updateEmailFlagByEmailIds(emailIds, markStarAction: markStarAction); if (currentOverlayContext != null && currentContext != null) { final message = markStarAction == MarkStarAction.unMarkStar ? AppLocalizations.of(currentContext!).marked_unstar_multiple_item(countMarkStarSuccess) @@ -1494,6 +1515,10 @@ class MailboxDashBoardController extends ReloadableController void _emptyTrashFolderSuccess(EmptyTrashFolderSuccess success) { viewStateMailboxActionProgress.value = Right(UIState.idle); + handleDeleteEmailsInMailbox( + emailIds: success.emailIds, + affectedMailboxId: success.mailboxId, + ); if (currentOverlayContext != null && currentContext != null) { appToast.showToastSuccessMessage( currentOverlayContext!, @@ -1516,8 +1541,16 @@ class MailboxDashBoardController extends ReloadableController void _deleteMultipleEmailsPermanentlySuccess(Success success) { List listEmailIdResult = []; if (success is DeleteMultipleEmailsPermanentlyAllSuccess) { + handleDeleteEmailsInMailbox( + emailIds: success.emailIds, + affectedMailboxId: success.mailboxId, + ); listEmailIdResult = success.emailIds; } else if (success is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { + handleDeleteEmailsInMailbox( + emailIds: success.emailIds, + affectedMailboxId: success.mailboxId, + ); listEmailIdResult = success.emailIds; } @@ -2500,6 +2533,10 @@ class MailboxDashBoardController extends ReloadableController void _emptySpamFolderSuccess(EmptySpamFolderSuccess success) { viewStateMailboxActionProgress.value = Right(UIState.idle); + handleDeleteEmailsInMailbox( + emailIds: success.emailIds, + affectedMailboxId: success.mailboxId, + ); if (currentOverlayContext != null && currentContext != null) { appToast.showToastSuccessMessage( currentOverlayContext!, diff --git a/lib/features/search/email/presentation/search_email_controller.dart b/lib/features/search/email/presentation/search_email_controller.dart index 6748769676..82d679f34f 100644 --- a/lib/features/search/email/presentation/search_email_controller.dart +++ b/lib/features/search/email/presentation/search_email_controller.dart @@ -33,10 +33,6 @@ import 'package:tmail_ui_user/features/composer/presentation/extensions/prefix_e import 'package:tmail_ui_user/features/contact/presentation/model/contact_arguments.dart'; import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart'; import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart'; -import 'package:tmail_ui_user/features/email/domain/state/delete_email_permanently_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/delete_multiple_emails_permanently_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/move_to_mailbox_state.dart'; import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart'; import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart'; @@ -49,8 +45,6 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/get_all import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/quick_search_email_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/domain/usecases/save_recent_search_interactor.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/action/dashboard_action.dart'; -import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/delete_emails_in_mailbox_extension.dart'; -import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_emails_with_new_mailbox_id_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/search/email_receive_time_type.dart'; @@ -68,10 +62,6 @@ import 'package:tmail_ui_user/features/search/email/presentation/model/search_mo import 'package:tmail_ui_user/features/search/email/presentation/search_email_bindings.dart'; import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.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/mark_as_multiple_email_read_state.dart'; -import 'package:tmail_ui_user/features/thread/domain/state/mark_as_star_multiple_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/search_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/search_more_email_state.dart'; @@ -276,62 +266,7 @@ class SearchEmailController extends BaseController ever(mailboxDashBoardController.viewState, (viewState) { final reactionState = viewState.getOrElse(() => UIState.idle); - if (reactionState is MarkAsEmailReadSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - [reactionState.emailId], - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsMultipleEmailReadAllSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.emailIds, - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsMultipleEmailReadHasSomeEmailFailure) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.successEmailIds, - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsStarEmailSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - [reactionState.emailId], - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is MarkAsStarMultipleEmailAllSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.emailIds, - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is MarkAsStarMultipleEmailHasSomeEmailFailure) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.successEmailIds, - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is DeleteEmailPermanentlySuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: [reactionState.emailId], - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is DeleteMultipleEmailsPermanentlyAllSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is EmptyTrashFolderSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is EmptySpamFolderSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is MoveToMailboxSuccess) { + if (reactionState is MoveToMailboxSuccess) { mailboxDashBoardController.handleUpdateEmailsWithNewMailboxId( originalMailboxIdsWithEmailIds: reactionState.originalMailboxIdsWithEmailIds, destinationMailboxId: reactionState.destinationMailboxId, diff --git a/lib/features/thread/presentation/thread_controller.dart b/lib/features/thread/presentation/thread_controller.dart index 549d2d79a9..c91e9c4a80 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -20,10 +20,6 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:model/model.dart'; import 'package:tmail_ui_user/features/base/base_controller.dart'; import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart'; -import 'package:tmail_ui_user/features/email/domain/state/delete_email_permanently_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/delete_multiple_emails_permanently_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_state.dart'; -import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/move_to_mailbox_state.dart'; import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart'; import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart'; @@ -31,7 +27,6 @@ import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.d import 'package:tmail_ui_user/features/mailbox/domain/state/mark_as_mailbox_read_state.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/action/dashboard_action.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/search_controller.dart' as search; -import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/delete_emails_in_mailbox_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/move_emails_to_mailbox_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart'; import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart'; @@ -51,13 +46,9 @@ import 'package:tmail_ui_user/features/thread/domain/model/email_filter.dart'; import 'package:tmail_ui_user/features/thread/domain/model/filter_message_option.dart'; import 'package:tmail_ui_user/features/thread/domain/model/get_email_request.dart'; import 'package:tmail_ui_user/features/thread/domain/model/search_query.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/get_all_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/get_email_by_id_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/load_more_emails_state.dart'; -import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_email_read_state.dart'; -import 'package:tmail_ui_user/features/thread/domain/state/mark_as_star_multiple_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/refresh_all_email_state.dart'; import 'package:tmail_ui_user/features/thread/domain/state/refresh_changes_all_email_state.dart'; @@ -348,68 +339,13 @@ class ThreadController extends BaseController with EmailActionController { ever(mailboxDashBoardController.viewState, (viewState) { final reactionState = viewState.getOrElse(() => UIState.idle); - if (reactionState is MarkAsEmailReadSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - [reactionState.emailId], - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsMultipleEmailReadAllSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.emailIds, - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsMultipleEmailReadHasSomeEmailFailure) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.successEmailIds, - readAction: reactionState.readActions, - ); - } else if (reactionState is MarkAsMailboxReadAllSuccess) { + if (reactionState is MarkAsMailboxReadAllSuccess) { _handleMarkEmailsAsReadByMailboxId(reactionState.mailboxId); } else if (reactionState is MarkAsMailboxReadHasSomeEmailFailure) { mailboxDashBoardController.updateEmailFlagByEmailIds( reactionState.successEmailIds, readAction: ReadActions.markAsRead, ); - } else if (reactionState is MarkAsStarEmailSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - [reactionState.emailId], - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is MarkAsStarMultipleEmailAllSuccess) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.emailIds, - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is MarkAsStarMultipleEmailHasSomeEmailFailure) { - mailboxDashBoardController.updateEmailFlagByEmailIds( - reactionState.successEmailIds, - markStarAction: reactionState.markStarAction, - ); - } else if (reactionState is DeleteEmailPermanentlySuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: [reactionState.emailId], - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is DeleteMultipleEmailsPermanentlyAllSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is DeleteMultipleEmailsPermanentlyHasSomeEmailFailure) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is EmptyTrashFolderSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); - } else if (reactionState is EmptySpamFolderSuccess) { - mailboxDashBoardController.handleDeleteEmailsInMailbox( - emailIds: reactionState.emailIds, - affectedMailboxId: reactionState.mailboxId, - ); } else if (reactionState is MoveToMailboxSuccess) { mailboxDashBoardController.handleMoveEmailsToMailbox( originalMailboxIdsWithEmailIds: reactionState.originalMailboxIdsWithEmailIds,