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