Use TupleKey(ObjectKey-AccountId-UserName) to store data to hive

(cherry picked from commit e0ace535d5f3af71eb13598d92524caf2c6d9bbf)
This commit is contained in:
dab246
2023-04-27 11:03:39 +07:00
committed by Dat Vu
parent 7d0a5729b2
commit 876cc368b0
107 changed files with 562 additions and 340 deletions
@@ -3,6 +3,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:model/mailbox/presentation_mailbox.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/fcm_subscription.dart';
@@ -21,11 +22,11 @@ abstract class FCMRepository {
}
);
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(FCMSubscription fcmSubscription);
@@ -2,6 +2,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:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/email/presentation_email.dart';
class GetEmailChangesToPushNotificationLoading extends UIState {}
@@ -10,11 +11,12 @@ class GetEmailChangesToPushNotificationSuccess extends UIState {
final List<PresentationEmail> emailList;
final AccountId accountId;
final UserName userName;
GetEmailChangesToPushNotificationSuccess(this.accountId, this.emailList);
GetEmailChangesToPushNotificationSuccess(this.accountId, this.userName, this.emailList);
@override
List<Object> get props => [accountId, emailList];
List<Object> get props => [accountId, userName, emailList];
}
class GetEmailChangesToPushNotificationFailure extends FeatureFailure {
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_email_state_to_refresh_state.dart';
@@ -11,10 +12,10 @@ class DeleteEmailStateToRefreshInteractor {
DeleteEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(DeleteEmailStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(accountId, TypeName.emailType);
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.emailType);
yield Right<Failure, Success>(DeleteEmailStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(DeleteEmailStateToRefreshFailure(e));
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/delete_mailbox_state_to_refresh_state.dart';
@@ -11,10 +12,10 @@ class DeleteMailboxStateToRefreshInteractor {
DeleteMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(DeleteMailboxStateToRefreshLoading());
await _fcmRepository.deleteStateToRefresh(accountId, TypeName.mailboxType);
await _fcmRepository.deleteStateToRefresh(accountId, userName, TypeName.mailboxType);
yield Right<Failure, Success>(DeleteMailboxStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(DeleteMailboxStateToRefreshFailure(e));
@@ -5,6 +5,7 @@ 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/state.dart' as jmap;
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/extensions/email_extension.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_changes_to_push_notification_state.dart';
@@ -17,6 +18,7 @@ class GetEmailChangesToPushNotificationInteractor {
Stream<Either<Failure, Success>> execute(
Session session,
AccountId accountId,
UserName userName,
jmap.State currentState,
{
Properties? propertiesCreated,
@@ -37,7 +39,7 @@ class GetEmailChangesToPushNotificationInteractor {
?.map((email) => email.toPresentationEmail())
.toList() ?? List.empty();
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, presentationEmailList));
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, userName, presentationEmailList));
} catch (e) {
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e));
}
@@ -29,7 +29,7 @@ class GetEmailChangesToRemoveNotificationInteractor {
try {
yield Right<Failure, Success>(GetEmailChangesToRemoveNotificationLoading());
final currentState = await _emailRepository.getEmailState(accountId);
final currentState = await _emailRepository.getEmailState(session, accountId);
log('GetEmailChangesToRemoveNotificationInteractor::execute():currentState: $currentState');
if (currentState != null) {
final emailIds = await _fcmRepository.getEmailChangesToRemoveNotification(
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_email_state_to_refresh_state.dart';
@@ -11,10 +12,10 @@ class GetEmailStateToRefreshInteractor {
GetEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(GetEmailStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailType);
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.emailType);
yield Right<Failure, Success>(GetEmailStateToRefreshSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetEmailStateToRefreshFailure(e));
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailbox_state_to_refresh_state.dart';
@@ -11,10 +12,10 @@ class GetMailboxStateToRefreshInteractor {
GetMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(GetMailboxStateToRefreshLoading());
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.mailboxType);
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.mailboxType);
yield Right<Failure, Success>(GetMailboxStateToRefreshSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetMailboxStateToRefreshFailure(e));
@@ -3,6 +3,7 @@ import 'package:core/presentation/state/success.dart';
import 'package:dartz/dartz.dart';
import 'package:fcm/model/type_name.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/get_stored_email_delivery_state.dart';
@@ -11,10 +12,10 @@ class GetStoredEmailDeliveryStateInteractor {
GetStoredEmailDeliveryStateInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName) async* {
try {
yield Right<Failure, Success>(GetStoredEmailDeliveryStateLoading());
final storedState = await _fcmRepository.getStateToRefresh(accountId, TypeName.emailDelivery);
final storedState = await _fcmRepository.getStateToRefresh(accountId, userName, TypeName.emailDelivery);
yield Right<Failure, Success>(GetStoredEmailDeliveryStateSuccess(storedState));
} catch (e) {
yield Left<Failure, Success>(GetStoredEmailDeliveryStateFailure(e));
@@ -4,6 +4,7 @@ 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:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_delivery_state.dart';
@@ -12,10 +13,10 @@ class StoreEmailDeliveryStateInteractor {
StoreEmailDeliveryStateInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
try {
yield Right<Failure, Success>(StoreEmailDeliveryStateLoading());
await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailDelivery, newState);
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.emailDelivery, newState);
yield Right<Failure, Success>(StoreEmailDeliveryStateSuccess());
} catch (e) {
yield Left<Failure, Success>(StoreEmailDeliveryStateFailure(e));
@@ -4,6 +4,7 @@ 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:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_email_state_to_refresh_state.dart';
@@ -12,10 +13,10 @@ class StoreEmailStateToRefreshInteractor {
StoreEmailStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
try {
yield Right<Failure, Success>(StoreEmailStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(accountId, TypeName.emailType, newState);
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.emailType, newState);
yield Right<Failure, Success>(StoreEmailStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(StoreEmailStateToRefreshFailure(e));
@@ -4,6 +4,7 @@ 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:jmap_dart_client/jmap/core/user_name.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/state/store_mailbox_state_to_refresh_state.dart';
@@ -12,10 +13,10 @@ class StoreMailboxStateToRefreshInteractor {
StoreMailboxStateToRefreshInteractor(this._fcmRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, jmap.State newState) async* {
Stream<Either<Failure, Success>> execute(AccountId accountId, UserName userName, jmap.State newState) async* {
try {
yield Right<Failure, Success>(StoreMailboxStateToRefreshLoading());
await _fcmRepository.storeStateToRefresh(accountId, TypeName.mailboxType, newState);
await _fcmRepository.storeStateToRefresh(accountId, userName, TypeName.mailboxType, newState);
yield Right<Failure, Success>(StoreMailboxStateToRefreshSuccess());
} catch (e) {
yield Left<Failure, Success>(StoreMailboxStateToRefreshFailure(e));