Get all mailbox cache by AccountId
(cherry picked from commit 8a7ccbf5d757ac9f1ffbd1fc5a1c863f30ab7b4c)
This commit is contained in:
@@ -13,6 +13,7 @@ export 'presentation/extensions/compare_list_extensions.dart';
|
||||
export 'presentation/extensions/string_extension.dart';
|
||||
export 'presentation/extensions/tap_down_details_extension.dart';
|
||||
export 'domain/extensions/media_type_extension.dart';
|
||||
export 'presentation/extensions/map_extensions.dart';
|
||||
|
||||
// Exceptions
|
||||
export 'domain/exceptions/download_file_exception.dart';
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
extension MapExtensions<K, V> on Map<K, V> {
|
||||
|
||||
Map<K, V> where(bool Function(K, V) condition) {
|
||||
Map<K, V> result = {};
|
||||
for (var element in entries) {
|
||||
if (condition(element.key, element.value)) {
|
||||
result[element.key] = element.value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:tmail_ui_user/features/caching/config/hive_cache_config.dart';
|
||||
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||
|
||||
abstract class HiveCacheClient<T> {
|
||||
|
||||
@@ -77,6 +79,21 @@ abstract class HiveCacheClient<T> {
|
||||
});
|
||||
}
|
||||
|
||||
Future<List<T>> getListByCollectionId(String collectionId) {
|
||||
return Future.sync(() async {
|
||||
final boxItem = encryption ? await openBoxEncryption() : await openBox();
|
||||
return boxItem.toMap()
|
||||
.where((key, value) {
|
||||
final tupleKey = TupleKey.fromString(key as String);
|
||||
return tupleKey.parts.length >= 2 && tupleKey.parts[1] == collectionId;
|
||||
})
|
||||
.values
|
||||
.toList();
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateItem(String key, T newObject) {
|
||||
return Future.sync(() async {
|
||||
final boxItem = encryption
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -117,7 +117,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
||||
|
||||
@override
|
||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId) async {
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache();
|
||||
final mailboxesCache = await _mapMailboxDataSource[DataSourceType.local]!.getAllMailboxCache(accountId);
|
||||
final mailboxesCacheNotPutNotifications = mailboxesCache
|
||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||
|
||||
Reference in New Issue
Block a user