Auto refresh mails when resume app from background

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-06-17 17:03:39 +07:00
committed by Dat H. Pham
parent 4bd5ecc5d4
commit 23019ae030
17 changed files with 35 additions and 266 deletions
@@ -43,14 +43,11 @@ import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_ma
import 'package:tmail_ui_user/features/push_notification/data/network/fcm_api.dart';
import 'package:tmail_ui_user/features/push_notification/data/repository/fcm_repository_impl.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/delete_firebase_registration_cache_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/destroy_firebase_registration_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_changes_to_remove_notification_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_firebase_registration_by_device_id_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_mailboxes_not_put_notifications_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_new_receive_email_from_notification_interactor.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart';
@@ -147,11 +144,8 @@ class FcmInteractorBindings extends InteractorsBindings {
Get.lazyPut(() => GetEmailChangesToRemoveNotificationInteractor(
Get.find<FCMRepositoryImpl>(),
Get.find<EmailRepository>()));
Get.lazyPut(() => GetEmailStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => DeleteEmailStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => GetFirebaseRegistrationByDeviceIdInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => RegisterNewFirebaseRegistrationTokenInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => GetMailboxStateToRefreshInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => StoreFirebaseRegistrationInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => GetStoredFirebaseRegistrationInteractor(Get.find<FCMRepositoryImpl>()));
Get.lazyPut(() => DestroyFirebaseRegistrationInteractor(Get.find<FCMRepositoryImpl>()));
@@ -114,9 +114,9 @@ class EmailChangeListener extends ChangeListener {
void _synchronizeEmailOnForegroundAction(jmap.State newState) {
log('EmailChangeListener::_synchronizeEmailAction():newState: $newState');
if (_dashBoardController != null) {
_dashBoardController!.dispatchEmailUIAction(RefreshChangeEmailAction(newState));
}
_dashBoardController?.dispatchEmailUIAction(RefreshChangeEmailAction(
newState: newState,
));
}
void _pushNotificationAction(jmap.State newState, AccountId accountId, UserName userName, Session? session) {
@@ -1,4 +1,3 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.dart';
@@ -11,18 +10,19 @@ import 'package:tmail_ui_user/features/push_notification/presentation/listener/c
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class MailboxChangeListener extends ChangeListener {
MailboxDashBoardController? _dashBoardController;
MailboxChangeListener._internal() {
try {
_dashBoardController = getBinding<MailboxDashBoardController>();
} catch (e) {
logError('MailboxChangeListener::_internal(): IS NOT REGISTERED: ${e.toString()}');
logError(
'MailboxChangeListener::_internal(): IS NOT REGISTERED: ${e.toString()}');
}
}
static final MailboxChangeListener _instance = MailboxChangeListener._internal();
static final MailboxChangeListener _instance =
MailboxChangeListener._internal();
static MailboxChangeListener get instance => _instance;
@@ -48,8 +48,8 @@ class MailboxChangeListener extends ChangeListener {
void _synchronizeMailboxOnForegroundAction(jmap.State newState) {
log('MailboxChangeListener::_synchronizeMailboxOnForegroundAction():newState: $newState');
if (_dashBoardController != null) {
_dashBoardController!.dispatchMailboxUIAction(RefreshChangeMailboxAction(newState));
}
_dashBoardController?.dispatchMailboxUIAction(RefreshChangeMailboxAction(
newState: newState,
));
}
}
}