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/string_extension.dart';
|
||||||
export 'presentation/extensions/tap_down_details_extension.dart';
|
export 'presentation/extensions/tap_down_details_extension.dart';
|
||||||
export 'domain/extensions/media_type_extension.dart';
|
export 'domain/extensions/media_type_extension.dart';
|
||||||
|
export 'presentation/extensions/map_extensions.dart';
|
||||||
|
|
||||||
// Exceptions
|
// Exceptions
|
||||||
export 'domain/exceptions/download_file_exception.dart';
|
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 'dart:typed_data';
|
||||||
|
|
||||||
|
import 'package:core/core.dart';
|
||||||
import 'package:hive/hive.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/config/hive_cache_config.dart';
|
||||||
|
import 'package:tmail_ui_user/features/caching/utils/cache_utils.dart';
|
||||||
|
|
||||||
abstract class HiveCacheClient<T> {
|
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) {
|
Future<void> updateItem(String key, T newObject) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxItem = encryption
|
final boxItem = encryption
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/subscribe_multiple_m
|
|||||||
abstract class MailboxDataSource {
|
abstract class MailboxDataSource {
|
||||||
Future<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties});
|
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);
|
Future<MailboxChangeResponse> getChanges(Session session, AccountId accountId, State sinceState);
|
||||||
|
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Mailbox>> getAllMailboxCache() {
|
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final listMailboxes = await _mailboxCacheManager.getAllMailbox();
|
final listMailboxes = await _mailboxCacheManager.getAllMailbox(accountId);
|
||||||
return listMailboxes;
|
return listMailboxes;
|
||||||
}).catchError(_exceptionThrower.throwException);
|
}).catchError(_exceptionThrower.throwException);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<Mailbox>> getAllMailboxCache() {
|
Future<List<Mailbox>> getAllMailboxCache(AccountId accountId) {
|
||||||
throw UnimplementedError();
|
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/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.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:model/mailbox/presentation_mailbox.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.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_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/list_mailbox_id_extension.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_cache_extension.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_cache_extension.dart';
|
||||||
@@ -14,10 +16,9 @@ class MailboxCacheManager {
|
|||||||
|
|
||||||
MailboxCacheManager(this._mailboxCacheClient);
|
MailboxCacheManager(this._mailboxCacheClient);
|
||||||
|
|
||||||
Future<List<Mailbox>> getAllMailbox() async {
|
Future<List<Mailbox>> getAllMailbox(AccountId accountId) async {
|
||||||
final mailboxCacheList = await _mailboxCacheClient.getAll();
|
final mailboxCacheList = await _mailboxCacheClient.getListByCollectionId(accountId.asString);
|
||||||
final mailboxList = mailboxCacheList.map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
return mailboxCacheList.toMailboxList();
|
||||||
return mailboxList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> update(
|
Future<void> update(
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
|||||||
@override
|
@override
|
||||||
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
|
Stream<MailboxResponse> getAllMailbox(Session session, AccountId accountId, {Properties? properties}) async* {
|
||||||
final localMailboxResponse = await Future.wait([
|
final localMailboxResponse = await Future.wait([
|
||||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||||
stateDataSource.getState(StateType.mailbox)
|
stateDataSource.getState(StateType.mailbox)
|
||||||
]).then((List response) {
|
]).then((List response) {
|
||||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||||
@@ -83,7 +83,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final newMailboxResponse = await Future.wait([
|
final newMailboxResponse = await Future.wait([
|
||||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||||
stateDataSource.getState(StateType.mailbox)
|
stateDataSource.getState(StateType.mailbox)
|
||||||
]).then((List response) {
|
]).then((List response) {
|
||||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||||
@@ -118,7 +118,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<MailboxResponse> refresh(Session session, AccountId accountId, State currentState) async* {
|
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;
|
bool hasMoreChanges = true;
|
||||||
State? sinceState = currentState;
|
State? sinceState = currentState;
|
||||||
@@ -146,7 +146,7 @@ class MailboxRepositoryImpl extends MailboxRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final newMailboxResponse = await Future.wait([
|
final newMailboxResponse = await Future.wait([
|
||||||
mapDataSource[DataSourceType.local]!.getAllMailboxCache(),
|
mapDataSource[DataSourceType.local]!.getAllMailboxCache(accountId),
|
||||||
stateDataSource.getState(StateType.mailbox)
|
stateDataSource.getState(StateType.mailbox)
|
||||||
]).then((List response) {
|
]).then((List response) {
|
||||||
return MailboxResponse(mailboxes: response.first, state: response.last);
|
return MailboxResponse(mailboxes: response.first, state: response.last);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ class FCMRepositoryImpl extends FCMRepository {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<PresentationMailbox>> getMailboxesNotPutNotifications(Session session, AccountId accountId) async {
|
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
|
final mailboxesCacheNotPutNotifications = mailboxesCache
|
||||||
.map((mailbox) => mailbox.toPresentationMailbox())
|
.map((mailbox) => mailbox.toPresentationMailbox())
|
||||||
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
.where((presentationMailbox) => presentationMailbox.pushNotificationDeactivated)
|
||||||
|
|||||||
Reference in New Issue
Block a user