TF-2026 Implement SaveToDraft method
(cherry picked from commit cf03def2f5de115fb9feb64af6686c3957b8f1f2)
This commit is contained in:
@@ -71,7 +71,7 @@ abstract class EmailDataSource {
|
||||
|
||||
Future<bool> removeEmailDrafts(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail);
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId);
|
||||
|
||||
Future<List<EmailId>> deleteMultipleEmailsPermanently(Session session, AccountId accountId, List<EmailId> emailIds);
|
||||
|
||||
|
||||
@@ -113,9 +113,9 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail) {
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.updateEmailDrafts(session, accountId, newEmail);
|
||||
return await emailAPI.updateEmailDrafts(session, accountId, newEmail, oldEmailId);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail) {
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -136,8 +136,8 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail) {
|
||||
return emailDataSource[DataSourceType.network]!.updateEmailDrafts(session, accountId, newEmail);
|
||||
Future<Email> updateEmailDrafts(Session session, AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
return emailDataSource[DataSourceType.network]!.updateEmailDrafts(session, accountId, newEmail, oldEmailId);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user