TF-1190 Handle SetError when save email as drafts
This commit is contained in:
@@ -25,14 +25,13 @@ class SaveEmailAsDraftsInteractor {
|
|||||||
final currentEmailState = listState.last;
|
final currentEmailState = listState.last;
|
||||||
|
|
||||||
final emailAsDrafts = await _emailRepository.saveEmailAsDrafts(accountId, email);
|
final emailAsDrafts = await _emailRepository.saveEmailAsDrafts(accountId, email);
|
||||||
if (emailAsDrafts != null) {
|
yield Right<Failure, Success>(
|
||||||
yield Right<Failure, Success>(SaveEmailAsDraftsSuccess(
|
SaveEmailAsDraftsSuccess(
|
||||||
emailAsDrafts,
|
emailAsDrafts,
|
||||||
currentEmailState: currentEmailState,
|
currentEmailState: currentEmailState,
|
||||||
currentMailboxState: currentMailboxState));
|
currentMailboxState: currentMailboxState
|
||||||
} else {
|
)
|
||||||
yield Left<Failure, Success>(SaveEmailAsDraftsFailure(null));
|
);
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield Left<Failure, Success>(SaveEmailAsDraftsFailure(e));
|
yield Left<Failure, Success>(SaveEmailAsDraftsFailure(e));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ abstract class EmailDataSource {
|
|||||||
MarkStarAction markStarAction
|
MarkStarAction markStarAction
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<Email?> saveEmailAsDrafts(AccountId accountId, Email email);
|
Future<Email> saveEmailAsDrafts(AccountId accountId, Email email);
|
||||||
|
|
||||||
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
||||||
|
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class EmailDataSourceImpl extends EmailDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Email?> saveEmailAsDrafts(AccountId accountId, Email email) {
|
Future<Email> saveEmailAsDrafts(AccountId accountId, Email email) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
return await emailAPI.saveEmailAsDrafts(accountId, email);
|
return await emailAPI.saveEmailAsDrafts(accountId, email);
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
|
|||||||
@@ -432,7 +432,7 @@ class EmailAPI with HandleSetErrorMixin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Email?> saveEmailAsDrafts(AccountId accountId, Email email) async {
|
Future<Email> saveEmailAsDrafts(AccountId accountId, Email email) async {
|
||||||
final setEmailMethod = SetEmailMethod(accountId)
|
final setEmailMethod = SetEmailMethod(accountId)
|
||||||
..addCreate(email.id.id, email);
|
..addCreate(email.id.id, email);
|
||||||
|
|
||||||
@@ -446,14 +446,19 @@ 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 emailCreated = setEmailResponse?.created?[email.id.id];
|
||||||
return setEmailResponse?.created?[email.id.id];
|
final listEntriesErrors = _handleSetEmailResponse(response: setEmailResponse,);
|
||||||
}).catchError((error) {
|
final mapErrors = Map.fromEntries(listEntriesErrors);
|
||||||
throw error;
|
|
||||||
});
|
if (emailCreated != null && mapErrors.isEmpty) {
|
||||||
|
return emailCreated;
|
||||||
|
} else {
|
||||||
|
throw SetEmailMethodException(mapErrors);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId) async {
|
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId) async {
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class EmailRepositoryImpl extends EmailRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Email?> saveEmailAsDrafts(AccountId accountId, Email email) {
|
Future<Email> saveEmailAsDrafts(AccountId accountId, Email email) {
|
||||||
return emailDataSource.saveEmailAsDrafts(accountId, email);
|
return emailDataSource.saveEmailAsDrafts(accountId, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ abstract class EmailRepository {
|
|||||||
|
|
||||||
Future<List<EmailContent>> addTooltipWhenHoverOnLink(List<EmailContent> emailContents);
|
Future<List<EmailContent>> addTooltipWhenHoverOnLink(List<EmailContent> emailContents);
|
||||||
|
|
||||||
Future<Email?> saveEmailAsDrafts(AccountId accountId, Email email);
|
Future<Email> saveEmailAsDrafts(AccountId accountId, Email email);
|
||||||
|
|
||||||
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
Future<bool> removeEmailDrafts(AccountId accountId, EmailId emailId);
|
||||||
|
|
||||||
|
|||||||
+34
-11
@@ -61,6 +61,7 @@ import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller
|
|||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/download/download_controller.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/download/download_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/search_controller.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/search_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/spam_report_controller.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/set_error_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
||||||
@@ -277,9 +278,9 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
(failure) {
|
(failure) {
|
||||||
if (failure is SendEmailFailure) {
|
if (failure is SendEmailFailure) {
|
||||||
_handleSendEmailFailure(failure);
|
_handleSendEmailFailure(failure);
|
||||||
} else if (failure is SaveEmailAsDraftsFailure
|
} else if (failure is SaveEmailAsDraftsFailure) {
|
||||||
|| failure is RemoveEmailDraftsFailure
|
_handleSaveEmailAsDraftsFailure(failure);
|
||||||
|| failure is UpdateEmailDraftsFailure) {
|
} else if (failure is RemoveEmailDraftsFailure || failure is UpdateEmailDraftsFailure) {
|
||||||
clearState();
|
clearState();
|
||||||
} else if (failure is MarkAsMailboxReadAllFailure ||
|
} else if (failure is MarkAsMailboxReadAllFailure ||
|
||||||
failure is MarkAsMailboxReadFailure) {
|
failure is MarkAsMailboxReadFailure) {
|
||||||
@@ -1555,22 +1556,23 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
final listErrors = exception.mapErrors.values.toList();
|
final listErrors = exception.mapErrors.values.toList();
|
||||||
final toastSuccess = _handleSetErrors(listErrors);
|
final toastSuccess = _handleSetErrors(listErrors);
|
||||||
if (!toastSuccess) {
|
if (!toastSuccess) {
|
||||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).message_has_been_sent_failure);
|
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).sendMessageFailure);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).message_has_been_sent_failure);
|
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).sendMessageFailure);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearState();
|
clearState();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _handleSetErrors(List<SetError> listErrors) {
|
bool _handleSetErrors(List<SetError> listErrors, {bool isDrafts = false}) {
|
||||||
for (var error in listErrors) {
|
for (var error in listErrors) {
|
||||||
if (error.type == SetError.tooLarge) {
|
if (error.type == SetError.tooLarge || error.type == SetError.overQuota) {
|
||||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).sendMessageFailureWithSetErrorTypeTooLarge);
|
if (isDrafts) {
|
||||||
return true;
|
_showToastSendMessageFailure(error.toastMessageForSaveEmailAsDraftFailure(currentContext!));
|
||||||
} else if (error.type == SetError.overQuota) {
|
} else {
|
||||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).sendMessageFailureWithSetErrorTypeOverQuota);
|
_showToastSendMessageFailure(error.toastMessageForSendEmailFailure(currentContext!));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1588,6 +1590,27 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _handleSaveEmailAsDraftsFailure(SaveEmailAsDraftsFailure failure) {
|
||||||
|
logError('MailboxDashBoardController::_handleSaveEmailAsDraftsFailure():failure: $failure');
|
||||||
|
if (currentContext == null) {
|
||||||
|
clearState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final exception = failure.exception;
|
||||||
|
logError('MailboxDashBoardController::_handleSaveEmailAsDraftsFailure():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() {
|
||||||
_emailReceiveManager.closeEmailReceiveManagerStream();
|
_emailReceiveManager.closeEmailReceiveManagerStream();
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
|
||||||
|
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||||
|
|
||||||
|
extension SetErrorExtension on SetError {
|
||||||
|
|
||||||
|
String toastMessageForSendEmailFailure(BuildContext context) {
|
||||||
|
if (type == SetError.tooLarge) {
|
||||||
|
return AppLocalizations.of(context).sendMessageFailureWithSetErrorTypeTooLarge;
|
||||||
|
} else if (type == SetError.overQuota) {
|
||||||
|
return AppLocalizations.of(context).sendMessageFailureWithSetErrorTypeOverQuota;
|
||||||
|
} else {
|
||||||
|
return AppLocalizations.of(context).sendMessageFailure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String toastMessageForSaveEmailAsDraftFailure(BuildContext context) {
|
||||||
|
if (type == SetError.tooLarge) {
|
||||||
|
return AppLocalizations.of(context).saveEmailAsDraftFailureWithSetErrorTypeTooLarge;
|
||||||
|
} else if (type == SetError.overQuota) {
|
||||||
|
return AppLocalizations.of(context).saveEmailAsDraftFailureWithSetErrorTypeOverQuota;
|
||||||
|
} else {
|
||||||
|
return AppLocalizations.of(context).saveEmailAsDraftFailure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"@@last_modified": "2023-02-02T19:29:42.134695",
|
"@@last_modified": "2023-02-03T11:24:09.273116",
|
||||||
"initializing_data": "Initializing data...",
|
"initializing_data": "Initializing data...",
|
||||||
"@initializing_data": {
|
"@initializing_data": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -588,12 +588,6 @@
|
|||||||
"placeholders_order": [],
|
"placeholders_order": [],
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
"message_has_been_sent_failure": "Message has been sent failure",
|
|
||||||
"@message_has_been_sent_failure": {
|
|
||||||
"type": "text",
|
|
||||||
"placeholders_order": [],
|
|
||||||
"placeholders": {}
|
|
||||||
},
|
|
||||||
"done": "Done",
|
"done": "Done",
|
||||||
"@done": {
|
"@done": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -2650,6 +2644,12 @@
|
|||||||
"placeholders_order": [],
|
"placeholders_order": [],
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
},
|
},
|
||||||
|
"sendMessageFailure": "Failure to send your message.",
|
||||||
|
"@sendMessageFailure": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
"sendMessageFailureWithSetErrorTypeTooLarge": "Failure to send your message, because it is too large.",
|
"sendMessageFailureWithSetErrorTypeTooLarge": "Failure to send your message, because it is too large.",
|
||||||
"@sendMessageFailureWithSetErrorTypeTooLarge": {
|
"@sendMessageFailureWithSetErrorTypeTooLarge": {
|
||||||
"type": "text",
|
"type": "text",
|
||||||
@@ -2661,5 +2661,23 @@
|
|||||||
"type": "text",
|
"type": "text",
|
||||||
"placeholders_order": [],
|
"placeholders_order": [],
|
||||||
"placeholders": {}
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"saveEmailAsDraftFailure": "Failure to save your message as drafts.",
|
||||||
|
"@saveEmailAsDraftFailure": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"saveEmailAsDraftFailureWithSetErrorTypeTooLarge": "Failure to save your message as drafts, because it is too large.",
|
||||||
|
"@saveEmailAsDraftFailureWithSetErrorTypeTooLarge": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
|
},
|
||||||
|
"saveEmailAsDraftFailureWithSetErrorTypeOverQuota": "Failure to save your message as drafts, because it is over quota.",
|
||||||
|
"@saveEmailAsDraftFailureWithSetErrorTypeOverQuota": {
|
||||||
|
"type": "text",
|
||||||
|
"placeholders_order": [],
|
||||||
|
"placeholders": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -602,13 +602,6 @@ class AppLocalizations {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String get message_has_been_sent_failure {
|
|
||||||
return Intl.message(
|
|
||||||
'Message has been sent failure',
|
|
||||||
name: 'message_has_been_sent_failure',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
String get done {
|
String get done {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'Done',
|
'Done',
|
||||||
@@ -2720,6 +2713,13 @@ class AppLocalizations {
|
|||||||
name: 'reduceSomeFiltersAndTryAgain');
|
name: 'reduceSomeFiltersAndTryAgain');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get sendMessageFailure {
|
||||||
|
return Intl.message(
|
||||||
|
'Failure to send your message.',
|
||||||
|
name: 'sendMessageFailure',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String get sendMessageFailureWithSetErrorTypeTooLarge {
|
String get sendMessageFailureWithSetErrorTypeTooLarge {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'Failure to send your message, because it is too large.',
|
'Failure to send your message, because it is too large.',
|
||||||
@@ -2733,4 +2733,25 @@ class AppLocalizations {
|
|||||||
name: 'sendMessageFailureWithSetErrorTypeOverQuota',
|
name: 'sendMessageFailureWithSetErrorTypeOverQuota',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String get saveEmailAsDraftFailure {
|
||||||
|
return Intl.message(
|
||||||
|
'Failure to save your message as drafts.',
|
||||||
|
name: 'saveEmailAsDraftFailure',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get saveEmailAsDraftFailureWithSetErrorTypeTooLarge {
|
||||||
|
return Intl.message(
|
||||||
|
'Failure to save your message as drafts, because it is too large.',
|
||||||
|
name: 'saveEmailAsDraftFailureWithSetErrorTypeTooLarge',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get saveEmailAsDraftFailureWithSetErrorTypeOverQuota {
|
||||||
|
return Intl.message(
|
||||||
|
'Failure to save your message as drafts, because it is over quota.',
|
||||||
|
name: 'saveEmailAsDraftFailureWithSetErrorTypeOverQuota',
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user