diff --git a/lib/features/email/presentation/controller/single_email_controller.dart b/lib/features/email/presentation/controller/single_email_controller.dart index 6918ee5256..b5a703bd3b 100644 --- a/lib/features/email/presentation/controller/single_email_controller.dart +++ b/lib/features/email/presentation/controller/single_email_controller.dart @@ -17,6 +17,7 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/session/session.dart'; +import 'package:jmap_dart_client/jmap/core/user_name.dart'; import 'package:jmap_dart_client/jmap/identities/identity.dart'; import 'package:jmap_dart_client/jmap/mail/calendar/calendar_event.dart'; import 'package:jmap_dart_client/jmap/mail/calendar/properties/attendee/calendar_attendee.dart'; @@ -174,6 +175,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin { Session? get session => mailboxDashBoardController.sessionCurrent; + UserName? get userName => session?.username; + SingleEmailController( this._getEmailContentInteractor, this._markAsEmailReadInteractor, diff --git a/lib/features/email/presentation/widgets/email_receiver_widget.dart b/lib/features/email/presentation/widgets/email_receiver_widget.dart index 636caaf1c5..b548471bb2 100644 --- a/lib/features/email/presentation/widgets/email_receiver_widget.dart +++ b/lib/features/email/presentation/widgets/email_receiver_widget.dart @@ -132,7 +132,7 @@ class _EmailReceiverWidgetState extends State { ] ), ), - if (widget.emailSelected.numberOfAllEmailAddress() > 1) + if (widget.emailSelected.countRecipients > 1) TMailButtonWidget.fromIcon( icon: _imagePaths.icChevronDown, backgroundColor: Colors.transparent, @@ -217,7 +217,7 @@ class _EmailReceiverWidgetState extends State { ] ), ), - if (widget.emailSelected.numberOfAllEmailAddress() > 1) + if (widget.emailSelected.countRecipients > 1) TMailButtonWidget.fromIcon( icon: _imagePaths.icChevronDown, backgroundColor: Colors.transparent, diff --git a/lib/features/email/presentation/widgets/email_view_bottom_bar_widget.dart b/lib/features/email/presentation/widgets/email_view_bottom_bar_widget.dart index c0d55c4702..381ab3f984 100644 --- a/lib/features/email/presentation/widgets/email_view_bottom_bar_widget.dart +++ b/lib/features/email/presentation/widgets/email_view_bottom_bar_widget.dart @@ -48,8 +48,11 @@ class EmailViewBottomBarWidget extends StatelessWidget { child: Row( children: [ Obx(() { - if (_singleEmailController.currentEmailLoaded.value != null - && presentationEmail.numberOfAllEmailAddress() > 1) { + final emailLoader = _singleEmailController.currentEmailLoaded.value; + final countMailAddress = presentationEmail.getCountMailAddressWithoutMe( + _singleEmailController.userName?.value ?? '', + ); + if (emailLoader != null && countMailAddress > 1) { return Expanded( child: TMailButtonWidget( key: const Key('reply_all_emails_button'), diff --git a/lib/features/email/presentation/widgets/information_sender_and_receiver_builder.dart b/lib/features/email/presentation/widgets/information_sender_and_receiver_builder.dart index 65961b3eeb..50777bea8e 100644 --- a/lib/features/email/presentation/widgets/information_sender_and_receiver_builder.dart +++ b/lib/features/email/presentation/widgets/information_sender_and_receiver_builder.dart @@ -44,7 +44,7 @@ class InformationSenderAndReceiverBuilder extends StatelessWidget { return Padding( padding: const EdgeInsetsDirectional.only(start: 16, end: 16, top: 16), child: Row( - crossAxisAlignment: emailSelected.numberOfAllEmailAddress() > 0 + crossAxisAlignment: emailSelected.countRecipients > 0 ? CrossAxisAlignment.start : CrossAxisAlignment.center, children: [ @@ -96,7 +96,7 @@ class InformationSenderAndReceiverBuilder extends StatelessWidget { )), ReceivedTimeBuilder(emailSelected: emailSelected), ]), - if (emailSelected.numberOfAllEmailAddress() > 0) + if (emailSelected.countRecipients > 0) EmailReceiverWidget( emailSelected: emailSelected, maxWidth: constraints.maxWidth, diff --git a/lib/features/sending_queue/presentation/widgets/sending_email_tile_widget.dart b/lib/features/sending_queue/presentation/widgets/sending_email_tile_widget.dart index 8b5d65837e..51705e2dfa 100644 --- a/lib/features/sending_queue/presentation/widgets/sending_email_tile_widget.dart +++ b/lib/features/sending_queue/presentation/widgets/sending_email_tile_widget.dart @@ -76,7 +76,7 @@ class SendingEmailTileWidget extends StatelessWidget { ) else SvgPicture.asset( - sendingEmail.presentationEmail.numberOfAllEmailAddress() == 1 + sendingEmail.presentationEmail.countRecipients == 1 ? sendingEmail.sendingState.getAvatarPersonal(_imagePaths) : sendingEmail.sendingState.getAvatarGroup(_imagePaths), fit: BoxFit.fill, diff --git a/model/lib/extensions/list_email_address_extension.dart b/model/lib/extensions/list_email_address_extension.dart index 41b4628e8a..ebece29a4f 100644 --- a/model/lib/extensions/list_email_address_extension.dart +++ b/model/lib/extensions/list_email_address_extension.dart @@ -47,6 +47,10 @@ extension SetEmailAddressExtension on Set? { ? this!.where((emailAddress) => emailAddress.email != emailAddressNotExist).toList() : List.empty(); } + + Set withoutMe(String userName) { + return filterEmailAddress(userName).toSet(); + } } extension ListEmailAddressExtension on List { diff --git a/model/lib/extensions/presentation_email_extension.dart b/model/lib/extensions/presentation_email_extension.dart index 7b1c5c46e9..f329e164ab 100644 --- a/model/lib/extensions/presentation_email_extension.dart +++ b/model/lib/extensions/presentation_email_extension.dart @@ -29,7 +29,16 @@ extension PresentationEmailExtension on PresentationEmail { } } - int numberOfAllEmailAddress() => to.numberEmailAddress() + cc.numberEmailAddress() + bcc.numberEmailAddress(); + int get countRecipients => + to.numberEmailAddress() + + cc.numberEmailAddress() + + bcc.numberEmailAddress(); + + int getCountMailAddressWithoutMe(String userName) => + to.withoutMe(userName).numberEmailAddress() + + cc.withoutMe(userName).numberEmailAddress() + + bcc.withoutMe(userName).numberEmailAddress() + + from.withoutMe(userName).numberEmailAddress(); String getReceivedAt(String newLocale, {String? pattern}) { final emailTime = receivedAt; diff --git a/model/test/extensions/presentattion_email_extension_test.dart b/model/test/extensions/presentattion_email_extension_test.dart new file mode 100644 index 0000000000..1eebaa3136 --- /dev/null +++ b/model/test/extensions/presentattion_email_extension_test.dart @@ -0,0 +1,65 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:jmap_dart_client/jmap/mail/email/email_address.dart'; +import 'package:model/extensions/presentation_email_extension.dart'; +import 'package:model/email/presentation_email.dart'; + +void main() { + group('PresentationEmailExtension::getCountMailAddressWithoutMe::', () { + test('Should return the correct count of email addresses excluding the user', () { + // Arrange + final email = PresentationEmail( + to: {EmailAddress('Alice', 'alice@example.com')}, + cc: {EmailAddress('Bob', 'bob@example.com')}, + bcc: {EmailAddress('Charlie', 'charlie@example.com')}, + from: {EmailAddress('User', 'user@example.com')}, + ); + + // Act + final count = email.getCountMailAddressWithoutMe('user@example.com'); + + // Assert + expect(count, 3); + }); + + test('Should return 0 when all email addresses are the user', () { + // Arrange + final email = PresentationEmail( + to: {EmailAddress('User', 'user@example.com')}, + cc: {EmailAddress('User', 'user@example.com')}, + bcc: {EmailAddress('User', 'user@example.com')}, + from: {EmailAddress('User', 'user@example.com')}, + ); + + // Act + final count = email.getCountMailAddressWithoutMe('user@example.com'); + + // Assert + expect(count, 0); + }); + + test('Should return the correct count excluding multiple instances of the user', () { + // Arrange + final email = PresentationEmail( + to: { + EmailAddress('Alice', 'alice@example.com'), + EmailAddress('User', 'user@example.com') + }, + cc: { + EmailAddress('User', 'user@example.com') + }, + bcc: { + EmailAddress('Charlie', 'charlie@example.com') + }, + from: { + EmailAddress('User', 'user@example.com') + }, + ); + + // Act + final count = email.getCountMailAddressWithoutMe('user@example.com'); + + // Assert + expect(count, 2); + }); + }); +}