Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive
(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
@@ -3,15 +3,16 @@ 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:jmap_dart_client/jmap/core/user_name.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';
|
||||
|
||||
abstract class FCMDatasource {
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState);
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState);
|
||||
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName);
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName);
|
||||
|
||||
Future<void> storeSubscription(FCMSubscriptionCache fcmSubscriptionCache);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ 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:jmap_dart_client/jmap/core/user_name.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/model/fcm_subscription.dart';
|
||||
@@ -16,23 +17,23 @@ class CacheFCMDatasourceImpl extends FCMDatasource {
|
||||
CacheFCMDatasourceImpl(this._firebaseCacheManager, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.storeStateToRefresh(accountId, typeName, newState);
|
||||
return await _firebaseCacheManager.storeStateToRefresh(accountId, userName, typeName, newState);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId,UserName userName, TypeName typeName) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.getStateToRefresh(accountId, typeName);
|
||||
return await _firebaseCacheManager.getStateToRefresh(accountId, userName, typeName);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return Future.sync(() async {
|
||||
return await _firebaseCacheManager.deleteStateToRefresh(accountId, typeName);
|
||||
return await _firebaseCacheManager.deleteStateToRefresh(accountId, userName, typeName);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ 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:jmap_dart_client/jmap/core/user_name.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/network/fcm_api.dart';
|
||||
@@ -24,17 +25,17 @@ class FcmDatasourceImpl extends FCMDatasource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<bool> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
Future<bool> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
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: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';
|
||||
@@ -14,13 +15,13 @@ class FCMCacheManager {
|
||||
|
||||
FCMCacheManager(this._fcmCacheClient,this._fcmSubscriptionCacheClient);
|
||||
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
return _fcmCacheClient.insertItem(stateKeyCache, newState.value);
|
||||
}
|
||||
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) async {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) async {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
final stateValue = await _fcmCacheClient.getItem(stateKeyCache);
|
||||
if (stateValue != null) {
|
||||
return jmap.State(stateValue);
|
||||
@@ -33,8 +34,8 @@ class FCMCacheManager {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString).toString();
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
final stateKeyCache = TupleKey(typeName.value, accountId.asString, userName.value).encodeKey;
|
||||
return _fcmCacheClient.deleteItem(stateKeyCache);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:fcm/model/type_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/properties/properties.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/extensions/list_email_extension.dart';
|
||||
@@ -75,18 +76,18 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> storeStateToRefresh(AccountId accountId, TypeName typeName, jmap.State newState) {
|
||||
return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, typeName, newState);
|
||||
Future<void> storeStateToRefresh(AccountId accountId, UserName userName, TypeName typeName, jmap.State newState) {
|
||||
return _fcmDatasource[DataSourceType.local]!.storeStateToRefresh(accountId, userName, typeName, newState);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, typeName);
|
||||
Future<jmap.State> getStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.getStateToRefresh(accountId, userName, typeName);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, typeName);
|
||||
Future<void> deleteStateToRefresh(AccountId accountId, UserName userName, TypeName typeName) {
|
||||
return _fcmDatasource[DataSourceType.local]!.deleteStateToRefresh(accountId, userName, typeName);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -117,7 +118,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
@override
|
||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId) async {
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username);
|
||||
final mailboxesCacheNotPutNotifications = mailboxesCache
|
||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||
|
||||
Reference in New Issue
Block a user