From ccb0112bead88189ca425b791d4cc9b9f278e14d Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 27 May 2022 19:44:54 +0700 Subject: [PATCH] TF-597 Fix cannot update null value for identity bcc and replyTo address --- .../identity_creator_controller.dart | 44 ++++++++++--------- .../presentation/identity_creator_view.dart | 12 ++++- model/lib/identity/identity_request_dto.dart | 9 ---- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/lib/features/identity_creator/presentation/identity_creator_controller.dart b/lib/features/identity_creator/presentation/identity_creator_controller.dart index 1eaea7f5b..0a7785e52 100644 --- a/lib/features/identity_creator/presentation/identity_creator_controller.dart +++ b/lib/features/identity_creator/presentation/identity_creator_controller.dart @@ -176,22 +176,16 @@ class IdentityCreatorController extends BaseController { replyToOfIdentity.value = listEmailAddressOfReplyTo .firstWhere((emailAddress) => emailAddress == identity?.replyTo!.first); } catch(e) { - replyToOfIdentity.value = null; + replyToOfIdentity.value = noneEmailAddress; } } else { - replyToOfIdentity.value = null; + replyToOfIdentity.value = noneEmailAddress; } log('IdentityCreatorController::_setUpAllFieldEmailAddress(): replyToOfIdentity: ${replyToOfIdentity.value}'); if (identity?.bcc?.isNotEmpty == true) { - try { - bccOfIdentity.value = listEmailAddressOfReplyTo - .firstWhere((emailAddress) => emailAddress == identity?.bcc!.first); - - inputBccIdentityController.text = bccOfIdentity.value?.email ?? ''; - } catch(e) { - bccOfIdentity.value = null; - } + bccOfIdentity.value = identity?.bcc!.first; + inputBccIdentityController.text = identity?.bcc!.first.emailAddress ?? ''; } else { bccOfIdentity.value = null; } @@ -220,7 +214,7 @@ class IdentityCreatorController extends BaseController { } void selectSignatureType(BuildContext context, SignatureType newSignatureType) async { - if (newSignatureType == SignatureType.plainText) { + if (newSignatureType == SignatureType.plainText && !BuildUtils.isWeb) { final signatureText = await _getSignatureHtmlText(); log('IdentityCreatorController::selectSignatureType(): signatureText: $signatureText'); updateContentHtmlEditor(signatureText); @@ -243,9 +237,9 @@ class IdentityCreatorController extends BaseController { Future _getSignatureHtmlText() async { if (BuildUtils.isWeb) { - return await signatureHtmlEditorController.getText(); + return signatureHtmlEditorController.getText(); } else { - return await signatureHtmlEditorMobileController?.getText(); + return signatureHtmlEditorMobileController?.getText(); } } @@ -266,20 +260,28 @@ class IdentityCreatorController extends BaseController { return; } - final signatureHtmlText = await _getSignatureHtmlText(); + final signaturePlainText = signaturePlainEditorController.text; + final signatureHtmlText = BuildUtils.isWeb + ? contentHtmlEditor + : await _getSignatureHtmlText(); + final bccAddress = bccOfIdentity.value != null && bccOfIdentity.value != noneEmailAddress + ? {bccOfIdentity.value!} + : {}; + final replyToAddress = replyToOfIdentity.value != null && replyToOfIdentity.value != noneEmailAddress + ? {replyToOfIdentity.value!} + : {}; + log('IdentityCreatorController::createNewIdentity(): bccAddress: $bccAddress'); + log('IdentityCreatorController::createNewIdentity(): replyToAddress: $replyToAddress'); + log('IdentityCreatorController::createNewIdentity(): signaturePlainText: $signaturePlainText'); log('IdentityCreatorController::createNewIdentity(): signatureHtmlText: $signatureHtmlText'); final newIdentity = Identity( name: _nameIdentity, email: emailOfIdentity.value?.email, - replyTo: replyToOfIdentity.value != null && replyToOfIdentity.value != noneEmailAddress - ? {replyToOfIdentity.value!} - : null, - bcc: bccOfIdentity.value != null && bccOfIdentity.value != noneEmailAddress - ? {bccOfIdentity.value!} - : null, - textSignature: Signature(signaturePlainEditorController.text), + replyTo: replyToAddress, + bcc: bccAddress, + textSignature: Signature(signaturePlainText), htmlSignature: Signature(signatureHtmlText ?? '')); log('IdentityCreatorController::createNewIdentity(): $newIdentity'); diff --git a/lib/features/identity_creator/presentation/identity_creator_view.dart b/lib/features/identity_creator/presentation/identity_creator_view.dart index c055d5cd8..2e6e8c33d 100644 --- a/lib/features/identity_creator/presentation/identity_creator_view.dart +++ b/lib/features/identity_creator/presentation/identity_creator_view.dart @@ -187,7 +187,11 @@ class IdentityCreatorView extends GetWidget { }) ..addOnChangeInputSuggestionAction((pattern) { controller.validateInputBccAddress(context, pattern); - controller.updateBccOfIdentity(EmailAddress(null, pattern)); + if (pattern == null || pattern.trim().isEmpty) { + controller.updateBccOfIdentity(null); + } else { + controller.updateBccOfIdentity(EmailAddress(null, pattern)); + } }) ..addOnSuggestionCallbackAction((pattern) => controller.getSuggestionEmailAddress(pattern))) @@ -328,7 +332,11 @@ class IdentityCreatorView extends GetWidget { }) ..addOnChangeInputSuggestionAction((pattern) { controller.validateInputBccAddress(context, pattern); - controller.updateBccOfIdentity(EmailAddress(null, pattern)); + if (pattern == null || pattern.trim().isEmpty) { + controller.updateBccOfIdentity(null); + } else { + controller.updateBccOfIdentity(EmailAddress(null, pattern)); + } }) ..addOnSuggestionCallbackAction((pattern) => controller.getSuggestionEmailAddress(pattern))) diff --git a/model/lib/identity/identity_request_dto.dart b/model/lib/identity/identity_request_dto.dart index 374cd6603..1e7d81bcd 100644 --- a/model/lib/identity/identity_request_dto.dart +++ b/model/lib/identity/identity_request_dto.dart @@ -13,19 +13,10 @@ part 'identity_request_dto.g.dart'; @JsonSerializable() class IdentityRequestDto with EquatableMixin { - @JsonKey(includeIfNull: false) final String? name; - - @JsonKey(includeIfNull: false) final Set? bcc; - - @JsonKey(includeIfNull: false) final Set? replyTo; - - @JsonKey(includeIfNull: false) final Signature? textSignature; - - @JsonKey(includeIfNull: false) final Signature? htmlSignature; IdentityRequestDto({