From 8aac2064681042698e873839814a708df5e54270 Mon Sep 17 00:00:00 2001 From: dab246 Date: Mon, 4 Dec 2023 10:54:36 +0700 Subject: [PATCH] TF-2298 Show default notification when get failure Signed-off-by: dab246 (cherry picked from commit 2e7b415a3f1e98e7b43b4e45c968b7242817c57f) --- .../listener/email_change_listener.dart | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/features/push_notification/presentation/listener/email_change_listener.dart b/lib/features/push_notification/presentation/listener/email_change_listener.dart index b950f2c2c..de567bc9c 100644 --- a/lib/features/push_notification/presentation/listener/email_change_listener.dart +++ b/lib/features/push_notification/presentation/listener/email_change_listener.dart @@ -52,6 +52,7 @@ import 'package:tmail_ui_user/features/push_notification/presentation/utils/fcm_ import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart'; import 'package:tmail_ui_user/main/localizations/app_localizations.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; +import 'package:uuid/uuid.dart'; class EmailChangeListener extends ChangeListener { @@ -155,6 +156,8 @@ class EmailChangeListener extends ChangeListener { void _getStoredEmailDeliveryState(AccountId accountId, UserName userName) { if (_getStoredEmailDeliveryStateInteractor != null) { consumeState(_getStoredEmailDeliveryStateInteractor!.execute(accountId, userName)); + } else { + _showDefaultLocalNotification(); } } @@ -162,6 +165,7 @@ class EmailChangeListener extends ChangeListener { if (_getStoredEmailStateInteractor != null && _session != null && _accountId != null) { consumeState(_getStoredEmailStateInteractor!.execute(_session!, _accountId!)); } else { + _showDefaultLocalNotification(); logError('EmailChangeListener::_getStoredEmailState(): _getStoredEmailStateInteractor is null'); } } @@ -179,12 +183,16 @@ class EmailChangeListener extends ChangeListener { propertiesCreated: EmailUtils.getPropertiesForEmailGetMethod(_session!, _accountId!), propertiesUpdated: ThreadConstants.propertiesUpdatedDefault, )); + } else { + _showDefaultLocalNotification(); } } void _storeEmailDeliveryStateAction(AccountId accountId, UserName userName, jmap.State state) { if (_storeEmailDeliveryStateInteractor != null) { consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, userName, state)); + } else { + _showDefaultLocalNotification(); } } @@ -216,12 +224,32 @@ class EmailChangeListener extends ChangeListener { await LocalNotificationManager.instance.setNotificationBadgeForIOS(); } + void _showDefaultLocalNotification() { + LocalNotificationManager.instance.showPushNotification( + id: '${FcmUtils.instance.platformOS}-${const Uuid().v1()}', + title: currentContext != null + ? AppLocalizations.of(currentContext!).appTitlePushNotification + : LocalNotificationConfig.notificationTitle, + message: currentContext != null + ? AppLocalizations.of(currentContext!).youHaveNewMessages + : LocalNotificationConfig.notificationMessage, + ); + + if (PlatformInfo.isAndroid) { + LocalNotificationManager.instance.groupPushNotification(); + } + } + @override void handleFailureViewState(Failure failure) { log('EmailChangeListener::_handleFailureViewState(): $failure'); if (failure is GetStoredEmailDeliveryStateFailure && failure.exception is NotFoundEmailDeliveryStateException) { _getStoredEmailState(); + } else if (failure is NotFoundEmailState || + failure is GetStoredEmailStateFailure || + failure is GetEmailChangesToPushNotificationFailure) { + _showDefaultLocalNotification(); } else if (failure is GetMailboxesNotPutNotificationsFailure) { final listEmails = _emailsAvailablePushNotification.toEmailsAvailablePushNotification(); _handleLocalPushNotification(listEmails); @@ -234,6 +262,8 @@ class EmailChangeListener extends ChangeListener { if (success is GetStoredEmailDeliveryStateSuccess) { if (_newStateEmailDelivery != success.state) { _getEmailChangesAction(success.state); + } else { + _showDefaultLocalNotification(); } } else if (success is GetStoredEmailStateSuccess) { _getEmailChangesAction(success.state); @@ -243,7 +273,11 @@ class EmailChangeListener extends ChangeListener { if (FcmUtils.instance.isMobileAndroid) { _handleListEmailToPushNotification(success.emailList); + } else { + _showDefaultLocalNotification(); } + } else { + _showDefaultLocalNotification(); } } else if (success is GetMailboxesNotPutNotificationsSuccess) { final listEmails = _emailsAvailablePushNotification.toEmailsAvailablePushNotification( @@ -274,6 +308,7 @@ class EmailChangeListener extends ChangeListener { void _handleLocalPushNotification(List emailList) { log('EmailChangeListener::_handleLocalPushNotification():emailList: $emailList'); if (emailList.isEmpty) { + _showDefaultLocalNotification(); return; }