Reconnect when sending email with error 401

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-04-15 12:04:05 +07:00
committed by Dat H. Pham
parent 7678f100ae
commit 92a9fe88a5
2 changed files with 52 additions and 32 deletions
+4 -4
View File
@@ -175,7 +175,7 @@ abstract class BaseController extends GetxController
if (exception is ConnectionError) { if (exception is ConnectionError) {
_handleConnectionErrorException(); _handleConnectionErrorException();
} else if (exception is BadCredentialsException) { } else if (exception is BadCredentialsException) {
_handleBadCredentialsException(); handleBadCredentialsException();
} }
} }
@@ -186,7 +186,7 @@ abstract class BaseController extends GetxController
} else if (exception is ConnectionError) { } else if (exception is ConnectionError) {
_handleConnectionErrorException(); _handleConnectionErrorException();
} else if (exception is BadCredentialsException) { } else if (exception is BadCredentialsException) {
_handleBadCredentialsException(); handleBadCredentialsException();
} }
} }
@@ -219,8 +219,8 @@ abstract class BaseController extends GetxController
} }
} }
void _handleBadCredentialsException() { void handleBadCredentialsException() {
log('$runtimeType::_handleBadCredentialsException:'); log('$runtimeType::handleBadCredentialsException:');
if (twakeAppManager.hasComposer) { if (twakeAppManager.hasComposer) {
_performSaveAndReconnection(); _performSaveAndReconnection();
} else { } else {
@@ -106,6 +106,7 @@ import 'package:tmail_ui_user/features/upload/domain/state/local_image_picker_st
import 'package:tmail_ui_user/features/upload/domain/usecases/local_file_picker_interactor.dart'; import 'package:tmail_ui_user/features/upload/domain/usecases/local_file_picker_interactor.dart';
import 'package:tmail_ui_user/features/upload/domain/usecases/local_image_picker_interactor.dart'; import 'package:tmail_ui_user/features/upload/domain/usecases/local_image_picker_interactor.dart';
import 'package:tmail_ui_user/features/upload/presentation/controller/upload_controller.dart'; import 'package:tmail_ui_user/features/upload/presentation/controller/upload_controller.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/universal_import/html_stub.dart' as html; import 'package:tmail_ui_user/main/universal_import/html_stub.dart' as html;
@@ -880,14 +881,21 @@ class ComposerController extends BaseController
_closeComposerAction(result: resultState); _closeComposerAction(result: resultState);
} else if (resultState is SendEmailFailure && resultState.exception is SendingEmailCanceledException) { } else if (resultState is SendEmailFailure && resultState.exception is SendingEmailCanceledException) {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
} else if ((resultState is SendEmailFailure || resultState is GenerateEmailFailure) && context.mounted) { } else if (resultState is SendEmailFailure || resultState is GenerateEmailFailure) {
if (resultState.exception is BadCredentialsException) {
_sendButtonState = ButtonState.enabled;
handleBadCredentialsException();
} else if (context.mounted) {
await _showConfirmDialogWhenSendMessageFailure( await _showConfirmDialogWhenSendMessageFailure(
context: context, context: context,
failure: resultState failure: resultState,
); );
} else { } else {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
} }
} else {
_sendButtonState = ButtonState.enabled;
}
} }
Future<dynamic> _showSendingMessageDialog({ Future<dynamic> _showSendingMessageDialog({
@@ -1225,11 +1233,14 @@ class ComposerController extends BaseController
} else if ((resultState is SaveEmailAsDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException) || } else if ((resultState is SaveEmailAsDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException) ||
(resultState is UpdateEmailDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException)) { (resultState is UpdateEmailDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException)) {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
} else if ((resultState is SaveEmailAsDraftsFailure || } else if (resultState is SaveEmailAsDraftsFailure ||
resultState is UpdateEmailDraftsFailure || resultState is UpdateEmailDraftsFailure ||
resultState is GenerateEmailFailure) && resultState is GenerateEmailFailure
context.mounted
) { ) {
if (resultState.exception is BadCredentialsException) {
_saveToDraftButtonState = ButtonState.enabled;
handleBadCredentialsException();
} else if (context.mounted) {
await _showConfirmDialogWhenSaveMessageToDraftsFailure( await _showConfirmDialogWhenSaveMessageToDraftsFailure(
context: context, context: context,
failure: resultState, failure: resultState,
@@ -1241,11 +1252,14 @@ class ComposerController extends BaseController
onCancelAction: () { onCancelAction: () {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
_closeComposerAction(closeOverlays: true); _closeComposerAction(closeOverlays: true);
} },
); );
} else { } else {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
} }
} else {
_saveToDraftButtonState = ButtonState.enabled;
}
} }
void clearFocus(BuildContext context) { void clearFocus(BuildContext context) {
@@ -1933,18 +1947,24 @@ class ComposerController extends BaseController
} else if ((resultState is SaveEmailAsDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException) || } else if ((resultState is SaveEmailAsDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException) ||
(resultState is UpdateEmailDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException)) { (resultState is UpdateEmailDraftsFailure && resultState.exception is SavingEmailToDraftsCanceledException)) {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
} else if ((resultState is SaveEmailAsDraftsFailure || } else if (resultState is SaveEmailAsDraftsFailure ||
resultState is UpdateEmailDraftsFailure || resultState is UpdateEmailDraftsFailure ||
resultState is GenerateEmailFailure) && resultState is GenerateEmailFailure
context.mounted
) { ) {
if (resultState.exception is BadCredentialsException) {
_closeComposerButtonState = ButtonState.enabled;
handleBadCredentialsException();
} else if (context.mounted) {
await _showConfirmDialogWhenSaveMessageToDraftsFailure( await _showConfirmDialogWhenSaveMessageToDraftsFailure(
context: context, context: context,
failure: resultState failure: resultState,
); );
} else { } else {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
} }
} else {
_closeComposerButtonState = ButtonState.enabled;
}
} }
EmailId? getDraftEmailId() { EmailId? getDraftEmailId() {