diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 686ee83956..85570a7831 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -1003,6 +1003,9 @@ class SingleEmailController extends BaseController with AppLoaderMixin { case EmailActionType.unsubscribe: _unsubscribeEmail(context, presentationEmail); break; + case EmailActionType.archiveMessage: + archiveMessage(context, presentationEmail); + break; default: break; } @@ -1480,4 +1483,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin { ) ); } + + void archiveMessage(BuildContext context, PresentationEmail email) { + mailboxDashBoardController.archiveMessage(context, email); + } } \ No newline at end of file diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index d21588050b..b1ed437a80 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -23,7 +23,6 @@ import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_draft import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart'; import 'package:tmail_ui_user/features/composer/domain/state/update_email_drafts_state.dart'; import 'package:tmail_ui_user/features/email/domain/model/move_action.dart'; -import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.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'; @@ -1347,25 +1346,4 @@ class MailboxController extends BaseMailboxController with MailboxActionHandlerM mailboxDashBoardController.emptySpamFolderAction(spamFolderId: presentationMailbox.id); } } - - void archiveMessage(PresentationEmail email) { - final mailboxContain = email.findMailboxContain(mailboxDashBoardController.mapMailboxById); - if (mailboxContain != null) { - final archiveMailboxId = mailboxDashBoardController.getMailboxIdByRole(PresentationMailbox.roleArchive); - if (archiveMailboxId != null) { - final moveToArchiveMailboxRequest = MoveToMailboxRequest( - {mailboxContain.id: [email.id!]}, - archiveMailboxId, - MoveAction.moving, - EmailActionType.moveToMailbox, - destinationPath:findNodePath(archiveMailboxId) - ); - mailboxDashBoardController.moveToMailbox( - mailboxDashBoardController.sessionCurrent!, - mailboxDashBoardController.accountId.value!, - moveToArchiveMailboxRequest - ); - } - } - } } \ No newline at end of file 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 a3a830e6fd..1d30c98e34 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -2393,6 +2393,28 @@ class MailboxDashBoardController extends ReloadableController { return false; } + void archiveMessage(BuildContext context, PresentationEmail email) { + final mailboxContain = email.findMailboxContain(mapMailboxById); + if (mailboxContain != null) { + final archiveMailboxId = getMailboxIdByRole(PresentationMailbox.roleArchive); + final archiveMailboxPath = mapMailboxById[archiveMailboxId]?.getDisplayName(context); + if (archiveMailboxId != null) { + final moveToArchiveMailboxRequest = MoveToMailboxRequest( + {mailboxContain.id: [email.id!]}, + archiveMailboxId, + MoveAction.moving, + EmailActionType.moveToMailbox, + destinationPath: archiveMailboxPath + ); + moveToMailbox( + sessionCurrent!, + accountId.value!, + moveToArchiveMailboxRequest + ); + } + } + } + @override void onClose() { _emailReceiveManager.closeEmailReceiveManagerStream(); diff --git a/lib/features/thread/presentation/mixin/email_action_controller.dart b/lib/features/thread/presentation/mixin/email_action_controller.dart index 0d7e047382..16c462650e 100644 --- a/lib/features/thread/presentation/mixin/email_action_controller.dart +++ b/lib/features/thread/presentation/mixin/email_action_controller.dart @@ -287,4 +287,8 @@ mixin EmailActionController { void openEmailInNewTabAction(BuildContext context, PresentationEmail email) { AppUtils.launchLink(email.routeWebAsString); } + + void archiveMessage(BuildContext context, PresentationEmail email) { + mailboxDashBoardController.archiveMessage(context, email); + } } \ 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 956dfe27af..6e4274cd72 100644 --- a/lib/features/thread/presentation/thread_controller.dart +++ b/lib/features/thread/presentation/thread_controller.dart @@ -1183,11 +1183,13 @@ class ThreadController extends BaseController with EmailActionController { if (direction == DismissDirection.startToEnd) { ReadActions readActions = !email.hasRead ? ReadActions.markAsRead : ReadActions.markAsUnread; markAsEmailRead(email, readActions, MarkReadAction.swipeOnThread); + } else if (direction == DismissDirection.endToStart) { + archiveMessage(context, email); } return false; } - DismissDirection getSwipeDirection(bool isWebDesktop, SelectMode selectMode) { + DismissDirection getSwipeDirection(bool isWebDesktop, SelectMode selectMode, PresentationEmail email) { if (isWebDesktop) { return DismissDirection.none; } @@ -1196,9 +1198,13 @@ class ThreadController extends BaseController with EmailActionController { return DismissDirection.none; } - return DismissDirection.startToEnd; + return isInArchiveMailbox(email) + ? DismissDirection.startToEnd + : DismissDirection.horizontal; } + bool isInArchiveMailbox(PresentationEmail email) => email.mailboxContain?.isArchive == true; + void scrollToTop() { if (listEmailController.hasClients) { listEmailController.animateTo(0, duration: const Duration(milliseconds: 500), curve: Curves.fastOutSlowIn); diff --git a/lib/features/thread/presentation/thread_view.dart b/lib/features/thread/presentation/thread_view.dart index cf1fa88940..2c6f8f1f70 100644 --- a/lib/features/thread/presentation/thread_view.dart +++ b/lib/features/thread/presentation/thread_view.dart @@ -495,33 +495,33 @@ class ThreadView extends GetWidget ), secondaryBackground: controller.isInArchiveMailbox(presentationEmail) == false ? Container( - color: AppColor.colorItemRecipientSelected, - padding: const EdgeInsetsDirectional.only(end: 16), - child: Align( - alignment: AlignmentDirectional.centerEnd, - child: Row( - children: [ - const Spacer(), - CircleAvatar( - backgroundColor: AppColor.colorSpamReportBannerBackground, - radius: 24, - child: SvgPicture.asset( - controller.imagePaths.icMailboxArchived, - fit: BoxFit.fill, - ) - ), - const SizedBox(width: 11), - Text( - AppLocalizations.of(context).archiveMessage, - style: const TextStyle( - fontSize: 15, - color: AppColor.primaryColor, + color: AppColor.colorItemRecipientSelected, + padding: const EdgeInsetsDirectional.only(end: 16), + child: Align( + alignment: AlignmentDirectional.centerEnd, + child: Row( + children: [ + const Spacer(), + CircleAvatar( + backgroundColor: AppColor.colorSpamReportBannerBackground, + radius: 24, + child: SvgPicture.asset( + controller.imagePaths.icMailboxArchived, + fit: BoxFit.fill, + ) ), - ), - ], + const SizedBox(width: 11), + Text( + AppLocalizations.of(context).archiveMessage, + style: const TextStyle( + fontSize: 15, + color: AppColor.primaryColor, + ), + ), + ], + ), ), - ), - ) + ) : null, confirmDismiss: (direction) => controller.swipeEmailAction(context, presentationEmail, direction), child: EmailTileBuilder( @@ -730,13 +730,13 @@ class ThreadView extends GetWidget AppLocalizations.of(context).archiveMessage, email, iconLeftPadding: controller.responsiveUtils.isMobile(context) - ? const EdgeInsets.only(left: 12, right: 16) - : const EdgeInsets.only(right: 12), + ? const EdgeInsetsDirectional.only(start: 12, end: 16) + : const EdgeInsetsDirectional.only(start: 12), iconRightPadding: controller.responsiveUtils.isMobile(context) - ? const EdgeInsets.only(right: 12) + ? const EdgeInsetsDirectional.only(start: 12) : EdgeInsets.zero ) - ..onActionClick((email) => controller.archiveMessage(email)) + ..onActionClick((email) => controller.archiveMessage(context, email)) ).build(); } @@ -821,7 +821,7 @@ class ThreadView extends GetWidget ), onCallbackAction: () { popBack(); - controller.archiveMessage(email); + controller.archiveMessage(context, email); } ) );