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
@@ -39,8 +39,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
@override
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
final localMailboxResponse = await Future.wait([
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
stateDataSource.getState(accountId, StateType.mailbox)
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
stateDataSource.getState(accountId, session.username, StateType.mailbox)
]).then((List response) {
return MailboxResponse(mailboxes: response.first, state: response.last);
});
@@ -65,26 +65,27 @@ class MailboxRepositoryImpl extends MailboxRepository {
await Future.wait([
mapDataSource[DataSourceType.local]!.update(
accountId,
session.username,
updated: newMailboxUpdated,
created: changesResponse.created,
destroyed: changesResponse.destroyed),
if (changesResponse.newStateMailbox != null)
stateDataSource.saveState(accountId, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
stateDataSource.saveState(accountId, session.username, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
]);
}
} else {
final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(session, accountId);
await Future.wait([
mapDataSource[DataSourceType.local]!.update(accountId, created: mailboxResponse.mailboxes),
mapDataSource[DataSourceType.local]!.update(accountId, session.username, created: mailboxResponse.mailboxes),
if (mailboxResponse.state != null)
stateDataSource.saveState(accountId, mailboxResponse.state!.toStateCache(StateType.mailbox)),
stateDataSource.saveState(accountId, session.username, mailboxResponse.state!.toStateCache(StateType.mailbox)),
]);
}
final newMailboxResponse = await Future.wait([
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
stateDataSource.getState(accountId, StateType.mailbox)
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
stateDataSource.getState(accountId, session.username, StateType.mailbox)
]).then((List response) {
return MailboxResponse(mailboxes: response.first, state: response.last);
});
@@ -118,7 +119,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
@override
Stream<MailboxResponse> refresh(Session session, AccountId accountId, State currentState) async* {
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username);
bool hasMoreChanges = true;
State? sinceState = currentState;
@@ -137,17 +138,18 @@ class MailboxRepositoryImpl extends MailboxRepository {
await Future.wait([
mapDataSource[DataSourceType.local]!.update(
accountId,
session.username,
updated: newMailboxUpdated,
created: changesResponse.created,
destroyed: changesResponse.destroyed),
if (changesResponse.newStateMailbox != null)
stateDataSource.saveState(accountId, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
stateDataSource.saveState(accountId, session.username, changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)),
]);
}
final newMailboxResponse = await Future.wait([
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
stateDataSource.getState(accountId, StateType.mailbox)
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId, session.username),
stateDataSource.getState(accountId, session.username, StateType.mailbox)
]).then((List response) {
return MailboxResponse(mailboxes: response.first, state: response.last);
});
@@ -191,8 +193,8 @@ class MailboxRepositoryImpl extends MailboxRepository {
}
@override
Future<State?> getMailboxState(AccountId accountId) {
return stateDataSource.getState(accountId, StateType.mailbox);
Future<State?> getMailboxState(Session session, AccountId accountId) {
return stateDataSource.getState(accountId, session.username, StateType.mailbox);
}
@override