Get state cache by AccountId
(cherry picked from commit 9bb1de613ca58e5a7cb66fbc97ecd308754d088b)
This commit is contained in:
@@ -4,7 +4,7 @@ import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart';
|
||||
|
||||
abstract class StateDataSource {
|
||||
Future<State?> getState(StateType stateType);
|
||||
Future<State?> getState(AccountId accountId, StateType stateType);
|
||||
|
||||
Future<void> saveState(AccountId accountId, StateCache stateCache);
|
||||
}
|
||||
@@ -18,9 +18,10 @@ class StateDataSourceImpl extends StateDataSource {
|
||||
StateDataSourceImpl(this._stateCacheClient, this._exceptionThrower);
|
||||
|
||||
@override
|
||||
Future<State?> getState(StateType stateType) {
|
||||
Future<State?> getState(AccountId accountId, StateType stateType) {
|
||||
return Future.sync(() async {
|
||||
final stateCache = await _stateCacheClient.getItem(stateType.value);
|
||||
final stateKey = TupleKey(stateType.value, accountId.asString).toString();
|
||||
final stateCache = await _stateCacheClient.getItem(stateKey);
|
||||
return stateCache?.toState();
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
|
||||
final localMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -84,7 +84,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -147,7 +147,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
stateDataSource.getState(accountId, StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
});
|
||||
@@ -191,8 +191,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<State?> getMailboxState() {
|
||||
return stateDataSource.getState(StateType.mailbox);
|
||||
Future<State?> getMailboxState(AccountId accountId) {
|
||||
return stateDataSource.getState(accountId, StateType.mailbox);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user