From f1a3589df05884cfd15bcd5e170dd2acfd70636d Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 20 Sep 2023 15:19:52 +0700 Subject: [PATCH] TF-1608 Set `references` and `inReplyTo` fields for reply/replyAll email (cherry picked from commit 775c2485c947567015551c1a2f47272acf4f2ced) --- .../presentation/composer_controller.dart | 60 +++++++++++++++---- .../model/save_to_draft_view_event.dart | 6 +- .../model/composer_arguments.dart | 17 +++++- 3 files changed, 70 insertions(+), 13 deletions(-) diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 5f35d058d..a5f105939 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -620,13 +620,14 @@ class ComposerController extends BaseController { } Future _generateEmail( - BuildContext context, - UserProfile userProfile, - { - bool asDrafts = false, - MailboxId? draftMailboxId, - MailboxId? outboxMailboxId - } + BuildContext context, + UserProfile userProfile, + { + bool asDrafts = false, + MailboxId? draftMailboxId, + MailboxId? outboxMailboxId, + ComposerArguments? arguments, + } ) async { Set listFromEmailAddress = {EmailAddress(null, userProfile.email)}; if (identitySelected?.email?.isNotEmpty == true) { @@ -673,6 +674,9 @@ class ComposerController extends BaseController { mapKeywords[KeyWordIdentifier.emailSeen] = true; } + final inReplyTo = _generateInReplyTo(arguments); + final references = _generateReferences(arguments); + final generatePartId = PartId(_uuid.v1()); return Email( @@ -682,6 +686,8 @@ class ComposerController extends BaseController { cc: listCcEmailAddress.toSet(), bcc: listBccEmailAddress.toSet(), replyTo: listReplyToEmailAddress, + inReplyTo: inReplyTo, + references: references, keywords: mapKeywords.isNotEmpty ? mapKeywords : null, subject: subjectEmail.value, htmlBody: { @@ -698,6 +704,31 @@ class ComposerController extends BaseController { ); } + MessageIdsHeaderValue? _generateInReplyTo(ComposerArguments? arguments) { + if (arguments?.emailActionType == EmailActionType.reply || + arguments?.emailActionType == EmailActionType.replyAll) { + return arguments?.messageId; + } + return null; + } + + MessageIdsHeaderValue? _generateReferences(ComposerArguments? arguments) { + if (arguments?.emailActionType == EmailActionType.reply || + arguments?.emailActionType == EmailActionType.replyAll) { + Set ids = {}; + if (arguments?.messageId?.ids.isNotEmpty == true) { + ids.addAll(arguments!.messageId!.ids); + } + if (arguments?.references?.ids.isNotEmpty == true) { + ids.addAll(arguments!.references!.ids); + } + if (ids.isNotEmpty) { + return MessageIdsHeaderValue(ids); + } + } + return null; + } + Future>> _getMapContent(String emailBodyText) async { if (kIsWeb) { return await richTextWebController.refactorContentHasInlineImage( @@ -813,7 +844,13 @@ class ComposerController extends BaseController { final userProfile = mailboxDashBoardController.userProfile.value; if (arguments != null && accountId != null && userProfile != null && session != null) { - final createdEmail = await _generateEmail(context, userProfile, outboxMailboxId: outboxMailboxId); + final createdEmail = await _generateEmail( + context, + userProfile, + outboxMailboxId: outboxMailboxId, + arguments: arguments + ); + final emailRequest = arguments.emailActionType == EmailActionType.editSendingEmail ? arguments.sendingEmail!.toEmailRequest(newEmail: createdEmail) : EmailRequest( @@ -1061,7 +1098,8 @@ class ComposerController extends BaseController { context, userProfile, asDrafts: true, - draftMailboxId: draftMailboxId + draftMailboxId: draftMailboxId, + arguments: arguments, ); if (arguments.emailActionType == EmailActionType.editDraft) { @@ -1112,6 +1150,7 @@ class ComposerController extends BaseController { userProfile: userProfile, draftMailboxId: draftMailboxId, emailIdEditing: _emailIdEditing, + arguments: mailboxDashBoardController.composerArguments, ) ); } @@ -1122,7 +1161,8 @@ class ComposerController extends BaseController { event.context, event.userProfile, asDrafts: true, - draftMailboxId: event.draftMailboxId + draftMailboxId: event.draftMailboxId, + arguments: event.arguments ); if (event.emailIdEditing == null) { diff --git a/lib/features/composer/presentation/model/save_to_draft_view_event.dart b/lib/features/composer/presentation/model/save_to_draft_view_event.dart index 59c41de18..14db275c0 100644 --- a/lib/features/composer/presentation/model/save_to_draft_view_event.dart +++ b/lib/features/composer/presentation/model/save_to_draft_view_event.dart @@ -5,6 +5,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:model/user/user_profile.dart'; +import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart'; class SaveToDraftViewEvent extends ViewEvent { final BuildContext context; @@ -13,6 +14,7 @@ class SaveToDraftViewEvent extends ViewEvent { final UserProfile userProfile; final MailboxId draftMailboxId; final EmailId? emailIdEditing; + final ComposerArguments? arguments; SaveToDraftViewEvent({ required this.context, @@ -20,7 +22,8 @@ class SaveToDraftViewEvent extends ViewEvent { required this.accountId, required this.userProfile, required this.draftMailboxId, - this.emailIdEditing + this.emailIdEditing, + this.arguments, }); @override @@ -31,5 +34,6 @@ class SaveToDraftViewEvent extends ViewEvent { userProfile, draftMailboxId, emailIdEditing, + arguments, ]; } \ No newline at end of file diff --git a/lib/features/email/presentation/model/composer_arguments.dart b/lib/features/email/presentation/model/composer_arguments.dart index c82aa71c0..7860bd0b8 100644 --- a/lib/features/email/presentation/model/composer_arguments.dart +++ b/lib/features/email/presentation/model/composer_arguments.dart @@ -1,3 +1,4 @@ +import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:model/model.dart'; @@ -16,6 +17,8 @@ class ComposerArguments extends RouterArguments { final Role? mailboxRole; final SendingEmail? sendingEmail; final String? uri; + final MessageIdsHeaderValue? messageId; + final MessageIdsHeaderValue? references; ComposerArguments({ this.emailActionType = EmailActionType.compose, @@ -27,6 +30,8 @@ class ComposerArguments extends RouterArguments { this.listSharedMediaFile, this.sendingEmail, this.uri, + this.messageId, + this.references, }); factory ComposerArguments.fromSendingEmail(SendingEmail sendingEmail) => @@ -83,22 +88,30 @@ class ComposerArguments extends RouterArguments { required PresentationEmail presentationEmail, required String content, Role? mailboxRole, + MessageIdsHeaderValue? messageId, + MessageIdsHeaderValue? references, }) => ComposerArguments( emailActionType: EmailActionType.reply, presentationEmail: presentationEmail, emailContents: content, - mailboxRole: mailboxRole + mailboxRole: mailboxRole, + messageId: messageId, + references: references, ); factory ComposerArguments.replyAllEmail({ required PresentationEmail presentationEmail, required String content, Role? mailboxRole, + MessageIdsHeaderValue? messageId, + MessageIdsHeaderValue? references, }) => ComposerArguments( emailActionType: EmailActionType.replyAll, presentationEmail: presentationEmail, emailContents: content, - mailboxRole: mailboxRole + mailboxRole: mailboxRole, + messageId: messageId, + references: references, ); factory ComposerArguments.forwardEmail({