Skip to content

Commit

Permalink
TF-3290 Only show reconnection confirm dialog when composer is opened
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Dec 12, 2024
1 parent 7a6a02f commit ba1e41a
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 54 deletions.
76 changes: 42 additions & 34 deletions lib/features/base/base_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';
import 'package:tmail_ui_user/main/universal_import/html_stub.dart' as html;
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

abstract class BaseController extends GetxController
Expand All @@ -81,6 +82,7 @@ abstract class BaseController extends GetxController
final Uuid uuid = Get.find<Uuid>();
final ApplicationManager applicationManager = Get.find<ApplicationManager>();
final ToastManager toastManager = Get.find<ToastManager>();
final TwakeAppManager twakeAppManager = Get.find<TwakeAppManager>();

bool _isFcmEnabled = false;

Expand Down Expand Up @@ -231,45 +233,51 @@ abstract class BaseController extends GetxController
}

void _handleBadCredentialsException() {
if (PlatformInfo.isWeb) {
if (currentContext == null) {
_executeBeforeReconnectAndLogOut();
return;
}
log('$runtimeType::_handleBadCredentialsException:');
if (!twakeAppManager.isComposerOpened) {
_performReconnection();
return;
}

showConfirmDialogAction(
currentContext!,
AppLocalizations.of(currentContext!).dialogMessageSessionHasExpired,
AppLocalizations.of(currentContext!).reconnect,
title: AppLocalizations.of(currentContext!).sessionExpired,
alignCenter: true,
outsideDismissible: false,
titleActionButtonMaxLines: 1,
icon: SvgPicture.asset(imagePaths.icTMailLogo, width: 64, height: 64),
onConfirmAction: _executeBeforeReconnectAndLogOut,
onCancelAction: onCancelReconnectWhenSessionExpired
);
} else if (PlatformInfo.isMobile) {
if (currentContext == null) {
clearDataAndGoToLoginPage();
return;
}
if (currentContext == null) {
_performSaveAndReconnection();
return;
}

showConfirmDialogAction(
currentContext!,
AppLocalizations.of(currentContext!).dialogMessageSessionHasExpired,
AppLocalizations.of(currentContext!).reconnect,
title: AppLocalizations.of(currentContext!).sessionExpired,
alignCenter: true,
outsideDismissible: false,
titleActionButtonMaxLines: 1,
icon: SvgPicture.asset(imagePaths.icTMailLogo, width: 64, height: 64),
onConfirmAction: clearDataAndGoToLoginPage,
onCancelAction: onCancelReconnectWhenSessionExpired
);
final appLocalizations = AppLocalizations.of(currentContext!);
showConfirmDialogAction(
currentContext!,
appLocalizations.messageWarningDialogWhenExpiredOIDCTokenAndReconnection,
appLocalizations.saveAndRefresh,
title: appLocalizations.sessionExpired,
cancelTitle: appLocalizations.no,
alignCenter: true,
outsideDismissible: false,
titleActionButtonMaxLines: 1,
marginIcon: EdgeInsetsDirectional.zero,
icon: SvgPicture.asset(imagePaths.icTMailLogo, width: 64, height: 64),
onConfirmAction: _performSaveAndReconnection,
onCancelAction: _performReconnection,
onCloseButtonAction: _performCloseReconnectionConfirmDialog
);
}

void _performSaveAndReconnection() {
if (PlatformInfo.isWeb) {
_executeBeforeReconnectAndLogOut();
} else if (PlatformInfo.isMobile) {
clearDataAndGoToLoginPage();
}
}

void _performReconnection() {
clearDataAndGoToLoginPage();
}

void _performCloseReconnectionConfirmDialog() {
popBack();
}

void handleFailureViewState(Failure failure) async {
logError('$runtimeType::handleFailureViewState():Failure = $failure');
if (failure is LogoutOidcFailure) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ class MailboxDashBoardController extends ReloadableController
} else if (success is GetAllIdentitiesSuccess) {
_handleGetAllIdentitiesSuccess(success);
} else if (success is GetComposerCacheSuccess) {
_removeComposerCacheOnWeb();
goToComposer(ComposerArguments.fromSessionStorageBrowser(success.composerCache));
} else if (success is GetIdentityCacheOnWebSuccess) {
goToSettings();
Expand Down Expand Up @@ -1523,12 +1524,14 @@ class MailboxDashBoardController extends ReloadableController
composerArguments = arguments;
ComposerBindings().dependencies();
composerOverlayState.value = ComposerOverlayState.active;
twakeAppManager.openComposerOnWeb();
}

void closeComposerOverlay({dynamic result}) async {
composerArguments = null;
ComposerBindings().dispose();
composerOverlayState.value = ComposerOverlayState.inActive;
twakeAppManager.closeComposerOnWeb();
if (result is SendingEmailArguments) {
handleSendEmailAction(result);
} else if (result is SendEmailSuccess ||
Expand Down Expand Up @@ -3035,6 +3038,7 @@ class MailboxDashBoardController extends ReloadableController
sessionCurrent = null;
mapMailboxById = {};
mapDefaultMailboxIdByRole = {};
twakeAppManager.closeComposerOnWeb();
super.onClose();
}
}
26 changes: 13 additions & 13 deletions lib/l10n/intl_messages.arb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"@@last_modified": "2024-12-09T13:59:58.460897",
"@@last_modified": "2024-12-12T15:50:46.911821",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
Expand Down Expand Up @@ -2930,12 +2930,6 @@
"placeholders_order": [],
"placeholders": {}
},
"errorWhileFetchingSubaddress": "Error while fetching the subaddress",
"@errorWhileFetchingSubaddress": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"connectedToTheInternet": "Connected to the internet",
"@connectedToTheInternet": {
"type": "text",
Expand Down Expand Up @@ -4038,12 +4032,6 @@
"placeholders_order": [],
"placeholders": {}
},
"dialogMessageSessionHasExpired": "The current session has expired. Please reconnect to the server",
"@dialogMessageSessionHasExpired": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"sMimeGoodSignatureMessage": "The authenticity of this message had been verified with SMime signature.",
"@sMimeGoodSignatureMessage": {
"type": "text",
Expand Down Expand Up @@ -4205,5 +4193,17 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"messageWarningDialogWhenExpiredOIDCTokenAndReconnection": "Your session expired. We need to take you back to the login page in order to refresh it. You might want to save the email you are currently editing before we do so.",
"@messageWarningDialogWhenExpiredOIDCTokenAndReconnection": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"saveAndRefresh": "Save & refresh",
"@saveAndRefresh": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:tmail_ui_user/main/pages/app_pages.dart';
import 'package:tmail_ui_user/main/routes/app_routes.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/utils/app_utils.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:url_strategy/url_strategy.dart';
import 'package:worker_manager/worker_manager.dart';

Expand Down Expand Up @@ -52,6 +53,7 @@ class TMailApp extends StatefulWidget {
class _TMailAppState extends State<TMailApp> {

DeepLinksManager? _deepLinksManager;
final TwakeAppManager _twakeAppManager = Get.find<TwakeAppManager>();

@override
void initState() {
Expand Down Expand Up @@ -105,6 +107,7 @@ class _TMailAppState extends State<TMailApp> {
if (PlatformInfo.isMobile) {
_deepLinksManager?.dispose();
}
_twakeAppManager.dispose();
super.dispose();
}
}
2 changes: 2 additions & 0 deletions lib/main/bindings/core/core_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'package:tmail_ui_user/main/utils/app_config.dart';
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
import 'package:tmail_ui_user/main/utils/ios_notification_manager.dart';
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

class CoreBindings extends Bindings {
Expand Down Expand Up @@ -72,6 +73,7 @@ class CoreBindings extends Bindings {
if (PlatformInfo.isIOS) {
Get.put(IOSNotificationManager());
}
Get.put(TwakeAppManager());
}

void _bindingIsolate() {
Expand Down
22 changes: 15 additions & 7 deletions lib/main/localizations/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4221,13 +4221,6 @@ class AppLocalizations {
);
}

String get dialogMessageSessionHasExpired {
return Intl.message(
'The current session has expired. Please reconnect to the server',
name: 'dialogMessageSessionHasExpired',
);
}

String get sMimeGoodSignatureMessage {
return Intl.message(
'The authenticity of this message had been verified with SMime signature.',
Expand Down Expand Up @@ -4408,4 +4401,19 @@ class AppLocalizations {
name: 'getHelpOrReportABug',
);
}

String get messageWarningDialogWhenExpiredOIDCTokenAndReconnection {
return Intl.message(
'Your session expired. We need to take you back to the login page in order to refresh it. You might want to save the email you are currently editing before we do so.',
name: 'messageWarningDialogWhenExpiredOIDCTokenAndReconnection',
);
}

String get saveAndRefresh {
return Intl.message(
'Save & refresh',
name: 'saveAndRefresh',
);
}

}
20 changes: 20 additions & 0 deletions lib/main/utils/twake_app_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/composer_overlay_state.dart';

class TwakeAppManager {
ComposerOverlayState? _composerOverlayState;

void openComposerOnWeb() =>
_composerOverlayState = ComposerOverlayState.active;

void closeComposerOnWeb() {
_composerOverlayState = ComposerOverlayState.inActive;
_composerOverlayState = null;
}

bool get isComposerOpened =>
_composerOverlayState == ComposerOverlayState.active;

void dispose() {
_composerOverlayState = null;
}
}
5 changes: 5 additions & 0 deletions test/features/base/base_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

import '../../fixtures/account_fixtures.dart';
Expand Down Expand Up @@ -70,6 +71,7 @@ class SomeOtherException extends RemoteException {}
MockSpec<Uuid>(),
MockSpec<ApplicationManager>(),
MockSpec<ToastManager>(),
MockSpec<TwakeAppManager>(),
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -88,6 +90,7 @@ void main() {
late MockUuid mockUuid;
late MockApplicationManager mockApplicationManager;
late MockToastManager mockToastManager;
late MockTwakeAppManager mockTwakeAppManager;

setUpAll(() {
mockCachingManager = MockCachingManager();
Expand All @@ -103,6 +106,7 @@ void main() {
mockUuid = MockUuid();
mockApplicationManager = MockApplicationManager();
mockToastManager = MockToastManager();
mockTwakeAppManager = MockTwakeAppManager();

Get.put<CachingManager>(mockCachingManager);
Get.put<LanguageCacheManager>(mockLanguageCacheManager);
Expand All @@ -121,6 +125,7 @@ void main() {
Get.put<Uuid>(mockUuid);
Get.put<ApplicationManager>(mockApplicationManager);
Get.put<ToastManager>(mockToastManager);
Get.put<TwakeAppManager>(mockTwakeAppManager);
Get.testMode = true;

mockBaseController = MockBaseController();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/app_config.dart';
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

import '../../../fixtures/account_fixtures.dart';
Expand Down Expand Up @@ -142,6 +143,7 @@ class MockMailboxDashBoardController extends Mock implements MailboxDashBoardCon
MockSpec<Uuid>(),
MockSpec<ApplicationManager>(),
MockSpec<ToastManager>(),
MockSpec<TwakeAppManager>(),

// Composer controller mock specs
MockSpec<LocalFilePickerInteractor>(),
Expand Down Expand Up @@ -182,6 +184,7 @@ void main() {
late MockUuid mockUuid;
late MockApplicationManager mockApplicationManager;
late MockToastManager mockToastManager;
late MockTwakeAppManager mockTwakeAppManager;

// Declaration composer controller
late ComposerController? composerController;
Expand Down Expand Up @@ -223,6 +226,7 @@ void main() {
mockUuid = MockUuid();
mockApplicationManager = MockApplicationManager();
mockToastManager = MockToastManager();
mockTwakeAppManager = MockTwakeAppManager();

Get.put<CachingManager>(mockCachingManager);
Get.put<LanguageCacheManager>(mockLanguageCacheManager);
Expand All @@ -241,6 +245,7 @@ void main() {
Get.put<Uuid>(mockUuid);
Get.put<ApplicationManager>(mockApplicationManager);
Get.put<ToastManager>(mockToastManager);
Get.put<TwakeAppManager>(mockTwakeAppManager);

// Mock Getx controllers
Get.put<MailboxDashBoardController>(mockMailboxDashBoardController);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_id
import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart';
import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart';
import 'package:tmail_ui_user/main/utils/toast_manager.dart';
import 'package:tmail_ui_user/main/utils/twake_app_manager.dart';
import 'package:uuid/uuid.dart';

import '../../../../fixtures/email_fixtures.dart';
Expand Down Expand Up @@ -91,6 +92,7 @@ const fallbackGenerators = {
MockSpec<PrintUtils>(),
MockSpec<ApplicationManager>(),
MockSpec<ToastManager>(),
MockSpec<TwakeAppManager>(),
])
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -125,6 +127,7 @@ void main() {
final printUtils = MockPrintUtils();
final applicationManager = MockApplicationManager();
final mockToastManager = MockToastManager();
final mockTwakeAppManager = MockTwakeAppManager();

late SingleEmailController singleEmailController;

Expand Down Expand Up @@ -160,6 +163,7 @@ void main() {
Get.put<PrintUtils>(printUtils);
Get.put<ApplicationManager>(applicationManager);
Get.put<ToastManager>(mockToastManager);
Get.put<TwakeAppManager>(mockTwakeAppManager);

when(mailboxDashboardController.accountId).thenReturn(Rxn(testAccountId));
when(uuid.v4()).thenReturn(testTaskId);
Expand Down
Loading

0 comments on commit ba1e41a

Please sign in to comment.