Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TF-3379 Fix email sent to mailing list from other people dont have replyAll button #3391

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class _EmailReceiverWidgetState extends State<EmailReceiverWidget> {
]
),
),
if (widget.emailSelected.numberOfAllEmailAddress() > 1)
if (widget.emailSelected.countRecipients > 1)
TMailButtonWidget.fromIcon(
icon: _imagePaths.icChevronDown,
backgroundColor: Colors.transparent,
Expand Down Expand Up @@ -217,7 +217,7 @@ class _EmailReceiverWidgetState extends State<EmailReceiverWidget> {
]
),
),
if (widget.emailSelected.numberOfAllEmailAddress() > 1)
if (widget.emailSelected.countRecipients > 1)
TMailButtonWidget.fromIcon(
icon: _imagePaths.icChevronDown,
backgroundColor: Colors.transparent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions model/lib/extensions/list_email_address_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ extension SetEmailAddressExtension on Set<EmailAddress>? {
? this!.where((emailAddress) => emailAddress.email != emailAddressNotExist).toList()
: List.empty();
}

Set<EmailAddress> withoutMe(String userName) {
return filterEmailAddress(userName).toSet();
}
}

extension ListEmailAddressExtension on List<EmailAddress> {
Expand Down
11 changes: 10 additions & 1 deletion model/lib/extensions/presentation_email_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
hoangdat marked this conversation as resolved.
Show resolved Hide resolved

String getReceivedAt(String newLocale, {String? pattern}) {
final emailTime = receivedAt;
Expand Down
65 changes: 65 additions & 0 deletions model/test/extensions/presentattion_email_extension_test.dart
Original file line number Diff line number Diff line change
@@ -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', '[email protected]')},
cc: {EmailAddress('Bob', '[email protected]')},
bcc: {EmailAddress('Charlie', '[email protected]')},
from: {EmailAddress('User', '[email protected]')},
);

// Act
final count = email.getCountMailAddressWithoutMe('[email protected]');

// Assert
expect(count, 3);
});

test('Should return 0 when all email addresses are the user', () {
// Arrange
final email = PresentationEmail(
to: {EmailAddress('User', '[email protected]')},
cc: {EmailAddress('User', '[email protected]')},
bcc: {EmailAddress('User', '[email protected]')},
from: {EmailAddress('User', '[email protected]')},
);

// Act
final count = email.getCountMailAddressWithoutMe('[email protected]');

// Assert
expect(count, 0);
});

test('Should return the correct count excluding multiple instances of the user', () {
// Arrange
final email = PresentationEmail(
to: {
EmailAddress('Alice', '[email protected]'),
EmailAddress('User', '[email protected]')
},
cc: {
EmailAddress('User', '[email protected]')
},
bcc: {
EmailAddress('Charlie', '[email protected]')
},
from: {
EmailAddress('User', '[email protected]')
},
);

// Act
final count = email.getCountMailAddressWithoutMe('[email protected]');

// Assert
expect(count, 2);
});
});
}
Loading