Store state cache by AccountId
(cherry picked from commit cb8d44d31360986b1c87694681166e83fc78a666)
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.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';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.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';
|
||||
@@ -23,13 +26,14 @@ class StateDataSourceImpl extends StateDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveState(StateCache stateCache) {
|
||||
Future<void> saveState(AccountId accountId, StateCache stateCache) {
|
||||
return Future.sync(() async {
|
||||
final stateCacheExist = await _stateCacheClient.isExistTable();
|
||||
final stateKey = TupleKey(stateCache.type.value, accountId.asString).toString();
|
||||
if (stateCacheExist) {
|
||||
return await _stateCacheClient.updateItem(stateCache.type.value, stateCache);
|
||||
return await _stateCacheClient.updateItem(stateKey, stateCache);
|
||||
} else {
|
||||
return await _stateCacheClient.insertItem(stateCache.type.value, stateCache);
|
||||
return await _stateCacheClient.insertItem(stateKey, stateCache);
|
||||
}
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user