Skip to content

Commit

Permalink
TF-1328 Implement archiveMessage in thread and singleEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui authored and hoangdat committed Jan 2, 2024
1 parent a6ff6c4 commit 83b45fd
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -1480,4 +1483,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
)
);
}

void archiveMessage(BuildContext context, PresentationEmail email) {
mailboxDashBoardController.archiveMessage(context, email);
}
}
22 changes: 0 additions & 22 deletions lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 8 additions & 2 deletions lib/features/thread/presentation/thread_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
60 changes: 30 additions & 30 deletions lib/features/thread/presentation/thread_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,33 +495,33 @@ class ThreadView extends GetWidget<ThreadController>
),
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(
Expand Down Expand Up @@ -730,13 +730,13 @@ class ThreadView extends GetWidget<ThreadController>
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();
}

Expand Down Expand Up @@ -821,7 +821,7 @@ class ThreadView extends GetWidget<ThreadController>
),
onCallbackAction: () {
popBack();
controller.archiveMessage(email);
controller.archiveMessage(context, email);
}
)
);
Expand Down

0 comments on commit 83b45fd

Please sign in to comment.