[Android][Disable work manager] Handle the logic of sending mail
- Send mail anyway - If sending failed with no connection, email will be stored in cache - No more automatically resend - Resent, Edit, Delete manually (cherry picked from commit 8c7e8c28fb20f053c9aae4069f1236baff4d6ef8)
This commit is contained in:
committed by
Dat H. Pham
parent
4952fbe840
commit
85ad953a15
+23
-55
@@ -111,7 +111,6 @@ import 'package:tmail_ui_user/features/network_connection/presentation/network_c
|
|||||||
if (dart.library.html) 'package:tmail_ui_user/features/network_connection/presentation/web_network_connection_controller.dart';
|
if (dart.library.html) 'package:tmail_ui_user/features/network_connection/presentation/web_network_connection_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_constants.dart';
|
import 'package:tmail_ui_user/features/offline_mode/config/work_manager_constants.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
|
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/one_time_work_request.dart';
|
import 'package:tmail_ui_user/features/offline_mode/work_manager/one_time_work_request.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker_type.dart';
|
import 'package:tmail_ui_user/features/offline_mode/work_manager/worker_type.dart';
|
||||||
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
|
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
|
||||||
@@ -403,28 +402,8 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
void handleExceptionAction({Failure? failure, Exception? exception}) {
|
void handleExceptionAction({Failure? failure, Exception? exception}) {
|
||||||
super.handleExceptionAction(failure: failure, exception: exception);
|
super.handleExceptionAction(failure: failure, exception: exception);
|
||||||
if (failure is SendEmailFailure && exception is NoNetworkError) {
|
if (failure is SendEmailFailure && exception is NoNetworkError) {
|
||||||
if (PlatformInfo.isIOS) {
|
log('MailboxDashBoardController::handleExceptionAction(): $failure');
|
||||||
if (currentContext != null) {
|
_storeSendingEmailInCaseOfSendingFailureInMobile(failure);
|
||||||
_showToastSendMessageFailure(AppLocalizations.of(currentContext!).sendMessageFailure);
|
|
||||||
}
|
|
||||||
_updateSendingStateWhenSendEmailFailureOnIOS(failure);
|
|
||||||
} else if (PlatformInfo.isAndroid) {
|
|
||||||
if (failure.emailRequest.storedSendingId != null) {
|
|
||||||
_handleStoreSendingEmail(
|
|
||||||
failure.session,
|
|
||||||
failure.accountId,
|
|
||||||
failure.emailRequest,
|
|
||||||
failure.mailboxRequest
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
_handleUpdateSendingEmail(
|
|
||||||
failure.session,
|
|
||||||
failure.accountId,
|
|
||||||
failure.emailRequest,
|
|
||||||
failure.mailboxRequest
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1839,7 +1818,7 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
|
|
||||||
void _handleSendEmailFailure(SendEmailFailure failure) {
|
void _handleSendEmailFailure(SendEmailFailure failure) {
|
||||||
logError('MailboxDashBoardController::_handleSendEmailFailure():failure: $failure');
|
logError('MailboxDashBoardController::_handleSendEmailFailure():failure: $failure');
|
||||||
_updateSendingStateWhenSendEmailFailureOnIOS(failure);
|
_storeSendingEmailInCaseOfSendingFailureInMobile(failure);
|
||||||
if (currentContext == null) {
|
if (currentContext == null) {
|
||||||
clearState();
|
clearState();
|
||||||
return;
|
return;
|
||||||
@@ -1968,6 +1947,17 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _storeSendingEmailInCaseOfSendingFailureInMobile(SendEmailFailure failure) {
|
||||||
|
if (PlatformInfo.isMobile) {
|
||||||
|
_handleUpdateSendingEmail(
|
||||||
|
failure.session,
|
||||||
|
failure.accountId,
|
||||||
|
failure.emailRequest,
|
||||||
|
failure.mailboxRequest
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _handleUpdateSendingEmail(
|
void _handleUpdateSendingEmail(
|
||||||
Session session,
|
Session session,
|
||||||
AccountId accountId,
|
AccountId accountId,
|
||||||
@@ -1995,12 +1985,9 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleStoreSendingEmailSuccess(StoreSendingEmailSuccess success) {
|
void _handleStoreSendingEmailSuccess(StoreSendingEmailSuccess success) {
|
||||||
if (PlatformInfo.isAndroid) {
|
|
||||||
addSendingEmailToSendingQueue(success.sendingEmail);
|
|
||||||
}
|
|
||||||
getAllSendingEmails();
|
getAllSendingEmails();
|
||||||
if (currentOverlayContext != null && currentContext != null) {
|
if (currentOverlayContext != null && currentContext != null) {
|
||||||
appToast.showToastSuccessMessage(
|
appToast.showToastWarningMessage(
|
||||||
currentOverlayContext!,
|
currentOverlayContext!,
|
||||||
AppLocalizations.of(currentContext!).messageHasBeenSavedToTheSendingQueue,
|
AppLocalizations.of(currentContext!).messageHasBeenSavedToTheSendingQueue,
|
||||||
leadingSVGIconColor: Colors.white,
|
leadingSVGIconColor: Colors.white,
|
||||||
@@ -2009,11 +1996,14 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
|
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
|
||||||
if (PlatformInfo.isAndroid) {
|
|
||||||
await WorkManagerController().cancelByUniqueId(success.newSendingEmail.sendingId);
|
|
||||||
addSendingEmailToSendingQueue(success.newSendingEmail);
|
|
||||||
}
|
|
||||||
getAllSendingEmails();
|
getAllSendingEmails();
|
||||||
|
if (currentOverlayContext != null && currentContext != null) {
|
||||||
|
appToast.showToastWarningMessage(
|
||||||
|
currentOverlayContext!,
|
||||||
|
AppLocalizations.of(currentContext!).messageHasBeenSavedToTheSendingQueue,
|
||||||
|
leadingSVGIconColor: Colors.white,
|
||||||
|
leadingSVGIcon: imagePaths.icEmail);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addSendingEmailToSendingQueue(SendingEmail sendingEmail) async {
|
void addSendingEmailToSendingQueue(SendingEmail sendingEmail) async {
|
||||||
@@ -2213,7 +2203,7 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleSendEmailSuccess(SendEmailSuccess success) {
|
void _handleSendEmailSuccess(SendEmailSuccess success) {
|
||||||
if (PlatformInfo.isIOS &&
|
if (PlatformInfo.isMobile &&
|
||||||
success.emailRequest.storedSendingId != null &&
|
success.emailRequest.storedSendingId != null &&
|
||||||
accountId.value != null &&
|
accountId.value != null &&
|
||||||
sessionCurrent != null
|
sessionCurrent != null
|
||||||
@@ -2238,28 +2228,6 @@ class MailboxDashBoardController extends ReloadableController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _updateSendingStateWhenSendEmailFailureOnIOS(SendEmailFailure failure) {
|
|
||||||
log('MailboxDashBoardController::_updateSendingStateWhenSendEmailFailureOnIOS:');
|
|
||||||
if (PlatformInfo.isIOS &&
|
|
||||||
failure.emailRequest.storedSendingId != null &&
|
|
||||||
accountId.value != null &&
|
|
||||||
sessionCurrent != null
|
|
||||||
) {
|
|
||||||
final sendingEmailError = failure.emailRequest.toSendingEmail(
|
|
||||||
failure.emailRequest.storedSendingId!,
|
|
||||||
mailboxRequest: failure.mailboxRequest,
|
|
||||||
newState: SendingState.error
|
|
||||||
);
|
|
||||||
consumeState(
|
|
||||||
_updateSendingEmailInteractor.execute(
|
|
||||||
accountId.value!,
|
|
||||||
sessionCurrent!.username,
|
|
||||||
sendingEmailError
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<EmailAddress>> getContactSuggestion(String query) async {
|
Future<List<EmailAddress>> getContactSuggestion(String query) async {
|
||||||
_getAutoCompleteInteractor = getBinding<GetAutoCompleteInteractor>();
|
_getAutoCompleteInteractor = getBinding<GetAutoCompleteInteractor>();
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_r
|
|||||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_controller.dart'
|
import 'package:tmail_ui_user/features/network_connection/presentation/network_connection_controller.dart'
|
||||||
if (dart.library.html) 'package:tmail_ui_user/features/network_connection/presentation/web_network_connection_controller.dart';
|
if (dart.library.html) 'package:tmail_ui_user/features/network_connection/presentation/web_network_connection_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/offline_mode/controller/work_manager_controller.dart';
|
|
||||||
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
import 'package:tmail_ui_user/features/offline_mode/model/sending_state.dart';
|
||||||
import 'package:tmail_ui_user/features/sending_queue/domain/extensions/list_sending_email_extension.dart';
|
import 'package:tmail_ui_user/features/sending_queue/domain/extensions/list_sending_email_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/sending_queue/domain/extensions/sending_email_extension.dart';
|
import 'package:tmail_ui_user/features/sending_queue/domain/extensions/sending_email_extension.dart';
|
||||||
@@ -250,10 +249,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleDeleteListSendingEmailSuccess(DeleteMultipleSendingEmailSuccess success) async {
|
void _handleDeleteListSendingEmailSuccess(DeleteMultipleSendingEmailSuccess success) async {
|
||||||
if (PlatformInfo.isAndroid) {
|
|
||||||
await Future.wait(success.sendingIds.map(WorkManagerController().cancelByUniqueId));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentContext != null && currentOverlayContext != null) {
|
if (currentContext != null && currentOverlayContext != null) {
|
||||||
appToast.showToastSuccessMessage(
|
appToast.showToastSuccessMessage(
|
||||||
currentOverlayContext!,
|
currentOverlayContext!,
|
||||||
@@ -277,7 +272,7 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PlatformInfo.isIOS && listSendingEmails.isNotEmpty) {
|
if (PlatformInfo.isMobile && listSendingEmails.isNotEmpty) {
|
||||||
final sendingEmailRunning = listSendingEmails.first.updatingSendingState(SendingState.running);
|
final sendingEmailRunning = listSendingEmails.first.updatingSendingState(SendingState.running);
|
||||||
_updateSendingEmailAction(
|
_updateSendingEmailAction(
|
||||||
newSendingEmail: sendingEmailRunning,
|
newSendingEmail: sendingEmailRunning,
|
||||||
@@ -292,14 +287,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
|
|||||||
_getMailboxRequest(sendingEmailRunning),
|
_getMailboxRequest(sendingEmailRunning),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
consumeState(
|
|
||||||
_updateMultipleSendingEmailInteractor.execute(
|
|
||||||
accountId,
|
|
||||||
session.username,
|
|
||||||
listSendingEmails.toSendingStateWaiting()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,13 +304,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleResendSendingEmailSuccess(List<SendingEmail> newListSendingEmails) async {
|
void _handleResendSendingEmailSuccess(List<SendingEmail> newListSendingEmails) async {
|
||||||
if (PlatformInfo.isAndroid) {
|
|
||||||
await Future.forEach<SendingEmail>(newListSendingEmails, (sendingEmail) async {
|
|
||||||
await WorkManagerController().cancelByUniqueId(sendingEmail.sendingId);
|
|
||||||
dashboardController.addSendingEmailToSendingQueue(sendingEmail);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentContext != null && currentOverlayContext != null) {
|
if (currentContext != null && currentOverlayContext != null) {
|
||||||
appToast.showToastSuccessMessage(
|
appToast.showToastSuccessMessage(
|
||||||
currentOverlayContext!,
|
currentOverlayContext!,
|
||||||
@@ -345,9 +325,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
|
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
|
||||||
if (PlatformInfo.isAndroid) {
|
|
||||||
await WorkManagerController().cancelByUniqueId(success.newSendingEmail.sendingId);
|
|
||||||
}
|
|
||||||
refreshSendingQueue();
|
refreshSendingQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user