Get all mailbox cache by AccountId
(cherry picked from commit 8a7ccbf5d757ac9f1ffbd1fc5a1c863f30ab7b4c)
This commit is contained in:
@@ -22,7 +22,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_m
|
||||
abstract class MailboxDataSource {
|
||||
Future<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties});
|
||||
|
||||
Future<List<Mailbox>> getAllMailboxCache();
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId);
|
||||
|
||||
Future<MailboxChangeResponse> getChanges(Session session, AccountId accountId, State sinceState);
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Mailbox>> getAllMailboxCache() {
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||
return Future.sync(() async {
|
||||
final listMailboxes = await _mailboxCacheManager.getAllMailbox();
|
||||
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId);
|
||||
return listMailboxes;
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Mailbox>> getAllMailboxCache() {
|
||||
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
|
||||
|
||||
extension ListMailboxCacheExtension on List<MailboxCache> {
|
||||
List<Mailbox> toMailboxList() => map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/extensions/account_id_extensions.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_id_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_cache_extension.dart';
|
||||
@@ -14,10 +16,9 @@ class MailboxCacheManager {
|
||||
|
||||
MailboxCacheManager(this._mailboxCacheClient);
|
||||
|
||||
Future<List<Mailbox>> getAllMailbox() async {
|
||||
final mailboxCacheList = await _mailboxCacheClient.getAll();
|
||||
final mailboxList = mailboxCacheList.map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
||||
return mailboxList;
|
||||
Future<List<Mailbox>> getAllMailbox(AccountId accountId) async {
|
||||
final mailboxCacheList = await _mailboxCacheClient.getListByCollectionId(accountId.asString);
|
||||
return mailboxCacheList.toMailboxList();
|
||||
}
|
||||
|
||||
Future<void> update(
|
||||
|
||||
@@ -39,7 +39,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
@override
|
||||
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
|
||||
final localMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
@@ -83,7 +83,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
}
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
@@ -118,7 +118,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
|
||||
@override
|
||||
Stream<MailboxResponse> refresh(Session session, AccountId accountId, State currentState) async* {
|
||||
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache();
|
||||
final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
|
||||
|
||||
bool hasMoreChanges = true;
|
||||
State? sinceState = currentState;
|
||||
@@ -146,7 +146,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
||||
}
|
||||
|
||||
final newMailboxResponse = await Future.wait([
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||
stateDataSource.getState(StateType.mailbox)
|
||||
]).then((List response) {
|
||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||
|
||||
Reference in New Issue
Block a user