TF-1190 Handle SetError when update email as drafts
This commit is contained in:
@@ -25,14 +25,13 @@ class UpdateEmailDraftsInteractor {
|
||||
final currentEmailState = listState.last;
|
||||
|
||||
final newEmailDrafts = await _emailRepository.updateEmailDrafts(accountId, newEmail, oldEmailId);
|
||||
if (newEmailDrafts != null) {
|
||||
yield Right<Failure, Success>(UpdateEmailDraftsSuccess(
|
||||
newEmailDrafts,
|
||||
currentEmailState: currentEmailState,
|
||||
currentMailboxState: currentMailboxState));
|
||||
} else {
|
||||
yield Left<Failure, Success>(UpdateEmailDraftsFailure(null));
|
||||
}
|
||||
yield Right<Failure, Success>(
|
||||
UpdateEmailDraftsSuccess(
|
||||
newEmailDrafts,
|
||||
currentEmailState: currentEmailState,
|
||||
currentMailboxState: currentMailboxState
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(UpdateEmailDraftsFailure(e));
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ abstract class EmailDataSource {
|
||||
|
||||
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<Email?> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId);
|
||||
Future<Email> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId);
|
||||
|
||||
Future<List<EmailId>> deleteMultipleEmailsPermanently(AccountId accountId, List<EmailId> emailIds);
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
Future<Email> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.updateEmailDrafts(accountId, newEmail, oldEmailId);
|
||||
}).catchError((error) {
|
||||
|
||||
@@ -451,7 +451,7 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
);
|
||||
|
||||
final emailCreated = setEmailResponse?.created?[email.id.id];
|
||||
final listEntriesErrors = _handleSetEmailResponse(response: setEmailResponse,);
|
||||
final listEntriesErrors = _handleSetEmailResponse(response: setEmailResponse);
|
||||
final mapErrors = Map.fromEntries(listEntriesErrors);
|
||||
|
||||
if (emailCreated != null && mapErrors.isEmpty) {
|
||||
@@ -485,7 +485,7 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
});
|
||||
}
|
||||
|
||||
Future<Email?> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) async {
|
||||
Future<Email> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) async {
|
||||
final setEmailMethod = SetEmailMethod(accountId)
|
||||
..addCreate(newEmail.id.id, newEmail)
|
||||
..addDestroy({oldEmailId.id});
|
||||
@@ -500,19 +500,20 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
.execute();
|
||||
|
||||
final setEmailResponse = response.parse<SetEmailResponse>(
|
||||
setEmailInvocation.methodCallId,
|
||||
SetEmailResponse.deserialize);
|
||||
setEmailInvocation.methodCallId,
|
||||
SetEmailResponse.deserialize
|
||||
);
|
||||
|
||||
return Future.sync(() async {
|
||||
final emailUpdated = setEmailResponse?.created?[newEmail.id.id];
|
||||
final emailDestroyed = setEmailResponse?.destroyed?.contains(oldEmailId.id);
|
||||
if (emailUpdated != null && emailDestroyed == true) {
|
||||
return emailUpdated;
|
||||
}
|
||||
return null;
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
final emailUpdated = setEmailResponse?.created?[newEmail.id.id];
|
||||
final isEmailDestroyedSuccess = setEmailResponse?.destroyed?.contains(oldEmailId.id) ?? false;
|
||||
final listEntriesErrors = _handleSetEmailResponse(response: setEmailResponse);
|
||||
final mapErrors = Map.fromEntries(listEntriesErrors);
|
||||
|
||||
if (emailUpdated != null && isEmailDestroyedSuccess && mapErrors.isEmpty) {
|
||||
return emailUpdated;
|
||||
} else {
|
||||
throw SetEmailMethodException(mapErrors);
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<EmailId>> deleteMultipleEmailsPermanently(AccountId accountId, List<EmailId> emailIds) async {
|
||||
|
||||
@@ -114,7 +114,7 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Email?> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
Future<Email> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId) {
|
||||
return emailDataSource.updateEmailDrafts(accountId, newEmail, oldEmailId);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ abstract class EmailRepository {
|
||||
|
||||
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<Email?> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId);
|
||||
Future<Email> updateEmailDrafts(AccountId accountId, Email newEmail, EmailId oldEmailId);
|
||||
|
||||
Future<List<EmailId>> deleteMultipleEmailsPermanently(AccountId accountId, List<EmailId> emailIds);
|
||||
|
||||
|
||||
+24
-1
@@ -280,7 +280,9 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
_handleSendEmailFailure(failure);
|
||||
} else if (failure is SaveEmailAsDraftsFailure) {
|
||||
_handleSaveEmailAsDraftsFailure(failure);
|
||||
} else if (failure is RemoveEmailDraftsFailure || failure is UpdateEmailDraftsFailure) {
|
||||
} else if (failure is UpdateEmailDraftsFailure) {
|
||||
_handleUpdateEmailAsDraftsFailure(failure);
|
||||
} else if (failure is RemoveEmailDraftsFailure) {
|
||||
clearState();
|
||||
} else if (failure is MarkAsMailboxReadAllFailure ||
|
||||
failure is MarkAsMailboxReadFailure) {
|
||||
@@ -1610,6 +1612,27 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
|
||||
clearState();
|
||||
}
|
||||
|
||||
void _handleUpdateEmailAsDraftsFailure(UpdateEmailDraftsFailure failure) {
|
||||
logError('MailboxDashBoardController::_handleUpdateEmailAsDraftsFailure():failure: $failure');
|
||||
if (currentContext == null) {
|
||||
clearState();
|
||||
return;
|
||||
}
|
||||
final exception = failure.exception;
|
||||
logError('MailboxDashBoardController::_handleUpdateEmailAsDraftsFailure():exception: $exception');
|
||||
if (exception is SetEmailMethodException) {
|
||||
final listErrors = exception.mapErrors.values.toList();
|
||||
final toastSuccess = _handleSetErrors(listErrors);
|
||||
if (!toastSuccess) {
|
||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).saveEmailAsDraftFailure);
|
||||
}
|
||||
} else {
|
||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).saveEmailAsDraftFailure);
|
||||
}
|
||||
|
||||
clearState();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
|
||||
Reference in New Issue
Block a user