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

Fix recipient chips not auto create #3350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
81 changes: 46 additions & 35 deletions lib/features/composer/presentation/composer_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1601,16 +1601,16 @@ class ComposerController extends BaseController
final inputReplyToEmail = replyToEmailAddressController.text;

if (inputToEmail.isNotEmpty) {
_autoCreateToEmailTag(MailAddress.validateAddress(inputToEmail));
_autoCreateToEmailTag(inputToEmail);
}
if (inputCcEmail.isNotEmpty) {
_autoCreateCcEmailTag(MailAddress.validateAddress(inputCcEmail));
_autoCreateCcEmailTag(inputCcEmail);
}
if (inputBccEmail.isNotEmpty) {
_autoCreateBccEmailTag(MailAddress.validateAddress(inputBccEmail));
_autoCreateBccEmailTag(inputBccEmail);
}
if (inputReplyToEmail.isNotEmpty) {
_autoCreateReplyToEmailTag(MailAddress.validateAddress(inputReplyToEmail));
_autoCreateReplyToEmailTag(inputReplyToEmail);
}
}

Expand All @@ -1621,53 +1621,64 @@ class ComposerController extends BaseController
.contains(inputEmail);
}

void _autoCreateToEmailTag(MailAddress inputMailAddress) {
if (!_isDuplicatedRecipient(inputMailAddress.asEncodedString(), listToEmailAddress)) {
listToEmailAddress.add(inputMailAddress.asEmailAddress());
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
void _updateListEmailAddressByPrefix(
PrefixEmailAddress prefixEmailAddress,
String email,
) {
final listEmailAddressByPrefix = {
PrefixEmailAddress.to: listToEmailAddress,
PrefixEmailAddress.cc: listCcEmailAddress,
PrefixEmailAddress.bcc: listBccEmailAddress,
PrefixEmailAddress.replyTo: listReplyToEmailAddress,
};
final currentHandlingListEmailAddress = listEmailAddressByPrefix[prefixEmailAddress] ?? [];
try {
final inputMailAddress = MailAddress.validateAddress(email);
if (!_isDuplicatedRecipient(inputMailAddress.asEncodedString(), currentHandlingListEmailAddress)) {
currentHandlingListEmailAddress.add(inputMailAddress.asEmailAddress());
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
}
} catch (e) {
log('ComposerController::_updateListEmailAddressOfPrefix(): $e');
final emailAddress = EmailAddress(null, email);
if (!_isDuplicatedRecipient(email, currentHandlingListEmailAddress)) {
currentHandlingListEmailAddress.add(emailAddress);
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
}
}
}

void _autoCreateToEmailTag(String email) {
_updateListEmailAddressByPrefix(PrefixEmailAddress.to, email);
log('ComposerController::_autoCreateToEmailTag(): STATE: ${keyToEmailTagEditor.currentState}');
keyToEmailTagEditor.currentState?.resetTextField();
Future.delayed(const Duration(milliseconds: 300), () {
keyToEmailTagEditor.currentState?.closeSuggestionBox();
});
}

void _autoCreateCcEmailTag(MailAddress inputMailAddress) {
if (!_isDuplicatedRecipient(inputMailAddress.asEncodedString(), listCcEmailAddress)) {
listCcEmailAddress.add(inputMailAddress.asEmailAddress());
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
}
void _autoCreateCcEmailTag(String email) {
_updateListEmailAddressByPrefix(PrefixEmailAddress.cc, email);
keyCcEmailTagEditor.currentState?.resetTextField();
Future.delayed(const Duration(milliseconds: 300), () {
keyCcEmailTagEditor.currentState?.closeSuggestionBox();
});
}

void _autoCreateBccEmailTag(MailAddress inputMailAddress) {
if (!_isDuplicatedRecipient(inputMailAddress.asEncodedString(), listBccEmailAddress)) {
listBccEmailAddress.add(inputMailAddress.asEmailAddress());
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
}
void _autoCreateBccEmailTag(String email) {
_updateListEmailAddressByPrefix(PrefixEmailAddress.bcc, email);
keyBccEmailTagEditor.currentState?.resetTextField();
Future.delayed(const Duration(milliseconds: 300), () {
keyBccEmailTagEditor.currentState?.closeSuggestionBox();
});
}

void _autoCreateReplyToEmailTag(MailAddress inputMailAddress) {
if (!_isDuplicatedRecipient(inputMailAddress.asEncodedString(), listReplyToEmailAddress)) {
listReplyToEmailAddress.add(inputMailAddress.asEmailAddress());
isInitialRecipient.value = true;
isInitialRecipient.refresh();
_updateStatusEmailSendButton();
}
void _autoCreateReplyToEmailTag(String email) {
_updateListEmailAddressByPrefix(PrefixEmailAddress.replyTo, email);
keyReplyToEmailTagEditor.currentState?.resetTextField();
Future.delayed(const Duration(milliseconds: 300), () {
keyReplyToEmailTagEditor.currentState?.closeSuggestionBox();
Expand Down Expand Up @@ -1742,28 +1753,28 @@ class ComposerController extends BaseController
toAddressExpandMode.value = ExpandMode.COLLAPSE;
final inputToEmail = toEmailAddressController.text;
if (inputToEmail.isNotEmpty) {
_autoCreateToEmailTag(MailAddress.validateAddress(inputToEmail));
_autoCreateToEmailTag(inputToEmail);
}
break;
case PrefixEmailAddress.cc:
ccAddressExpandMode.value = ExpandMode.COLLAPSE;
final inputCcEmail = ccEmailAddressController.text;
if (inputCcEmail.isNotEmpty) {
_autoCreateCcEmailTag(MailAddress.validateAddress(inputCcEmail));
_autoCreateCcEmailTag(inputCcEmail);
}
break;
case PrefixEmailAddress.bcc:
bccAddressExpandMode.value = ExpandMode.COLLAPSE;
final inputBccEmail = bccEmailAddressController.text;
if (inputBccEmail.isNotEmpty) {
_autoCreateBccEmailTag(MailAddress.validateAddress(inputBccEmail));
_autoCreateBccEmailTag(inputBccEmail);
}
break;
case PrefixEmailAddress.replyTo:
replyToAddressExpandMode.value = ExpandMode.COLLAPSE;
final inputReplyToEmail = replyToEmailAddressController.text;
if (inputReplyToEmail.isNotEmpty) {
_autoCreateReplyToEmailTag(MailAddress.validateAddress(inputReplyToEmail));
_autoCreateReplyToEmailTag(inputReplyToEmail);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
return RecipientSuggestionItemWidget(
imagePaths: widget.imagePaths,
suggestionState: suggestionEmailAddress.state,
emailAddress: MailAddress.validateAddress(suggestionEmailAddress.emailAddress.emailAddress).asEmailAddress(),
emailAddress: _subAdressingValidatedEmailAddress(suggestionEmailAddress.emailAddress),
suggestionValid: suggestionValid,
highlight: highlight,
onSelectedAction: (emailAddress) {
Expand Down Expand Up @@ -306,7 +306,7 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
return RecipientSuggestionItemWidget(
imagePaths: widget.imagePaths,
suggestionState: suggestionEmailAddress.state,
emailAddress: MailAddress.validateAddress(suggestionEmailAddress.emailAddress.emailAddress).asEmailAddress(),
emailAddress: _subAdressingValidatedEmailAddress(suggestionEmailAddress.emailAddress),
suggestionValid: suggestionValid,
highlight: highlight,
onSelectedAction: (emailAddress) {
Expand Down Expand Up @@ -506,40 +506,53 @@ class _RecipientComposerWidgetState extends State<RecipientComposerWidget> {
void _handleSelectOptionAction(
SuggestionEmailAddress suggestionEmailAddress,
StateSetter stateSetter
) {
MailAddress mailAddress = MailAddress.validateAddress(suggestionEmailAddress.emailAddress.emailAddress);
if (!_isDuplicatedRecipient(mailAddress.asEncodedString())) {
stateSetter(() => _currentListEmailAddress.add(mailAddress.asEmailAddress()));
_updateListEmailAddressAction();
}
}
) => _onEmailAddressReceived(
suggestionEmailAddress.emailAddress.emailAddress,
stateSetter);

void _handleSubmitTagAction(
String value,
StateSetter stateSetter
) {
MailAddress mailAddress = MailAddress.validateAddress(value.trim());
if (!_isDuplicatedRecipient(mailAddress.asEncodedString())) {
stateSetter(() => _currentListEmailAddress.add(mailAddress.asEmailAddress()));
_updateListEmailAddressAction();
}
}
) => _onEmailAddressReceived(value, stateSetter);

void _handleOnTagChangeAction(
String value,
StateSetter stateSetter
) {
MailAddress mailAddress = MailAddress.validateAddress(value.trim());
if (!_isDuplicatedRecipient(mailAddress.asEncodedString())) {
stateSetter(() => _currentListEmailAddress.add(mailAddress.asEmailAddress()));
_updateListEmailAddressAction();
}
_onEmailAddressReceived(value, stateSetter);
_gapBetweenTagChangedAndFindSuggestion = Timer(
const Duration(seconds: 1),
_handleGapBetweenTagChangedAndFindSuggestion
);
}

void _onEmailAddressReceived(String email, StateSetter stateSetter) {
try {
final mailAddress = MailAddress.validateAddress(email.trim());
if (!_isDuplicatedRecipient(mailAddress.asEncodedString())) {
stateSetter(() => _currentListEmailAddress.add(mailAddress.asEmailAddress()));
_updateListEmailAddressAction();
}
} catch (e) {
logError('_RecipientComposerWidgetState::_onEmailAddressReceived:Exception = $e');
final emailAddress = EmailAddress(null, email);
if (!_isDuplicatedRecipient(email)) {
stateSetter(() => _currentListEmailAddress.add(emailAddress));
_updateListEmailAddressAction();
}
}
}

EmailAddress _subAdressingValidatedEmailAddress(EmailAddress emailAddress) {
try {
final mailAddress = MailAddress.validateAddress(emailAddress.emailAddress);
return mailAddress.asEmailAddress();
} catch (e) {
logError('_RecipientComposerWidgetState::_subAdressingValidated:Exception = $e');
return emailAddress;
}
}

void _handleAcceptDraggableEmailAddressAction(
DraggableEmailAddress draggableEmailAddress,
StateSetter stateSetter
Expand Down
Loading