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,11 +881,18 @@ 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) {
await _showConfirmDialogWhenSendMessageFailure( if (resultState.exception is BadCredentialsException) {
context: context, _sendButtonState = ButtonState.enabled;
failure: resultState handleBadCredentialsException();
); } else if (context.mounted) {
await _showConfirmDialogWhenSendMessageFailure(
context: context,
failure: resultState,
);
} else {
_sendButtonState = ButtonState.enabled;
}
} else { } else {
_sendButtonState = ButtonState.enabled; _sendButtonState = ButtonState.enabled;
} }
@@ -1225,24 +1233,30 @@ 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
) { ) {
await _showConfirmDialogWhenSaveMessageToDraftsFailure( if (resultState.exception is BadCredentialsException) {
context: context, _saveToDraftButtonState = ButtonState.enabled;
failure: resultState, handleBadCredentialsException();
onConfirmAction: () { } else if (context.mounted) {
_saveToDraftButtonState = ButtonState.enabled; await _showConfirmDialogWhenSaveMessageToDraftsFailure(
popBack(); context: context,
_autoFocusFieldWhenLauncher(); failure: resultState,
}, onConfirmAction: () {
onCancelAction: () { _saveToDraftButtonState = ButtonState.enabled;
_saveToDraftButtonState = ButtonState.enabled; popBack();
_closeComposerAction(closeOverlays: true); _autoFocusFieldWhenLauncher();
} },
); onCancelAction: () {
_saveToDraftButtonState = ButtonState.enabled;
_closeComposerAction(closeOverlays: true);
},
);
} else {
_saveToDraftButtonState = ButtonState.enabled;
}
} else { } else {
_saveToDraftButtonState = ButtonState.enabled; _saveToDraftButtonState = ButtonState.enabled;
} }
@@ -1933,15 +1947,21 @@ 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
) { ) {
await _showConfirmDialogWhenSaveMessageToDraftsFailure( if (resultState.exception is BadCredentialsException) {
context: context, _closeComposerButtonState = ButtonState.enabled;
failure: resultState handleBadCredentialsException();
); } else if (context.mounted) {
await _showConfirmDialogWhenSaveMessageToDraftsFailure(
context: context,
failure: resultState,
);
} else {
_closeComposerButtonState = ButtonState.enabled;
}
} else { } else {
_closeComposerButtonState = ButtonState.enabled; _closeComposerButtonState = ButtonState.enabled;
} }