From 8d6bbccc567e80ff20e2b0813c921fde1d00483d Mon Sep 17 00:00:00 2001 From: dab246 Date: Wed, 19 Feb 2025 15:52:00 +0700 Subject: [PATCH] Handle the behaviour of Reply email when user is sender Signed-off-by: dab246 --- .../presentation_email_extension.dart | 23 +++++++++++++++---- .../presentation_email_extension.dart | 20 ++++++++++++---- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/lib/features/email/presentation/extensions/presentation_email_extension.dart b/lib/features/email/presentation/extensions/presentation_email_extension.dart index 60bc242e4..fd7ae0f24 100644 --- a/lib/features/email/presentation/extensions/presentation_email_extension.dart +++ b/lib/features/email/presentation/extensions/presentation_email_extension.dart @@ -1,8 +1,10 @@ +import 'package:collection/collection.dart'; import 'package:dartz/dartz.dart'; import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; import 'package:model/email/email_action_type.dart'; import 'package:model/email/presentation_email.dart'; +import 'package:model/extensions/email_address_extension.dart'; import 'package:model/extensions/list_email_address_extension.dart'; import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart'; @@ -25,6 +27,7 @@ extension PresentationEmailExtension on PresentationEmail { isSender: isSender, newToAddress: newToAddress, newFromAddress: newFromAddress, + newBccAddress: newBccAddress, newReplyToAddress: newReplyToAddress, userName: userName, ); @@ -52,15 +55,27 @@ extension PresentationEmailExtension on PresentationEmail { required bool isSender, required List newToAddress, required List newFromAddress, + required List newBccAddress, required List newReplyToAddress, String? userName, }) { if (isSender) { - return Tuple4(newToAddress, [], [], newReplyToAddress); + if (newBccAddress.isNotEmpty) { + return Tuple4(newToAddress, [], [], newReplyToAddress); + } + if (newReplyToAddress.isNotEmpty) { + return Tuple4(newReplyToAddress, [], [], []); + } + if (userName != null) { + final userEmail = newToAddress.firstWhereOrNull((address) => address.emailAddress == userName); + if (userEmail != null) { + return Tuple4([userEmail], [], [], []); + } + } + return Tuple4(newToAddress, [], [], []); } - final listToAddress = newReplyToAddress.isNotEmpty - ? newReplyToAddress.withoutMe(userName) - : newFromAddress.withoutMe(userName); + + final listToAddress = (newReplyToAddress.isNotEmpty ? newReplyToAddress : newFromAddress).withoutMe(userName); return Tuple4(listToAddress, [], [], []); } diff --git a/model/lib/extensions/presentation_email_extension.dart b/model/lib/extensions/presentation_email_extension.dart index 9d6912aaa..55decbcc8 100644 --- a/model/lib/extensions/presentation_email_extension.dart +++ b/model/lib/extensions/presentation_email_extension.dart @@ -32,11 +32,21 @@ extension PresentationEmailExtension on PresentationEmail { cc.numberEmailAddress() + bcc.numberEmailAddress(); - int getCountMailAddressWithoutMe(String userName) => - to.withoutMe(userName).numberEmailAddress() + - cc.withoutMe(userName).numberEmailAddress() + - bcc.withoutMe(userName).numberEmailAddress() + - from.withoutMe(userName).numberEmailAddress(); + int getCountMailAddressWithoutMe(String userName) { + final uniqueEmails = {}; + final newTo = to ?? {}; + final newCc = cc ?? {}; + final newBcc = bcc ?? {}; + final newFrom = from ?? {}; + + for (final email in [...newTo, ...newCc, ...newBcc, ...newFrom]) { + if (email.emailAddress != userName) { + uniqueEmails.add(email.emailAddress); + } + } + + return uniqueEmails.length; + } String getReceivedAt(String newLocale, {String? pattern}) { final emailTime = receivedAt;