TF-1749 Handle delete old email after update draft email

(cherry picked from commit 1a1331a723e191e3cae8db138f2d0fec71b4c87a)
This commit is contained in:
dab246
2023-04-07 18:28:09 +07:00
committed by Dat Vu
parent 60b6a0022a
commit 89d7f605d2
7 changed files with 44 additions and 25 deletions
@@ -528,13 +528,11 @@ class EmailAPI with HandleSetErrorMixin {
Future<Email> updateEmailDrafts(
Session session,
AccountId accountId,
Email newEmail,
EmailId oldEmailId
Email newEmail
) async {
final idCreateMethod = Id(_uuid.v1());
final setEmailMethod = SetEmailMethod(accountId)
..addCreate(idCreateMethod, newEmail)
..addDestroy({oldEmailId.id});
..addCreate(idCreateMethod, newEmail);
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
@@ -554,11 +552,10 @@ class EmailAPI with HandleSetErrorMixin {
);
final emailUpdated = setEmailResponse?.created?[idCreateMethod];
final isEmailDestroyedSuccess = setEmailResponse?.destroyed?.contains(oldEmailId.id) ?? false;
final listEntriesErrors = _handleSetEmailResponse(response: setEmailResponse);
final mapErrors = Map.fromEntries(listEntriesErrors);
if (emailUpdated != null && isEmailDestroyedSuccess && mapErrors.isEmpty) {
if (emailUpdated != null && mapErrors.isEmpty) {
return emailUpdated;
} else {
throw SetEmailMethodException(mapErrors);