Skip to content

Commit

Permalink
TF-3385 Clean up ThreadController and SearchEmailController ever list…
Browse files Browse the repository at this point in the history
…ener
  • Loading branch information
tddang-linagora committed Jan 2, 2025
1 parent bc50f8d commit f99451b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
);
}
}

Expand Down Expand Up @@ -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!,
Expand Down Expand Up @@ -958,7 +972,8 @@ class MailboxDashBoardController extends ReloadableController
}
}

void _markAsReadSelectedMultipleEmailSuccess(ReadActions readActions) {
void _markAsReadSelectedMultipleEmailSuccess(ReadActions readActions, List<EmailId> 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)
Expand All @@ -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) {
Expand Down Expand Up @@ -1025,7 +1044,9 @@ class MailboxDashBoardController extends ReloadableController
void _markAsStarMultipleEmailSuccess(
MarkStarAction markStarAction,
int countMarkStarSuccess,
List<EmailId> emailIds,
) {
updateEmailFlagByEmailIds(emailIds, markStarAction: markStarAction);
if (currentOverlayContext != null && currentContext != null) {
final message = markStarAction == MarkStarAction.unMarkStar
? AppLocalizations.of(currentContext!).marked_unstar_multiple_item(countMarkStarSuccess)
Expand Down Expand Up @@ -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!,
Expand All @@ -1516,8 +1541,16 @@ class MailboxDashBoardController extends ReloadableController
void _deleteMultipleEmailsPermanentlySuccess(Success success) {
List<EmailId> listEmailIdResult = <EmailId>[];
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;
}

Expand Down Expand Up @@ -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!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
66 changes: 1 addition & 65 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,13 @@ 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';
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
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';
Expand All @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f99451b

Please sign in to comment.