From 550752a2a494508b78c891edf3292732c335f80f Mon Sep 17 00:00:00 2001 From: dab246 Date: Tue, 25 Apr 2023 18:15:02 +0700 Subject: [PATCH] Store and get fcm cache by AccountId (cherry picked from commit e327dff45a4fc67d0c5a2d2afe64fc4673e2eac1) --- lib/features/caching/caching_manager.dart | 43 +++++++++---------- lib/features/caching/fcm_cache_client.dart | 9 ++++ .../caching/utils/caching_constants.dart | 2 + .../mailbox_dashboard_controller.dart | 16 +++---- .../data/datasource/fcm_datasource.dart | 7 +-- .../cache_fcm_datasource_impl.dart | 13 +++--- .../datasource_impl/fcm_datasource_impl.dart | 7 +-- .../data/local/fcm_cache_manager.dart | 37 ++++++++-------- .../data/repository/fcm_repository_impl.dart | 12 +++--- .../domain/repository/fcm_repository.dart | 6 +-- ...il_changes_to_push_notification_state.dart | 6 ++- ...ete_email_state_to_refresh_interactor.dart | 5 ++- ...e_mailbox_state_to_refresh_interactor.dart | 5 ++- ...anges_to_push_notification_interactor.dart | 2 +- ...get_email_state_to_refresh_interactor.dart | 5 ++- ...t_mailbox_state_to_refresh_interactor.dart | 5 ++- ...tored_email_delivery_state_interactor.dart | 5 ++- ...store_email_delivery_state_interactor.dart | 5 ++- ...ore_email_state_to_refresh_interactor.dart | 5 ++- ...e_mailbox_state_to_refresh_interactor.dart | 5 ++- .../listener/email_change_listener.dart | 24 +++++------ .../listener/mailbox_change_listener.dart | 7 +-- lib/main/bindings/local/local_bindings.dart | 6 ++- 23 files changed, 130 insertions(+), 107 deletions(-) create mode 100644 lib/features/caching/fcm_cache_client.dart diff --git a/lib/features/caching/caching_manager.dart b/lib/features/caching/caching_manager.dart index a5c8c8d0d..e65275160 100644 --- a/lib/features/caching/caching_manager.dart +++ b/lib/features/caching/caching_manager.dart @@ -1,15 +1,14 @@ import 'package:core/utils/app_logger.dart'; import 'package:tmail_ui_user/features/caching/account_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart'; import 'package:tmail_ui_user/features/caching/email_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/fcm_cache_client.dart'; import 'package:tmail_ui_user/features/caching/hive_cache_version_client.dart'; import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; import 'package:tmail_ui_user/features/caching/recent_search_cache_client.dart'; import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; import 'package:tmail_ui_user/features/caching/subscription_cache_client.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; -import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart'; - -import 'config/hive_cache_config.dart'; class CachingManager { final MailboxCacheClient _mailboxCacheClient; @@ -17,7 +16,7 @@ class CachingManager { final EmailCacheClient _emailCacheClient; final RecentSearchCacheClient _recentSearchCacheClient; final AccountCacheClient _accountCacheClient; - final FCMCacheManager _fcmCacheManager; + final FcmCacheClient _fcmCacheClient; final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient; final HiveCacheVersionClient _hiveCacheVersionClient; @@ -27,7 +26,7 @@ class CachingManager { this._emailCacheClient, this._recentSearchCacheClient, this._accountCacheClient, - this._fcmCacheManager, + this._fcmCacheClient, this._fcmSubscriptionCacheClient, this._hiveCacheVersionClient, ); @@ -37,11 +36,22 @@ class CachingManager { _stateCacheClient.clearAllData(), _mailboxCacheClient.clearAllData(), _emailCacheClient.clearAllData(), - _recentSearchCacheClient.clearAllData(), - _accountCacheClient.clearAllData(), + _fcmCacheClient.clearAllData(), _fcmSubscriptionCacheClient.clearAllData(), - _fcmCacheManager.clearAllStateToRefresh() - ]); + _recentSearchCacheClient.clearAllData(), + _accountCacheClient.clearAllData() + ]); + } + + Future clearData() async { + await Future.wait([ + _stateCacheClient.clearAllData(), + _mailboxCacheClient.clearAllData(), + _emailCacheClient.clearAllData(), + _fcmCacheClient.clearAllData(), + _fcmSubscriptionCacheClient.clearAllData(), + _recentSearchCacheClient.clearAllData() + ]); } Future clearEmailCache() async { @@ -52,23 +62,12 @@ class CachingManager { log('CachingManager::clearEmailCache(): success'); } - Future clearMailboxCache() async { - await Future.wait([ - _stateCacheClient.deleteItem(StateType.mailbox.value), - _mailboxCacheClient.clearAllData(), - ]); - log('CachingManager::clearMailboxCache(): success'); - } - Future onUpgradeCache(int oldVersion, int newVersion) async { log('CachingManager::onUpgradeCache():oldVersion $oldVersion | newVersion: $newVersion'); if (oldVersion == 0 && newVersion >= 1) { - await Future.wait([ - clearMailboxCache(), - clearEmailCache() - ]); + await clearData(); } - storeCacheVersion(newVersion); + await storeCacheVersion(newVersion); return Future.value(); } diff --git a/lib/features/caching/fcm_cache_client.dart b/lib/features/caching/fcm_cache_client.dart new file mode 100644 index 000000000..4f285e36f --- /dev/null +++ b/lib/features/caching/fcm_cache_client.dart @@ -0,0 +1,9 @@ + +import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/utils/caching_constants.dart'; + +class FcmCacheClient extends HiveCacheClient { + + @override + String get tableName => CachingConstants.fcmCacheBoxName; +} \ No newline at end of file diff --git a/lib/features/caching/utils/caching_constants.dart b/lib/features/caching/utils/caching_constants.dart index c550213d0..17cd34819 100644 --- a/lib/features/caching/utils/caching_constants.dart +++ b/lib/features/caching/utils/caching_constants.dart @@ -14,4 +14,6 @@ class CachingConstants { static const int RECENT_LOGIN_URL_HIVE_CACHE_IDENTITY = 12; static const int RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY = 13; static const int FCM_SUBSCRIPTION_HIVE_CACHE_IDENTITY = 14; + + static const String fcmCacheBoxName = 'fcm_cache_box'; } \ No newline at end of file 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 fc8e96224..fe483ae47 100644 --- a/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart @@ -1428,11 +1428,11 @@ class MailboxDashBoardController extends ReloadableController { } catch (e) { logError('MailboxDashBoardController::_handleRefreshActionWhenBackToApp(): $e'); } - if (_getEmailStateToRefreshInteractor != null) { - consumeState(_getEmailStateToRefreshInteractor!.execute()); + if (_getEmailStateToRefreshInteractor != null && accountId.value != null) { + consumeState(_getEmailStateToRefreshInteractor!.execute(accountId.value!)); } - if (_getMailboxStateToRefreshInteractor != null) { - consumeState(_getMailboxStateToRefreshInteractor!.execute()); + if (_getMailboxStateToRefreshInteractor != null && accountId.value != null) { + consumeState(_getMailboxStateToRefreshInteractor!.execute(accountId.value!)); } } @@ -1443,8 +1443,8 @@ class MailboxDashBoardController extends ReloadableController { } catch (e) { logError('MailboxDashBoardController::_deleteEmailStateToRefreshAction(): $e'); } - if (_deleteEmailStateToRefreshInteractor != null) { - consumeState(_deleteEmailStateToRefreshInteractor!.execute()); + if (_deleteEmailStateToRefreshInteractor != null && accountId.value != null) { + consumeState(_deleteEmailStateToRefreshInteractor!.execute(accountId.value!)); } } @@ -1455,8 +1455,8 @@ class MailboxDashBoardController extends ReloadableController { } catch (e) { logError('MailboxDashBoardController::_deleteMailboxStateToRefreshAction(): $e'); } - if (_deleteMailboxStateToRefreshInteractor != null) { - consumeState(_deleteMailboxStateToRefreshInteractor!.execute()); + if (_deleteMailboxStateToRefreshInteractor != null && accountId.value != null) { + consumeState(_deleteMailboxStateToRefreshInteractor!.execute(accountId.value!)); } } diff --git a/lib/features/push_notification/data/datasource/fcm_datasource.dart b/lib/features/push_notification/data/datasource/fcm_datasource.dart index 38efcca75..6435f72ae 100644 --- a/lib/features/push_notification/data/datasource/fcm_datasource.dart +++ b/lib/features/push_notification/data/datasource/fcm_datasource.dart @@ -1,16 +1,17 @@ import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/type_name.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart'; import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart'; abstract class FCMDatasource { - Future storeStateToRefresh(TypeName typeName, jmap.State newState); + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState); - Future getStateToRefresh(TypeName typeName); + Future getStateToRefresh(AccountId accountId, TypeName typeName); - Future deleteStateToRefresh(TypeName typeName); + Future deleteStateToRefresh(AccountId accountId, TypeName typeName); Future storeSubscription(FCMSubscriptionCache fcmSubscriptionCache); diff --git a/lib/features/push_notification/data/datasource_impl/cache_fcm_datasource_impl.dart b/lib/features/push_notification/data/datasource_impl/cache_fcm_datasource_impl.dart index 8827626fc..618b9d393 100644 --- a/lib/features/push_notification/data/datasource_impl/cache_fcm_datasource_impl.dart +++ b/lib/features/push_notification/data/datasource_impl/cache_fcm_datasource_impl.dart @@ -1,5 +1,6 @@ import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/type_name.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart'; import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart'; @@ -15,23 +16,23 @@ class CacheFCMDatasourceImpl extends FCMDatasource { CacheFCMDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower); @override - Future storeStateToRefresh(TypeName typeName, jmap.State newState) { + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) { return Future.sync(() async { - return await _firebaseCacheManager.storeStateToRefresh(typeName, newState); + return await _firebaseCacheManager.storeStateToRefresh(accountId, typeName, newState); }).catchError(_exceptionThrower.throwException); } @override - Future getStateToRefresh(TypeName typeName) { + Future getStateToRefresh(AccountId accountId, TypeName typeName) { return Future.sync(() async { - return await _firebaseCacheManager.getStateToRefresh(typeName); + return await _firebaseCacheManager.getStateToRefresh(accountId, typeName); }).catchError(_exceptionThrower.throwException); } @override - Future deleteStateToRefresh(TypeName typeName) { + Future deleteStateToRefresh(AccountId accountId, TypeName typeName) { return Future.sync(() async { - return await _firebaseCacheManager.deleteStateToRefresh(typeName); + return await _firebaseCacheManager.deleteStateToRefresh(accountId, typeName); }).catchError(_exceptionThrower.throwException); } diff --git a/lib/features/push_notification/data/datasource_impl/fcm_datasource_impl.dart b/lib/features/push_notification/data/datasource_impl/fcm_datasource_impl.dart index a02391835..4ad66ba8e 100644 --- a/lib/features/push_notification/data/datasource_impl/fcm_datasource_impl.dart +++ b/lib/features/push_notification/data/datasource_impl/fcm_datasource_impl.dart @@ -1,5 +1,6 @@ import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/type_name.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/data/datasource/fcm_datasource.dart'; import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart'; @@ -23,17 +24,17 @@ class FcmDatasourceImpl extends FCMDatasource { } @override - Future deleteStateToRefresh(TypeName typeName) { + Future deleteStateToRefresh(AccountId accountId, TypeName typeName) { throw UnimplementedError(); } @override - Future getStateToRefresh(TypeName typeName) { + Future getStateToRefresh(AccountId accountId, TypeName typeName) { throw UnimplementedError(); } @override - Future storeStateToRefresh(TypeName typeName, jmap.State newState) { + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) { throw UnimplementedError(); } diff --git a/lib/features/push_notification/data/local/fcm_cache_manager.dart b/lib/features/push_notification/data/local/fcm_cache_manager.dart index ac848cb21..c2105ef34 100644 --- a/lib/features/push_notification/data/local/fcm_cache_manager.dart +++ b/lib/features/push_notification/data/local/fcm_cache_manager.dart @@ -1,27 +1,27 @@ -import 'package:core/utils/app_logger.dart'; import 'package:fcm/model/type_name.dart'; -import 'package:shared_preferences/shared_preferences.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:model/extensions/account_id_extensions.dart'; +import 'package:tmail_ui_user/features/caching/fcm_cache_client.dart'; import 'package:tmail_ui_user/features/caching/subscription_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart'; import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart'; import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; class FCMCacheManager { - final SharedPreferences _sharedPreferences; + final FcmCacheClient _fcmCacheClient; final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient; + FCMCacheManager(this._fcmCacheClient,this._fcmSubscriptionCacheClient); - FCMCacheManager(this._sharedPreferences,this._fcmSubscriptionCacheClient); - - Future storeStateToRefresh(TypeName typeName, jmap.State newState) { - return _sharedPreferences.setString(typeName.value, newState.value); + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) { + final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString(); + return _fcmCacheClient.insertItem(stateKeyCache, newState.value); } - Future getStateToRefresh(TypeName typeName) async { - log('FCMCacheManager::getStoredFcmStateChange():keys_BEFORE: ${_sharedPreferences.getKeys().toString()}'); - await _sharedPreferences.reload(); - log('FCMCacheManager::getStoredFcmStateChange():keys_AFTER: ${_sharedPreferences.getKeys().toString()}'); - final stateValue = _sharedPreferences.getString(typeName.value); + Future getStateToRefresh(AccountId accountId, TypeName typeName) async { + final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString(); + final stateValue = await _fcmCacheClient.getItem(stateKeyCache); if (stateValue != null) { return jmap.State(stateValue); } else { @@ -33,16 +33,13 @@ class FCMCacheManager { } } - Future deleteStateToRefresh(TypeName typeName) { - return _sharedPreferences.remove(typeName.value); + Future deleteStateToRefresh(AccountId accountId, TypeName typeName) { + final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString(); + return _fcmCacheClient.deleteItem(stateKeyCache); } - Future clearAllStateToRefresh() async { - return await Future.wait([ - _sharedPreferences.remove(TypeName.emailType.value), - _sharedPreferences.remove(TypeName.mailboxType.value), - _sharedPreferences.remove(TypeName.emailDelivery.value), - ]).then((listResult) => listResult.every((result) => result)); + Future clearAllStateToRefresh() async { + return _fcmCacheClient.clearAllData(); } Future storeSubscription(FCMSubscriptionCache fcmSubscriptionCache) { diff --git a/lib/features/push_notification/data/repository/fcm_repository_impl.dart b/lib/features/push_notification/data/repository/fcm_repository_impl.dart index 8ac272c62..5a355d8d1 100644 --- a/lib/features/push_notification/data/repository/fcm_repository_impl.dart +++ b/lib/features/push_notification/data/repository/fcm_repository_impl.dart @@ -75,18 +75,18 @@ class FCMRepositoryImpl extends FCMRepository { } @override - Future storeStateToRefresh(TypeName typeName, jmap.State newState) { - return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(typeName, newState); + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) { + return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, typeName, newState); } @override - Future getStateToRefresh(TypeName typeName) { - return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(typeName); + Future getStateToRefresh(AccountId accountId, TypeName typeName) { + return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, typeName); } @override - Future deleteStateToRefresh(TypeName typeName) { - return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(typeName); + Future deleteStateToRefresh(AccountId accountId, TypeName typeName) { + return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, typeName); } @override diff --git a/lib/features/push_notification/domain/repository/fcm_repository.dart b/lib/features/push_notification/domain/repository/fcm_repository.dart index 14dec7177..0a2362612 100644 --- a/lib/features/push_notification/domain/repository/fcm_repository.dart +++ b/lib/features/push_notification/domain/repository/fcm_repository.dart @@ -21,11 +21,11 @@ abstract class FCMRepository { } ); - Future storeStateToRefresh(TypeName typeName, jmap.State newState); + Future storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState); - Future getStateToRefresh(TypeName typeName); + Future getStateToRefresh(AccountId accountId, TypeName typeName); - Future deleteStateToRefresh(TypeName typeName); + Future deleteStateToRefresh(AccountId accountId, TypeName typeName); Future storeSubscription(FCMSubscription fcmSubscription); diff --git a/lib/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart b/lib/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart index da8b605f6..6a65b363a 100644 --- a/lib/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart +++ b/lib/features/push_notification/domain/state/get_email_changes_to_push_notification_state.dart @@ -1,6 +1,7 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:model/email/presentation_email.dart'; class GetEmailChangesToPushNotificationLoading extends UIState {} @@ -8,11 +9,12 @@ class GetEmailChangesToPushNotificationLoading extends UIState {} class GetEmailChangesToPushNotificationSuccess extends UIState { final List emailList; + final AccountId accountId; - GetEmailChangesToPushNotificationSuccess(this.emailList); + GetEmailChangesToPushNotificationSuccess(this.accountId, this.emailList); @override - List get props => [emailList]; + List get props => [accountId, emailList]; } class GetEmailChangesToPushNotificationFailure extends FeatureFailure { diff --git a/lib/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart index e5a992df9..3046a29cb 100644 --- a/lib/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/delete_email_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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: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'; @@ -10,10 +11,10 @@ class DeleteEmailStateToRefreshInteractor { DeleteEmailStateToRefreshInteractor(this._fcmRepository); - Stream> execute() async* { + Stream> execute(AccountId accountId) async* { try { yield Right(DeleteEmailStateToRefreshLoading()); - await _fcmRepository.deleteStateToRefresh(TypeName.emailType); + await _fcmRepository.deleteStateToRefresh(accountId, TypeName.emailType); yield Right(DeleteEmailStateToRefreshSuccess()); } catch (e) { yield Left(DeleteEmailStateToRefreshFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/delete_mailbox_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/delete_mailbox_state_to_refresh_interactor.dart index cc3c6db62..98f2265b6 100644 --- a/lib/features/push_notification/domain/usecases/delete_mailbox_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/delete_mailbox_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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: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'; @@ -10,10 +11,10 @@ class DeleteMailboxStateToRefreshInteractor { DeleteMailboxStateToRefreshInteractor(this._fcmRepository); - Stream> execute() async* { + Stream> execute(AccountId accountId) async* { try { yield Right(DeleteMailboxStateToRefreshLoading()); - await _fcmRepository.deleteStateToRefresh(TypeName.mailboxType); + await _fcmRepository.deleteStateToRefresh(accountId, TypeName.mailboxType); yield Right(DeleteMailboxStateToRefreshSuccess()); } catch (e) { yield Left(DeleteMailboxStateToRefreshFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart b/lib/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart index 9bb84ec0e..f89af5042 100644 --- a/lib/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart +++ b/lib/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart @@ -37,7 +37,7 @@ class GetEmailChangesToPushNotificationInteractor { ?.map((email) => email.toPresentationEmail()) .toList() ?? List.empty(); - yield Right(GetEmailChangesToPushNotificationSuccess(presentationEmailList)); + yield Right(GetEmailChangesToPushNotificationSuccess(accountId, presentationEmailList)); } catch (e) { yield Left(GetEmailChangesToPushNotificationFailure(e)); } diff --git a/lib/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart index 0476ba7a6..184867e69 100644 --- a/lib/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/get_email_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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: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'; @@ -10,10 +11,10 @@ class GetEmailStateToRefreshInteractor { GetEmailStateToRefreshInteractor(this._fcmRepository); - Stream> execute() async* { + Stream> execute(AccountId accountId) async* { try { yield Right(GetEmailStateToRefreshLoading()); - final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailType); + final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailType); yield Right(GetEmailStateToRefreshSuccess(storedState)); } catch (e) { yield Left(GetEmailStateToRefreshFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart index 28d8e30d3..a7119edec 100644 --- a/lib/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/get_mailbox_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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: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'; @@ -10,10 +11,10 @@ class GetMailboxStateToRefreshInteractor { GetMailboxStateToRefreshInteractor(this._fcmRepository); - Stream> execute() async* { + Stream> execute(AccountId accountId) async* { try { yield Right(GetMailboxStateToRefreshLoading()); - final storedState = await _fcmRepository.getStateToRefresh(TypeName.mailboxType); + final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.mailboxType); yield Right(GetMailboxStateToRefreshSuccess(storedState)); } catch (e) { yield Left(GetMailboxStateToRefreshFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart b/lib/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart index a14e8a98c..779906089 100644 --- a/lib/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart +++ b/lib/features/push_notification/domain/usecases/get_stored_email_delivery_state_interactor.dart @@ -2,6 +2,7 @@ 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:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/get_stored_email_delivery_state.dart'; @@ -10,10 +11,10 @@ class GetStoredEmailDeliveryStateInteractor { GetStoredEmailDeliveryStateInteractor(this._fcmRepository); - Stream> execute() async* { + Stream> execute(AccountId accountId) async* { try { yield Right(GetStoredEmailDeliveryStateLoading()); - final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailDelivery); + final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailDelivery); yield Right(GetStoredEmailDeliveryStateSuccess(storedState)); } catch (e) { yield Left(GetStoredEmailDeliveryStateFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/store_email_delivery_state_interactor.dart b/lib/features/push_notification/domain/usecases/store_email_delivery_state_interactor.dart index 134c6a51a..f1b811f65 100644 --- a/lib/features/push_notification/domain/usecases/store_email_delivery_state_interactor.dart +++ b/lib/features/push_notification/domain/usecases/store_email_delivery_state_interactor.dart @@ -2,6 +2,7 @@ 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/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_delivery_state.dart'; @@ -11,10 +12,10 @@ class StoreEmailDeliveryStateInteractor { StoreEmailDeliveryStateInteractor(this._fcmRepository); - Stream> execute(jmap.State newState) async* { + Stream> execute(AccountId accountId, jmap.State newState) async* { try { yield Right(StoreEmailDeliveryStateLoading()); - await _fcmRepository.storeStateToRefresh(TypeName.emailDelivery, newState); + await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailDelivery, newState); yield Right(StoreEmailDeliveryStateSuccess()); } catch (e) { yield Left(StoreEmailDeliveryStateFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/store_email_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/store_email_state_to_refresh_interactor.dart index 2f1398d0d..1bdb92ee2 100644 --- a/lib/features/push_notification/domain/usecases/store_email_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/store_email_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_state_to_refresh_state.dart'; @@ -11,10 +12,10 @@ class StoreEmailStateToRefreshInteractor { StoreEmailStateToRefreshInteractor(this._fcmRepository); - Stream> execute(jmap.State newState) async* { + Stream> execute(AccountId accountId, jmap.State newState) async* { try { yield Right(StoreEmailStateToRefreshLoading()); - await _fcmRepository.storeStateToRefresh(TypeName.emailType, newState); + await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailType, newState); yield Right(StoreEmailStateToRefreshSuccess()); } catch (e) { yield Left(StoreEmailStateToRefreshFailure(e)); diff --git a/lib/features/push_notification/domain/usecases/store_mailbox_state_to_refresh_interactor.dart b/lib/features/push_notification/domain/usecases/store_mailbox_state_to_refresh_interactor.dart index 660db313a..633d14997 100644 --- a/lib/features/push_notification/domain/usecases/store_mailbox_state_to_refresh_interactor.dart +++ b/lib/features/push_notification/domain/usecases/store_mailbox_state_to_refresh_interactor.dart @@ -2,6 +2,7 @@ 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/state.dart' as jmap; import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart'; import 'package:tmail_ui_user/features/push_notification/domain/state/store_mailbox_state_to_refresh_state.dart'; @@ -11,10 +12,10 @@ class StoreMailboxStateToRefreshInteractor { StoreMailboxStateToRefreshInteractor(this._fcmRepository); - Stream> execute(jmap.State newState) async* { + Stream> execute(AccountId accountId, jmap.State newState) async* { try { yield Right(StoreMailboxStateToRefreshLoading()); - await _fcmRepository.storeStateToRefresh(TypeName.mailboxType, newState); + await _fcmRepository.storeStateToRefresh(accountId, TypeName.mailboxType, newState); yield Right(StoreMailboxStateToRefreshSuccess()); } catch (e) { yield Left(StoreMailboxStateToRefreshFailure(e)); 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 c17d984ae..62216d764 100644 --- a/lib/features/push_notification/presentation/listener/email_change_listener.dart +++ b/lib/features/push_notification/presentation/listener/email_change_listener.dart @@ -90,7 +90,7 @@ class EmailChangeListener extends ChangeListener { if (FcmUtils.instance.isMobileAndroid) { _handleRemoveNotificationWhenEmailMarkAsRead(action.newState, action.accountId, action.session); } - _handleStoreEmailStateToRefreshAction(action.newState); + _handleStoreEmailStateToRefreshAction(action.accountId, action.newState); } } } @@ -109,22 +109,22 @@ class EmailChangeListener extends ChangeListener { log('EmailChangeListener::_pushNotificationAction():newState: $newState'); if (BuildUtils.isWeb) { - _storeEmailDeliveryStateAction(_newStateEmailDelivery!); + _storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!); } else { if (Platform.isAndroid) { - _getStoredEmailDeliveryState(); + _getStoredEmailDeliveryState(accountId); } else if (Platform.isIOS) { - _storeEmailDeliveryStateAction(_newStateEmailDelivery!); - _showLocalNotificationForIOS(_newStateEmailDelivery!, _accountId!); + _storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!); + _showLocalNotificationForIOS(_newStateEmailDelivery!, accountId); } else { logError('EmailChangeListener::_pushNotificationAction(): NOT SUPPORTED PLATFORM'); } } } - void _getStoredEmailDeliveryState() { + void _getStoredEmailDeliveryState(AccountId accountId) { if (_getStoredEmailDeliveryStateInteractor != null) { - consumeState(_getStoredEmailDeliveryStateInteractor!.execute()); + consumeState(_getStoredEmailDeliveryStateInteractor!.execute(accountId)); } } @@ -148,9 +148,9 @@ class EmailChangeListener extends ChangeListener { } } - void _storeEmailDeliveryStateAction(jmap.State state) { + void _storeEmailDeliveryStateAction(AccountId accountId, jmap.State state) { if (_storeEmailDeliveryStateInteractor != null) { - consumeState(_storeEmailDeliveryStateInteractor!.execute(state)); + consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, state)); } } @@ -204,7 +204,7 @@ class EmailChangeListener extends ChangeListener { _getEmailChangesAction(success.state); } else if (success is GetEmailChangesToPushNotificationSuccess) { if (_newStateEmailDelivery != null) { - _storeEmailDeliveryStateAction(_newStateEmailDelivery!); + _storeEmailDeliveryStateAction(success.accountId, _newStateEmailDelivery!); if (FcmUtils.instance.isMobileAndroid) { _handleListEmailToPushNotification(success.emailList); @@ -244,10 +244,10 @@ class EmailChangeListener extends ChangeListener { _emailsAvailablePushNotification.clear(); } - void _handleStoreEmailStateToRefreshAction(jmap.State newState) { + void _handleStoreEmailStateToRefreshAction(AccountId accountId, jmap.State newState) { log('EmailChangeListener::_handleStoreEmailStateToRefreshAction():newState: $newState'); if (_storeEmailStateToRefreshInteractor != null) { - consumeState(_storeEmailStateToRefreshInteractor!.execute(newState)); + consumeState(_storeEmailStateToRefreshInteractor!.execute(accountId, newState)); } else { logError('EmailChangeListener::_handleStoreEmailStateToRefreshAction():_storeEmailStateToRefreshInteractor is null'); } diff --git a/lib/features/push_notification/presentation/listener/mailbox_change_listener.dart b/lib/features/push_notification/presentation/listener/mailbox_change_listener.dart index b0339906d..48e8257b2 100644 --- a/lib/features/push_notification/presentation/listener/mailbox_change_listener.dart +++ b/lib/features/push_notification/presentation/listener/mailbox_change_listener.dart @@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; import 'package:core/utils/app_logger.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap; import 'package:tmail_ui_user/features/base/action/ui_action.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/action/mailbox_ui_action.dart'; @@ -36,7 +37,7 @@ class MailboxChangeListener extends ChangeListener { if (action is SynchronizeMailboxOnForegroundAction) { _synchronizeMailboxOnForegroundAction(action.newState); } else if (action is StoreMailboxStateToRefreshAction) { - _handleStoreMailboxStateToRefreshAction(action.newState); + _handleStoreMailboxStateToRefreshAction(action.accountId, action.newState); } } } @@ -58,10 +59,10 @@ class MailboxChangeListener extends ChangeListener { } } - void _handleStoreMailboxStateToRefreshAction(jmap.State newState) { + void _handleStoreMailboxStateToRefreshAction(AccountId accountId, jmap.State newState) { log('MailboxChangeListener::_handleStoreMailboxStateToRefreshAction():newState: $newState'); if (_storeMailboxStateToRefreshInteractor != null) { - consumeState(_storeMailboxStateToRefreshInteractor!.execute(newState)); + consumeState(_storeMailboxStateToRefreshInteractor!.execute(accountId, newState)); } } } \ No newline at end of file diff --git a/lib/main/bindings/local/local_bindings.dart b/lib/main/bindings/local/local_bindings.dart index 514e9a4f6..e69b6b983 100644 --- a/lib/main/bindings/local/local_bindings.dart +++ b/lib/main/bindings/local/local_bindings.dart @@ -6,6 +6,7 @@ import 'package:tmail_ui_user/features/caching/authentication_info_cache_client. import 'package:tmail_ui_user/features/caching/caching_manager.dart'; import 'package:tmail_ui_user/features/caching/email_cache_client.dart'; import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart'; +import 'package:tmail_ui_user/features/caching/fcm_cache_client.dart'; import 'package:tmail_ui_user/features/caching/hive_cache_version_client.dart'; import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; import 'package:tmail_ui_user/features/caching/recent_login_url_cache_client.dart'; @@ -60,7 +61,8 @@ class LocalBindings extends Bindings { Get.put(RecentLoginUsernameCacheClient()); Get.put(RecentLoginUsernameCacheManager(Get.find())); Get.put(FCMSubscriptionCacheClient()); - Get.put(FCMCacheManager(Get.find(),Get.find())); + Get.put(FcmCacheClient()); + Get.put(FCMCacheManager(Get.find(),Get.find())); Get.put(HiveCacheVersionClient(Get.find(), Get.find())); Get.put(CachingManager( Get.find(), @@ -68,7 +70,7 @@ class LocalBindings extends Bindings { Get.find(), Get.find(), Get.find(), - Get.find(), + Get.find(), Get.find(), Get.find() ));