TF-2026 Implement SaveToDraft method

(cherry picked from commit cf03def2f5de115fb9feb64af6686c3957b8f1f2)
This commit is contained in:
dab246
2023-08-31 00:11:42 +07:00
committed by Dat Vu
parent 5f0b27e742
commit 8f7a1aeb10
11 changed files with 144 additions and 33 deletions
@@ -541,11 +541,13 @@ class EmailAPI with HandleSetErrorMixin {
Future<Email> updateEmailDrafts(
Session session,
AccountId accountId,
Email newEmail
Email newEmail,
EmailId oldEmailId
) async {
final idCreateMethod = Id(_uuid.v1());
final setEmailMethod = SetEmailMethod(accountId)
..addCreate(idCreateMethod, newEmail);
..addCreate(idCreateMethod, newEmail)
..addDestroy({oldEmailId.id});
final requestBuilder = JmapRequestBuilder(_httpClient, ProcessingInvocation());
@@ -565,10 +567,11 @@ class EmailAPI with HandleSetErrorMixin {
);
final emailUpdated = setEmailResponse?.created?[idCreateMethod];
final isEmailDeleted = setEmailResponse?.destroyed?.contains(oldEmailId.id);
final listEntriesErrors = _handleSetEmailResponse([setEmailResponse]);
final mapErrors = Map.fromEntries(listEntriesErrors);
if (emailUpdated != null && mapErrors.isEmpty) {
if (emailUpdated != null && isEmailDeleted == true && mapErrors.isEmpty) {
return emailUpdated;
} else {
throw SetEmailMethodException(mapErrors);