Handle the behaviour of Reply/ReplyToList/ReplyAll button
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -21,85 +21,84 @@ extension PresentationEmailExtension on PresentationEmail {
|
||||
|
||||
switch (emailActionType) {
|
||||
case EmailActionType.reply:
|
||||
List<EmailAddress> listReplyAddress;
|
||||
if (newReplyToAddress.isNotEmpty) {
|
||||
listReplyAddress = newReplyToAddress;
|
||||
} else if (isSender) {
|
||||
listReplyAddress = newToAddress;
|
||||
} else {
|
||||
listReplyAddress = newFromAddress;
|
||||
}
|
||||
final listReplyAddressWithoutUsername = listReplyAddress.withoutMe(userName);
|
||||
return _handleReply(
|
||||
isSender: isSender,
|
||||
newToAddress: newToAddress,
|
||||
newFromAddress: newFromAddress,
|
||||
newReplyToAddress: newReplyToAddress,
|
||||
userName: userName,
|
||||
);
|
||||
|
||||
return Tuple4(listReplyAddressWithoutUsername, [], [], []);
|
||||
case EmailActionType.replyToList:
|
||||
final recipientRecord = EmailUtils.extractRecipientsFromListPost(listPost ?? '');
|
||||
return _handleReplyToList(listPost, userName);
|
||||
|
||||
final listToAddressWithoutUsername = recipientRecord.toMailAddresses
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
|
||||
final listCcAddressWithoutUsername = recipientRecord.ccMailAddresses
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
|
||||
final listBccAddressWithoutUsername = recipientRecord.bccMailAddresses
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
|
||||
return Tuple4(
|
||||
listToAddressWithoutUsername,
|
||||
listCcAddressWithoutUsername,
|
||||
listBccAddressWithoutUsername,
|
||||
[]
|
||||
);
|
||||
case EmailActionType.replyAll:
|
||||
final recipientRecord = EmailUtils.extractRecipientsFromListPost(listPost ?? '');
|
||||
|
||||
final listToAddress = recipientRecord.toMailAddresses
|
||||
+ newReplyToAddress
|
||||
+ newFromAddress
|
||||
+ newToAddress;
|
||||
final listCcAddress = recipientRecord.ccMailAddresses + newCcAddress;
|
||||
final listBccAddress = recipientRecord.bccMailAddresses + newBccAddress;
|
||||
|
||||
final listToAddressWithoutUsername = listToAddress
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
final listCcAddressWithoutUsername = listCcAddress
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
final listBccAddressWithoutUsername = listBccAddress
|
||||
.toSet()
|
||||
.removeDuplicateEmails()
|
||||
.withoutMe(userName);
|
||||
|
||||
return Tuple4(
|
||||
listToAddressWithoutUsername,
|
||||
listCcAddressWithoutUsername,
|
||||
listBccAddressWithoutUsername,
|
||||
[]
|
||||
return _handleReplyAll(
|
||||
isSender: isSender,
|
||||
newToAddress: newToAddress,
|
||||
newCcAddress: newCcAddress,
|
||||
newBccAddress: newBccAddress,
|
||||
newReplyToAddress: newReplyToAddress,
|
||||
newFromAddress: newFromAddress,
|
||||
userName: userName,
|
||||
);
|
||||
|
||||
case EmailActionType.editDraft:
|
||||
return Tuple4(newToAddress, newCcAddress, newBccAddress, newReplyToAddress);
|
||||
|
||||
default:
|
||||
final listToAddressWithoutUsername = newToAddress.withoutMe(userName);
|
||||
final listCcAddressWithoutUsername = newCcAddress.withoutMe(userName);
|
||||
final listBccAddressWithoutUsername = newBccAddress.withoutMe(userName);
|
||||
|
||||
return Tuple4(
|
||||
listToAddressWithoutUsername,
|
||||
listCcAddressWithoutUsername,
|
||||
listBccAddressWithoutUsername,
|
||||
[]
|
||||
);
|
||||
return Tuple4(newToAddress, newCcAddress, newBccAddress, newReplyToAddress);
|
||||
}
|
||||
}
|
||||
|
||||
Tuple4<List<EmailAddress>, List<EmailAddress>, List<EmailAddress>, List<EmailAddress>> _handleReply({
|
||||
required bool isSender,
|
||||
required List<EmailAddress> newToAddress,
|
||||
required List<EmailAddress> newFromAddress,
|
||||
required List<EmailAddress> newReplyToAddress,
|
||||
String? userName,
|
||||
}) {
|
||||
if (isSender) {
|
||||
return Tuple4(newToAddress, [], [], newReplyToAddress);
|
||||
}
|
||||
final listToAddress = newReplyToAddress.isNotEmpty
|
||||
? newReplyToAddress.withoutMe(userName)
|
||||
: newFromAddress.withoutMe(userName);
|
||||
return Tuple4(listToAddress, [], [], []);
|
||||
}
|
||||
|
||||
Tuple4<List<EmailAddress>, List<EmailAddress>, List<EmailAddress>, List<EmailAddress>> _handleReplyToList(String? listPost, String? userName) {
|
||||
final recipientRecord = EmailUtils.extractRecipientsFromListPost(listPost ?? '');
|
||||
|
||||
return Tuple4(
|
||||
recipientRecord.toMailAddresses.removeDuplicateEmails().withoutMe(userName),
|
||||
recipientRecord.ccMailAddresses.removeDuplicateEmails().withoutMe(userName),
|
||||
recipientRecord.bccMailAddresses.removeDuplicateEmails().withoutMe(userName),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
Tuple4<List<EmailAddress>, List<EmailAddress>, List<EmailAddress>, List<EmailAddress>> _handleReplyAll({
|
||||
required bool isSender,
|
||||
required List<EmailAddress> newToAddress,
|
||||
required List<EmailAddress> newCcAddress,
|
||||
required List<EmailAddress> newBccAddress,
|
||||
required List<EmailAddress> newReplyToAddress,
|
||||
required List<EmailAddress> newFromAddress,
|
||||
String? userName,
|
||||
}) {
|
||||
if (isSender) {
|
||||
return Tuple4(newToAddress, newCcAddress, newBccAddress, newReplyToAddress);
|
||||
}
|
||||
|
||||
final listToAddress = {
|
||||
...(newReplyToAddress.isNotEmpty ? newReplyToAddress : newFromAddress),
|
||||
...newToAddress,
|
||||
}.removeDuplicateEmails().withoutMe(userName);
|
||||
|
||||
return Tuple4(
|
||||
listToAddress,
|
||||
newCcAddress.withoutMe(userName),
|
||||
newBccAddress.withoutMe(userName),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -218,4 +218,11 @@ class EmailUtils {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static bool isReplyToListEnabled(String listPost) {
|
||||
final recipientRecord = EmailUtils.extractRecipientsFromListPost(listPost);
|
||||
return recipientRecord.toMailAddresses.isNotEmpty ||
|
||||
recipientRecord.ccMailAddresses.isNotEmpty ||
|
||||
recipientRecord.bccMailAddresses.isNotEmpty;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import 'package:model/extensions/email_extension.dart';
|
||||
import 'package:model/extensions/presentation_email_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/controller/single_email_controller.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/styles/email_view_bottom_bar_widget_styles.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/utils/email_utils.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
typedef OnEmailActionCallback = void Function(EmailActionType, PresentationEmail);
|
||||
@@ -76,9 +77,10 @@ class EmailViewBottomBarWidget extends StatelessWidget {
|
||||
}),
|
||||
Obx(() {
|
||||
final currentEmailLoaded = _singleEmailController.currentEmailLoaded.value;
|
||||
|
||||
if (currentEmailLoaded != null &&
|
||||
currentEmailLoaded.emailCurrent?.hasListPost == true) {
|
||||
final isReplyToListEnabled = EmailUtils.isReplyToListEnabled(
|
||||
currentEmailLoaded?.emailCurrent?.listPost ?? '',
|
||||
);
|
||||
if (currentEmailLoaded != null && isReplyToListEnabled) {
|
||||
return Expanded(
|
||||
child: TMailButtonWidget(
|
||||
key: const Key('reply_to_list_email_button'),
|
||||
|
||||
Reference in New Issue
Block a user