712bc26402
Signed-off-by: dab246 <tdvu@linagora.com>
34 lines
1.6 KiB
Dart
34 lines
1.6 KiB
Dart
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/clients/state_cache_client.dart';
|
|
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/data/extensions/state_cache_extension.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
|
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
|
|
|
class StateCacheManager {
|
|
|
|
final StateCacheClient _stateCacheClient;
|
|
|
|
StateCacheManager(this._stateCacheClient);
|
|
|
|
Future<State?> getState(AccountId accountId, UserName userName, StateType stateType) async {
|
|
final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey;
|
|
final stateCache = await _stateCacheClient.getItem(stateKey);
|
|
return stateCache?.toState();
|
|
}
|
|
|
|
Future<void> saveState(AccountId accountId, UserName userName, StateCache stateCache) async {
|
|
final stateKey = TupleKey(stateCache.type.name, accountId.asString, userName.value).encodeKey;
|
|
return await _stateCacheClient.insertItem(stateKey, stateCache);
|
|
}
|
|
|
|
Future<void> deleteState(AccountId accountId, UserName userName, StateType stateType) async {
|
|
final stateKey = TupleKey(stateType.name, accountId.asString, userName.value).encodeKey;
|
|
return await _stateCacheClient.deleteItem(stateKey);
|
|
}
|
|
|
|
Future<void> closeStateHiveCacheBox() => _stateCacheClient.closeBox();
|
|
} |