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
@@ -1,18 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class DeleteEmailStateToRefreshLoading extends UIState {}
class DeleteEmailStateToRefreshSuccess extends UIState {
DeleteEmailStateToRefreshSuccess();
@override
List<Object> get props => [];
}
class DeleteEmailStateToRefreshFailure extends FeatureFailure {
DeleteEmailStateToRefreshFailure(dynamic exception) : super(exception: exception);
}
@@ -1,18 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
class DeleteMailboxStateToRefreshLoading extends UIState {}
class DeleteMailboxStateToRefreshSuccess extends UIState {
DeleteMailboxStateToRefreshSuccess();
@override
List<Object> get props => [];
}
class DeleteMailboxStateToRefreshFailure extends FeatureFailure {
DeleteMailboxStateToRefreshFailure(dynamic exception) : super(exception: exception);
}
@@ -1,21 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
class GetEmailStateToRefreshLoading extends UIState {}
class GetEmailStateToRefreshSuccess extends UIState {
final jmap.State storedState;
GetEmailStateToRefreshSuccess(this.storedState);
@override
List<Object> get props => [storedState];
}
class GetEmailStateToRefreshFailure extends FeatureFailure {
GetEmailStateToRefreshFailure(dynamic exception) : super(exception: exception);
}
@@ -1,21 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
class GetMailboxStateToRefreshLoading extends UIState {}
class GetMailboxStateToRefreshSuccess extends UIState {
final jmap.State storedState;
GetMailboxStateToRefreshSuccess(this.storedState);
@override
List<Object> get props => [storedState];
}
class GetMailboxStateToRefreshFailure extends FeatureFailure {
GetMailboxStateToRefreshFailure(dynamic exception) : super(exception: exception);
}
@@ -1,24 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_email_state_to_refresh_state.dart';
class DeleteEmailStateToRefreshInteractor {
final FCMRepository _fcmRepository;
DeleteEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.emailType);
yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e));
}
}
}
@@ -1,24 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_mailbox_state_to_refresh_state.dart';
class DeleteMailboxStateToRefreshInteractor {
final FCMRepository _fcmRepository;
DeleteMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(DeleteMailboxStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.mailboxType);
yield Right<Failure, Success>(DeleteMailboxStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(DeleteMailboxStateToRefreshFailure(e));
}
}
}
@@ -1,24 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
class GetEmailStateToRefreshInteractor {
final FCMRepository _fcmRepository;
GetEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(GetEmailStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.emailType);
yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e));
}
}
}
@@ -1,24 +0,0 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart';
class GetMailboxStateToRefreshInteractor {
final FCMRepository _fcmRepository;
GetMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(GetMailboxStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.mailboxType);
yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e));
}
}
}
@@ -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,
));
}
}
}