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
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/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';
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/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
@@ -40,16 +41,16 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
}
@override
Future<void> update(AccountId accountId, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
Future<void> update(AccountId accountId, UserName userName, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
return Future.sync(() async {
return await _mailboxCacheManager.update(accountId, updated: updated, created: created, destroyed: destroyed);
return await _mailboxCacheManager.update(accountId, userName, updated: updated, created: created, destroyed: destroyed);
}).catchError(_exceptionThrower.throwException);
}
@override
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId, UserName userName) {
return Future.sync(() async {
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId);
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId, userName);
return listMailboxes;
}).catchError(_exceptionThrower.throwException);
}
@@ -9,6 +9,7 @@ import 'package:jmap_dart_client/jmap/core/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';
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/mailbox/mailbox.dart';
import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart';
@@ -46,12 +47,12 @@ class MailboxDataSourceImpl extends MailboxDataSource {
}
@override
Future<void> update(AccountId accountId, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
Future<void> update(AccountId accountId, UserName userName, {List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
throw UnimplementedError();
}
@override
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId, UserName userName) {
throw UnimplementedError();
}
@@ -1,6 +1,7 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/state.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/state_cache_client.dart';
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
@@ -18,19 +19,19 @@ class StateDataSourceImpl extends StateDataSource {
StateDataSourceImpl(this._stateCacheClient, this._exceptionThrower);
@override
Future<State?> getState(AccountId accountId, StateType stateType) {
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) {
return Future.sync(() async {
final stateKey = TupleKey(stateType.value, accountId.asString).toString();
final stateKey = TupleKey(stateType.value, accountId.asString, userName.value).encodeKey;
final stateCache = await _stateCacheClient.getItem(stateKey);
return stateCache?.toState();
}).catchError(_exceptionThrower.throwException);
}
@override
Future<void> saveState(AccountId accountId, StateCache stateCache) {
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) {
return Future.sync(() async {
final stateCacheExist = await _stateCacheClient.isExistTable();
final stateKey = TupleKey(stateCache.type.value, accountId.asString).toString();
final stateKey = TupleKey(stateCache.type.value, accountId.asString, userName.value).encodeKey;
if (stateCacheExist) {
return await _stateCacheClient.updateItem(stateKey, stateCache);
} else {