Store and get fcm cache by AccountId

(cherry picked from commit e327dff45a4fc67d0c5a2d2afe64fc4673e2eac1)
This commit is contained in:
dab246
2023-04-25 18:15:02 +07:00
committed by Dat Vu
parent eb27022a08
commit 550752a2a4
23 changed files with 130 additions and 107 deletions
+21 -22
View File
@@ -1,15 +1,14 @@
import 'package:core/utils/app_logger.dart'; 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/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/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/hive_cache_version_client.dart';
import 'package:tmail_ui_user/features/caching/mailbox_cache_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/recent_search_cache_client.dart';
import 'package:tmail_ui_user/features/caching/state_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/caching/subscription_cache_client.dart';
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.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 { class CachingManager {
final MailboxCacheClient _mailboxCacheClient; final MailboxCacheClient _mailboxCacheClient;
@@ -17,7 +16,7 @@ class CachingManager {
final EmailCacheClient _emailCacheClient; final EmailCacheClient _emailCacheClient;
final RecentSearchCacheClient _recentSearchCacheClient; final RecentSearchCacheClient _recentSearchCacheClient;
final AccountCacheClient _accountCacheClient; final AccountCacheClient _accountCacheClient;
final FCMCacheManager _fcmCacheManager; final FcmCacheClient _fcmCacheClient;
final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient; final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient;
final HiveCacheVersionClient _hiveCacheVersionClient; final HiveCacheVersionClient _hiveCacheVersionClient;
@@ -27,7 +26,7 @@ class CachingManager {
this._emailCacheClient, this._emailCacheClient,
this._recentSearchCacheClient, this._recentSearchCacheClient,
this._accountCacheClient, this._accountCacheClient,
this._fcmCacheManager, this._fcmCacheClient,
this._fcmSubscriptionCacheClient, this._fcmSubscriptionCacheClient,
this._hiveCacheVersionClient, this._hiveCacheVersionClient,
); );
@@ -37,11 +36,22 @@ class CachingManager {
_stateCacheClient.clearAllData(), _stateCacheClient.clearAllData(),
_mailboxCacheClient.clearAllData(), _mailboxCacheClient.clearAllData(),
_emailCacheClient.clearAllData(), _emailCacheClient.clearAllData(),
_recentSearchCacheClient.clearAllData(), _fcmCacheClient.clearAllData(),
_accountCacheClient.clearAllData(),
_fcmSubscriptionCacheClient.clearAllData(), _fcmSubscriptionCacheClient.clearAllData(),
_fcmCacheManager.clearAllStateToRefresh() _recentSearchCacheClient.clearAllData(),
]); _accountCacheClient.clearAllData()
]);
}
Future<void> clearData() async {
await Future.wait([
_stateCacheClient.clearAllData(),
_mailboxCacheClient.clearAllData(),
_emailCacheClient.clearAllData(),
_fcmCacheClient.clearAllData(),
_fcmSubscriptionCacheClient.clearAllData(),
_recentSearchCacheClient.clearAllData()
]);
} }
Future<void> clearEmailCache() async { Future<void> clearEmailCache() async {
@@ -52,23 +62,12 @@ class CachingManager {
log('CachingManager::clearEmailCache(): success'); log('CachingManager::clearEmailCache(): success');
} }
Future<void> clearMailboxCache() async {
await Future.wait([
_stateCacheClient.deleteItem(StateType.mailbox.value),
_mailboxCacheClient.clearAllData(),
]);
log('CachingManager::clearMailboxCache(): success');
}
Future<void> onUpgradeCache(int oldVersion, int newVersion) async { Future<void> onUpgradeCache(int oldVersion, int newVersion) async {
log('CachingManager::onUpgradeCache():oldVersion $oldVersion | newVersion: $newVersion'); log('CachingManager::onUpgradeCache():oldVersion $oldVersion | newVersion: $newVersion');
if (oldVersion == 0 && newVersion >= 1) { if (oldVersion == 0 && newVersion >= 1) {
await Future.wait([ await clearData();
clearMailboxCache(),
clearEmailCache()
]);
} }
storeCacheVersion(newVersion); await storeCacheVersion(newVersion);
return Future.value(); return Future.value();
} }
@@ -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<String> {
@override
String get tableName => CachingConstants.fcmCacheBoxName;
}
@@ -14,4 +14,6 @@ class CachingConstants {
static const int RECENT_LOGIN_URL_HIVE_CACHE_IDENTITY = 12; static const int RECENT_LOGIN_URL_HIVE_CACHE_IDENTITY = 12;
static const int RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY = 13; static const int RECENT_LOGIN_USERNAME_HIVE_CACHE_IDENTITY = 13;
static const int FCM_SUBSCRIPTION_HIVE_CACHE_IDENTITY = 14; static const int FCM_SUBSCRIPTION_HIVE_CACHE_IDENTITY = 14;
static const String fcmCacheBoxName = 'fcm_cache_box';
} }
@@ -1428,11 +1428,11 @@ class MailboxDashBoardController extends ReloadableController {
} catch (e) { } catch (e) {
logError('MailboxDashBoardController::_handleRefreshActionWhenBackToApp(): $e'); logError('MailboxDashBoardController::_handleRefreshActionWhenBackToApp(): $e');
} }
if (_getEmailStateToRefreshInteractor != null) { if (_getEmailStateToRefreshInteractor != null && accountId.value != null) {
consumeState(_getEmailStateToRefreshInteractor!.execute()); consumeState(_getEmailStateToRefreshInteractor!.execute(accountId.value!));
} }
if (_getMailboxStateToRefreshInteractor != null) { if (_getMailboxStateToRefreshInteractor != null && accountId.value != null) {
consumeState(_getMailboxStateToRefreshInteractor!.execute()); consumeState(_getMailboxStateToRefreshInteractor!.execute(accountId.value!));
} }
} }
@@ -1443,8 +1443,8 @@ class MailboxDashBoardController extends ReloadableController {
} catch (e) { } catch (e) {
logError('MailboxDashBoardController::_deleteEmailStateToRefreshAction(): $e'); logError('MailboxDashBoardController::_deleteEmailStateToRefreshAction(): $e');
} }
if (_deleteEmailStateToRefreshInteractor != null) { if (_deleteEmailStateToRefreshInteractor != null && accountId.value != null) {
consumeState(_deleteEmailStateToRefreshInteractor!.execute()); consumeState(_deleteEmailStateToRefreshInteractor!.execute(accountId.value!));
} }
} }
@@ -1455,8 +1455,8 @@ class MailboxDashBoardController extends ReloadableController {
} catch (e) { } catch (e) {
logError('MailboxDashBoardController::_deleteMailboxStateToRefreshAction(): $e'); logError('MailboxDashBoardController::_deleteMailboxStateToRefreshAction(): $e');
} }
if (_deleteMailboxStateToRefreshInteractor != null) { if (_deleteMailboxStateToRefreshInteractor != null && accountId.value != null) {
consumeState(_deleteMailboxStateToRefreshInteractor!.execute()); consumeState(_deleteMailboxStateToRefreshInteractor!.execute(accountId.value!));
} }
} }
@@ -1,16 +1,17 @@
import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/firebase_subscription.dart';
import 'package:fcm/model/type_name.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: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/data/model/fcm_subscription.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart'; import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
abstract class FCMDatasource { abstract class FCMDatasource {
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState); Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState);
Future<jmap.State> getStateToRefresh(TypeName typeName); Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName);
Future<bool> deleteStateToRefresh(TypeName typeName); Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName);
Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache); Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache);
@@ -1,5 +1,6 @@
import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/firebase_subscription.dart';
import 'package:fcm/model/type_name.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: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/datasource/fcm_datasource.dart';
import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.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); CacheFCMDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower);
@override @override
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState) { Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
return Future.sync(() async { return Future.sync(() async {
return await _firebaseCacheManager.storeStateToRefresh(typeName, newState); return await _firebaseCacheManager.storeStateToRefresh(accountId, typeName, newState);
}).catchError(_exceptionThrower.throwException); }).catchError(_exceptionThrower.throwException);
} }
@override @override
Future<jmap.State> getStateToRefresh(TypeName typeName) { Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
return Future.sync(() async { return Future.sync(() async {
return await _firebaseCacheManager.getStateToRefresh(typeName); return await _firebaseCacheManager.getStateToRefresh(accountId, typeName);
}).catchError(_exceptionThrower.throwException); }).catchError(_exceptionThrower.throwException);
} }
@override @override
Future<bool> deleteStateToRefresh(TypeName typeName) { Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
return Future.sync(() async { return Future.sync(() async {
return await _firebaseCacheManager.deleteStateToRefresh(typeName); return await _firebaseCacheManager.deleteStateToRefresh(accountId, typeName);
}).catchError(_exceptionThrower.throwException); }).catchError(_exceptionThrower.throwException);
} }
@@ -1,5 +1,6 @@
import 'package:fcm/model/firebase_subscription.dart'; import 'package:fcm/model/firebase_subscription.dart';
import 'package:fcm/model/type_name.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: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/datasource/fcm_datasource.dart';
import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart'; import 'package:tmail_ui_user/features/push_notification/data/model/fcm_subscription.dart';
@@ -23,17 +24,17 @@ class FcmDatasourceImpl extends FCMDatasource {
} }
@override @override
Future<bool> deleteStateToRefresh(TypeName typeName) { Future<bool> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
Future<jmap.State> getStateToRefresh(TypeName typeName) { Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
throw UnimplementedError(); throw UnimplementedError();
} }
@override @override
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState) { Future<bool> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
throw UnimplementedError(); throw UnimplementedError();
} }
@@ -1,27 +1,27 @@
import 'package:core/utils/app_logger.dart';
import 'package:fcm/model/type_name.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/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/data/model/fcm_subscription.dart';
import 'package:tmail_ui_user/features/push_notification/domain/exceptions/fcm_exception.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; import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
class FCMCacheManager { class FCMCacheManager {
final SharedPreferences _sharedPreferences; final FcmCacheClient _fcmCacheClient;
final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient; final FCMSubscriptionCacheClient _fcmSubscriptionCacheClient;
FCMCacheManager(this._fcmCacheClient,this._fcmSubscriptionCacheClient);
FCMCacheManager(this._sharedPreferences,this._fcmSubscriptionCacheClient); Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState) { return _fcmCacheClient.insertItem(stateKeyCache, newState.value);
return _sharedPreferences.setString(typeName.value, newState.value);
} }
Future<jmap.State> getStateToRefresh(TypeName typeName) async { Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) async {
log('FCMCacheManager::getStoredFcmStateChange():keys_BEFORE: ${_sharedPreferences.getKeys().toString()}'); final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
await _sharedPreferences.reload(); final stateValue = await _fcmCacheClient.getItem(stateKeyCache);
log('FCMCacheManager::getStoredFcmStateChange():keys_AFTER: ${_sharedPreferences.getKeys().toString()}');
final stateValue = _sharedPreferences.getString(typeName.value);
if (stateValue != null) { if (stateValue != null) {
return jmap.State(stateValue); return jmap.State(stateValue);
} else { } else {
@@ -33,16 +33,13 @@ class FCMCacheManager {
} }
} }
Future<bool> deleteStateToRefresh(TypeName typeName) { Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
return _sharedPreferences.remove(typeName.value); final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
return _fcmCacheClient.deleteItem(stateKeyCache);
} }
Future<bool> clearAllStateToRefresh() async { Future<void> clearAllStateToRefresh() async {
return await Future.wait([ return _fcmCacheClient.clearAllData();
_sharedPreferences.remove(TypeName.emailType.value),
_sharedPreferences.remove(TypeName.mailboxType.value),
_sharedPreferences.remove(TypeName.emailDelivery.value),
]).then((listResult) => listResult.every((result) => result));
} }
Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache) { Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache) {
@@ -75,18 +75,18 @@ class FCMRepositoryImpl extends FCMRepository {
} }
@override @override
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState) { Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(typeName, newState); return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, typeName, newState);
} }
@override @override
Future<jmap.State> getStateToRefresh(TypeName typeName) { Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(typeName); return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, typeName);
} }
@override @override
Future<bool> deleteStateToRefresh(TypeName typeName) { Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(typeName); return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, typeName);
} }
@override @override
@@ -21,11 +21,11 @@ abstract class FCMRepository {
} }
); );
Future<bool> storeStateToRefresh(TypeName typeName, jmap.State newState); Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState);
Future<jmap.State> getStateToRefresh(TypeName typeName); Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName);
Future<bool> deleteStateToRefresh(TypeName typeName); Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName);
Future<void> storeSubscription(FCMSubscription fcmSubscription); Future<void> storeSubscription(FCMSubscription fcmSubscription);
@@ -1,6 +1,7 @@
import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/email/presentation_email.dart'; import 'package:model/email/presentation_email.dart';
class GetEmailChangesToPushNotificationLoading extends UIState {} class GetEmailChangesToPushNotificationLoading extends UIState {}
@@ -8,11 +9,12 @@ class GetEmailChangesToPushNotificationLoading extends UIState {}
class GetEmailChangesToPushNotificationSuccess extends UIState { class GetEmailChangesToPushNotificationSuccess extends UIState {
final List<PresentationEmail> emailList; final List<PresentationEmail> emailList;
final AccountId accountId;
GetEmailChangesToPushNotificationSuccess(this.emailList); GetEmailChangesToPushNotificationSuccess(this.accountId, this.emailList);
@override @override
List<Object> get props => [emailList]; List<Object> get props => [accountId, emailList];
} }
class GetEmailChangesToPushNotificationFailure extends FeatureFailure { class GetEmailChangesToPushNotificationFailure extends FeatureFailure {
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_email_state_to_refresh_state.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); DeleteEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* { Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try { try {
yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading()); yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(TypeName.emailType); await _fcmRepository.deleteStateToRefresh(accountId, TypeName.emailType);
yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess()); yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess());
} catch (e) { } catch (e) {
yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e)); yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_mailbox_state_to_refresh_state.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); DeleteMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* { Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try { try {
yield Right<Failure, Success>(DeleteMailboxStateToRefreshLoading()); yield Right<Failure, Success>(DeleteMailboxStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(TypeName.mailboxType); await _fcmRepository.deleteStateToRefresh(accountId, TypeName.mailboxType);
yield Right<Failure, Success>(DeleteMailboxStateToRefreshSuccess()); yield Right<Failure, Success>(DeleteMailboxStateToRefreshSuccess());
} catch (e) { } catch (e) {
yield Left<Failure, Success>(DeleteMailboxStateToRefreshFailure(e)); yield Left<Failure, Success>(DeleteMailboxStateToRefreshFailure(e));
@@ -37,7 +37,7 @@ class GetEmailChangesToPushNotificationInteractor {
?.map((email) => email.toPresentationEmail()) ?.map((email) => email.toPresentationEmail())
.toList() ?? List.empty(); .toList() ?? List.empty();
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(presentationEmailList)); yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, presentationEmailList));
} catch (e) { } catch (e) {
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e)); yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e));
} }
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.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); GetEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* { Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try { try {
yield Right<Failure, Success>(GetEmailStateToRefreshLoading()); yield Right<Failure, Success>(GetEmailStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailType); final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailType);
yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState)); yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState));
} catch (e) { } catch (e) {
yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e)); yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.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); GetMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* { Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try { try {
yield Right<Failure, Success>(GetMailboxStateToRefreshLoading()); yield Right<Failure, Success>(GetMailboxStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(TypeName.mailboxType); final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.mailboxType);
yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState)); yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState));
} catch (e) { } catch (e) {
yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e)); yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_stored_email_delivery_state.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); GetStoredEmailDeliveryStateInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute() async* { Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
try { try {
yield Right<Failure, Success>(GetStoredEmailDeliveryStateLoading()); yield Right<Failure, Success>(GetStoredEmailDeliveryStateLoading());
final storedState = await _fcmRepository.getStateToRefresh(TypeName.emailDelivery); final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailDelivery);
yield Right<Failure, Success>(GetStoredEmailDeliveryStateSuccess(storedState)); yield Right<Failure, Success>(GetStoredEmailDeliveryStateSuccess(storedState));
} catch (e) { } catch (e) {
yield Left<Failure, Success>(GetStoredEmailDeliveryStateFailure(e)); yield Left<Failure, Success>(GetStoredEmailDeliveryStateFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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: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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_delivery_state.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); StoreEmailDeliveryStateInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(jmap.State newState) async* { Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
try { try {
yield Right<Failure, Success>(StoreEmailDeliveryStateLoading()); yield Right<Failure, Success>(StoreEmailDeliveryStateLoading());
await _fcmRepository.storeStateToRefresh(TypeName.emailDelivery, newState); await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailDelivery, newState);
yield Right<Failure, Success>(StoreEmailDeliveryStateSuccess()); yield Right<Failure, Success>(StoreEmailDeliveryStateSuccess());
} catch (e) { } catch (e) {
yield Left<Failure, Success>(StoreEmailDeliveryStateFailure(e)); yield Left<Failure, Success>(StoreEmailDeliveryStateFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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: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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_state_to_refresh_state.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); StoreEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(jmap.State newState) async* { Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
try { try {
yield Right<Failure, Success>(StoreEmailStateToRefreshLoading()); yield Right<Failure, Success>(StoreEmailStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(TypeName.emailType, newState); await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailType, newState);
yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess()); yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess());
} catch (e) { } catch (e) {
yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e)); yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e));
@@ -2,6 +2,7 @@ import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.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: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/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_mailbox_state_to_refresh_state.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); StoreMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(jmap.State newState) async* { Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
try { try {
yield Right<Failure, Success>(StoreMailboxStateToRefreshLoading()); yield Right<Failure, Success>(StoreMailboxStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(TypeName.mailboxType, newState); await _fcmRepository.storeStateToRefresh(accountId, TypeName.mailboxType, newState);
yield Right<Failure, Success>(StoreMailboxStateToRefreshSuccess()); yield Right<Failure, Success>(StoreMailboxStateToRefreshSuccess());
} catch (e) { } catch (e) {
yield Left<Failure, Success>(StoreMailboxStateToRefreshFailure(e)); yield Left<Failure, Success>(StoreMailboxStateToRefreshFailure(e));
@@ -90,7 +90,7 @@ class EmailChangeListener extends ChangeListener {
if (FcmUtils.instance.isMobileAndroid) { if (FcmUtils.instance.isMobileAndroid) {
_handleRemoveNotificationWhenEmailMarkAsRead(action.newState, action.accountId, action.session); _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'); log('EmailChangeListener::_pushNotificationAction():newState: $newState');
if (BuildUtils.isWeb) { if (BuildUtils.isWeb) {
_storeEmailDeliveryStateAction(_newStateEmailDelivery!); _storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!);
} else { } else {
if (Platform.isAndroid) { if (Platform.isAndroid) {
_getStoredEmailDeliveryState(); _getStoredEmailDeliveryState(accountId);
} else if (Platform.isIOS) { } else if (Platform.isIOS) {
_storeEmailDeliveryStateAction(_newStateEmailDelivery!); _storeEmailDeliveryStateAction(accountId, _newStateEmailDelivery!);
_showLocalNotificationForIOS(_newStateEmailDelivery!, _accountId!); _showLocalNotificationForIOS(_newStateEmailDelivery!, accountId);
} else { } else {
logError('EmailChangeListener::_pushNotificationAction(): NOT SUPPORTED PLATFORM'); logError('EmailChangeListener::_pushNotificationAction(): NOT SUPPORTED PLATFORM');
} }
} }
} }
void _getStoredEmailDeliveryState() { void _getStoredEmailDeliveryState(AccountId accountId) {
if (_getStoredEmailDeliveryStateInteractor != null) { 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) { if (_storeEmailDeliveryStateInteractor != null) {
consumeState(_storeEmailDeliveryStateInteractor!.execute(state)); consumeState(_storeEmailDeliveryStateInteractor!.execute(accountId, state));
} }
} }
@@ -204,7 +204,7 @@ class EmailChangeListener extends ChangeListener {
_getEmailChangesAction(success.state); _getEmailChangesAction(success.state);
} else if (success is GetEmailChangesToPushNotificationSuccess) { } else if (success is GetEmailChangesToPushNotificationSuccess) {
if (_newStateEmailDelivery != null) { if (_newStateEmailDelivery != null) {
_storeEmailDeliveryStateAction(_newStateEmailDelivery!); _storeEmailDeliveryStateAction(success.accountId, _newStateEmailDelivery!);
if (FcmUtils.instance.isMobileAndroid) { if (FcmUtils.instance.isMobileAndroid) {
_handleListEmailToPushNotification(success.emailList); _handleListEmailToPushNotification(success.emailList);
@@ -244,10 +244,10 @@ class EmailChangeListener extends ChangeListener {
_emailsAvailablePushNotification.clear(); _emailsAvailablePushNotification.clear();
} }
void _handleStoreEmailStateToRefreshAction(jmap.State newState) { void _handleStoreEmailStateToRefreshAction(AccountId accountId, jmap.State newState) {
log('EmailChangeListener::_handleStoreEmailStateToRefreshAction():newState: $newState'); log('EmailChangeListener::_handleStoreEmailStateToRefreshAction():newState: $newState');
if (_storeEmailStateToRefreshInteractor != null) { if (_storeEmailStateToRefreshInteractor != null) {
consumeState(_storeEmailStateToRefreshInteractor!.execute(newState)); consumeState(_storeEmailStateToRefreshInteractor!.execute(accountId, newState));
} else { } else {
logError('EmailChangeListener::_handleStoreEmailStateToRefreshAction():_storeEmailStateToRefreshInteractor is null'); logError('EmailChangeListener::_handleStoreEmailStateToRefreshAction():_storeEmailStateToRefreshInteractor is null');
} }
@@ -2,6 +2,7 @@
import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart'; import 'package:core/presentation/state/success.dart';
import 'package:core/utils/app_logger.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: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/base/action/ui_action.dart';
import 'package:tmail_ui_user/features/mailbox/presentation/action/mailbox_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) { if (action is SynchronizeMailboxOnForegroundAction) {
_synchronizeMailboxOnForegroundAction(action.newState); _synchronizeMailboxOnForegroundAction(action.newState);
} else if (action is StoreMailboxStateToRefreshAction) { } 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'); log('MailboxChangeListener::_handleStoreMailboxStateToRefreshAction():newState: $newState');
if (_storeMailboxStateToRefreshInteractor != null) { if (_storeMailboxStateToRefreshInteractor != null) {
consumeState(_storeMailboxStateToRefreshInteractor!.execute(newState)); consumeState(_storeMailboxStateToRefreshInteractor!.execute(accountId, newState));
} }
} }
} }
+4 -2
View File
@@ -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/caching_manager.dart';
import 'package:tmail_ui_user/features/caching/email_cache_client.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/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/hive_cache_version_client.dart';
import 'package:tmail_ui_user/features/caching/mailbox_cache_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'; 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(RecentLoginUsernameCacheClient());
Get.put(RecentLoginUsernameCacheManager(Get.find<RecentLoginUsernameCacheClient>())); Get.put(RecentLoginUsernameCacheManager(Get.find<RecentLoginUsernameCacheClient>()));
Get.put(FCMSubscriptionCacheClient()); Get.put(FCMSubscriptionCacheClient());
Get.put(FCMCacheManager(Get.find<SharedPreferences>(),Get.find<FCMSubscriptionCacheClient>())); Get.put(FcmCacheClient());
Get.put(FCMCacheManager(Get.find<FcmCacheClient>(),Get.find<FCMSubscriptionCacheClient>()));
Get.put(HiveCacheVersionClient(Get.find<SharedPreferences>(), Get.find<CacheExceptionThrower>())); Get.put(HiveCacheVersionClient(Get.find<SharedPreferences>(), Get.find<CacheExceptionThrower>()));
Get.put(CachingManager( Get.put(CachingManager(
Get.find<MailboxCacheClient>(), Get.find<MailboxCacheClient>(),
@@ -68,7 +70,7 @@ class LocalBindings extends Bindings {
Get.find<EmailCacheClient>(), Get.find<EmailCacheClient>(),
Get.find<RecentSearchCacheClient>(), Get.find<RecentSearchCacheClient>(),
Get.find<AccountCacheClient>(), Get.find<AccountCacheClient>(),
Get.find<FCMCacheManager>(), Get.find<FcmCacheClient>(),
Get.find<FCMSubscriptionCacheClient>(), Get.find<FCMSubscriptionCacheClient>(),
Get.find<HiveCacheVersionClient>() Get.find<HiveCacheVersionClient>()
)); ));