diff --git a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart index 7ad58524b..14e6a2cf4 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -371,8 +371,8 @@ class MailboxDashBoardController extends ReloadableController { } void _handleClickLocalNotificationOnTerminated() async { - await _notificationManager.getNotificationDetails(); - final notificationResponse = _notificationManager.currentNotificationResponse; + _notificationManager.activatedNotificationClickedOnTerminate = true; + final notificationResponse = await _notificationManager.getCurrentNotificationResponse(); log('MailboxDashBoardController::_handleClickLocalNotificationOnTerminated():payload: ${notificationResponse?.payload}'); final emailIdFromPayload = notificationResponse?.payload; final currentAccountId = accountId.value; @@ -391,9 +391,6 @@ class MailboxDashBoardController extends ReloadableController { } void _getSessionCurrent() { - if (BuildUtils.isWeb) { - dispatchRoute(DashboardRoutes.thread); - } final arguments = Get.arguments; log('MailboxDashBoardController::_getSessionCurrent(): arguments = $arguments'); if (arguments is Session) { @@ -406,10 +403,13 @@ class MailboxDashBoardController extends ReloadableController { injectFCMBindings(sessionCurrent, accountId.value); _getVacationResponse(); - if (!BuildUtils.isWeb) { + if (!BuildUtils.isWeb && !_notificationManager.isNotificationClickedOnTerminate) { _handleClickLocalNotificationOnTerminated(); + } else { + dispatchRoute(DashboardRoutes.thread); } } else { + dispatchRoute(DashboardRoutes.thread); reload(); } } @@ -1383,6 +1383,7 @@ class MailboxDashBoardController extends ReloadableController { } void _handleClickLocalNotificationOnForeground(NotificationResponse? response) { + _notificationManager.activatedNotificationClickedOnTerminate = true; log('MailboxDashBoardController::_handleClickLocalNotificationOnForeground():payload: ${response?.payload}'); final emailIdFromPayload = response?.payload; final currentAccountId = accountId.value; diff --git a/lib/features/push_notification/presentation/notification/local_notification_manager.dart b/lib/features/push_notification/presentation/notification/local_notification_manager.dart index 2853ec4fa..614cb9667 100644 --- a/lib/features/push_notification/presentation/notification/local_notification_manager.dart +++ b/lib/features/push_notification/presentation/notification/local_notification_manager.dart @@ -18,7 +18,9 @@ class LocalNotificationManager { static LocalNotificationManager get instance => _instance; final _localNotificationsPlugin = FlutterLocalNotificationsPlugin(); - bool notificationsEnabled = false; + + bool _notificationsEnabled = false; + bool _isNotificationClickedOnTerminate = false; final StreamController localNotificationsController = StreamController.broadcast(); @@ -40,16 +42,19 @@ class LocalNotificationManager { return Future.value(); } - Future getNotificationDetails() async { + Future getCurrentNotificationResponse() async { try { _notificationAppLaunchDetails = await _localNotificationsPlugin.getNotificationAppLaunchDetails(); + return _notificationAppLaunchDetails?.notificationResponse; } catch (e) { - logError('LocalNotificationManager::getNotificationDetails(): ERROR: ${e.toString()}'); + logError('LocalNotificationManager::getCurrentNotificationResponse(): ERROR: ${e.toString()}'); } - return Future.value(); + return Future.value(null); } - NotificationResponse? get currentNotificationResponse => _notificationAppLaunchDetails?.notificationResponse; + set activatedNotificationClickedOnTerminate(bool clicked) => _isNotificationClickedOnTerminate = clicked; + + bool get isNotificationClickedOnTerminate => _isNotificationClickedOnTerminate; Future _initLocalNotification() async { return await _localNotificationsPlugin.initialize( @@ -69,17 +74,17 @@ class LocalNotificationManager { } void _checkLocalNotificationPermission() async { - if (notificationsEnabled) { + if (_notificationsEnabled) { return; } if (Platform.isAndroid) { final granted = await _isAndroidPermissionGranted(); if (!granted) { - notificationsEnabled = await _requestPermissions(); + _notificationsEnabled = await _requestPermissions(); } } else { - notificationsEnabled = await _requestPermissions(); + _notificationsEnabled = await _requestPermissions(); } }