[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:
Dat PHAM HOANG
2024-01-11 01:03:05 +07:00
committed by Dat H. Pham
parent 4952fbe840
commit 85ad953a15
2 changed files with 24 additions and 79 deletions
@@ -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';
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/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/worker_type.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}) {
super.handleExceptionAction(failure: failure, exception: exception);
if (failure is SendEmailFailure && exception is NoNetworkError) {
if (PlatformInfo.isIOS) {
if (currentContext != null) {
_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
);
}
}
log('MailboxDashBoardController::handleExceptionAction(): $failure');
_storeSendingEmailInCaseOfSendingFailureInMobile(failure);
}
}
@@ -1839,7 +1818,7 @@ class MailboxDashBoardController extends ReloadableController {
void _handleSendEmailFailure(SendEmailFailure failure) {
logError('MailboxDashBoardController::_handleSendEmailFailure():failure: $failure');
_updateSendingStateWhenSendEmailFailureOnIOS(failure);
_storeSendingEmailInCaseOfSendingFailureInMobile(failure);
if (currentContext == null) {
clearState();
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(
Session session,
AccountId accountId,
@@ -1995,12 +1985,9 @@ class MailboxDashBoardController extends ReloadableController {
}
void _handleStoreSendingEmailSuccess(StoreSendingEmailSuccess success) {
if (PlatformInfo.isAndroid) {
addSendingEmailToSendingQueue(success.sendingEmail);
}
getAllSendingEmails();
if (currentOverlayContext != null && currentContext != null) {
appToast.showToastSuccessMessage(
appToast.showToastWarningMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).messageHasBeenSavedToTheSendingQueue,
leadingSVGIconColor: Colors.white,
@@ -2009,11 +1996,14 @@ class MailboxDashBoardController extends ReloadableController {
}
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
if (PlatformInfo.isAndroid) {
await WorkManagerController().cancelByUniqueId(success.newSendingEmail.sendingId);
addSendingEmailToSendingQueue(success.newSendingEmail);
}
getAllSendingEmails();
if (currentOverlayContext != null && currentContext != null) {
appToast.showToastWarningMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).messageHasBeenSavedToTheSendingQueue,
leadingSVGIconColor: Colors.white,
leadingSVGIcon: imagePaths.icEmail);
}
}
void addSendingEmailToSendingQueue(SendingEmail sendingEmail) async {
@@ -2213,7 +2203,7 @@ class MailboxDashBoardController extends ReloadableController {
}
void _handleSendEmailSuccess(SendEmailSuccess success) {
if (PlatformInfo.isIOS &&
if (PlatformInfo.isMobile &&
success.emailRequest.storedSendingId != null &&
accountId.value != 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 {
_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/network_connection/presentation/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/sending_queue/domain/extensions/list_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 {
if (PlatformInfo.isAndroid) {
await Future.wait(success.sendingIds.map(WorkManagerController().cancelByUniqueId));
}
if (currentContext != null && currentOverlayContext != null) {
appToast.showToastSuccessMessage(
currentOverlayContext!,
@@ -277,7 +272,7 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
return;
}
if (PlatformInfo.isIOS && listSendingEmails.isNotEmpty) {
if (PlatformInfo.isMobile && listSendingEmails.isNotEmpty) {
final sendingEmailRunning = listSendingEmails.first.updatingSendingState(SendingState.running);
_updateSendingEmailAction(
newSendingEmail: sendingEmailRunning,
@@ -292,14 +287,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
_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 {
if (PlatformInfo.isAndroid) {
await Future.forEach<SendingEmail>(newListSendingEmails, (sendingEmail) async {
await WorkManagerController().cancelByUniqueId(sendingEmail.sendingId);
dashboardController.addSendingEmailToSendingQueue(sendingEmail);
});
}
if (currentContext != null && currentOverlayContext != null) {
appToast.showToastSuccessMessage(
currentOverlayContext!,
@@ -345,9 +325,6 @@ class SendingQueueController extends BaseController with MessageDialogActionMixi
}
void _handleUpdateSendingEmailSuccess(UpdateSendingEmailSuccess success) async {
if (PlatformInfo.isAndroid) {
await WorkManagerController().cancelByUniqueId(success.newSendingEmail.sendingId);
}
refreshSendingQueue();
}