diff --git a/lib/features/caching/config/cache_config.dart b/lib/features/caching/config/cache_config.dart deleted file mode 100644 index e5c508c66..000000000 --- a/lib/features/caching/config/cache_config.dart +++ /dev/null @@ -1,6 +0,0 @@ - -abstract class CacheConfig { - Future initializeDatabase(); - - void registerAdapter(); -} \ No newline at end of file diff --git a/lib/features/caching/config/cache_client.dart b/lib/features/caching/config/hive_cache_client.dart similarity index 89% rename from lib/features/caching/config/cache_client.dart rename to lib/features/caching/config/hive_cache_client.dart index 0f5ebbe31..9fdac09d2 100644 --- a/lib/features/caching/config/cache_client.dart +++ b/lib/features/caching/config/hive_cache_client.dart @@ -1,7 +1,7 @@ import 'package:hive/hive.dart'; -abstract class CacheClient { +abstract class HiveCacheClient { String get tableName; @@ -13,7 +13,7 @@ abstract class CacheClient { Future getItem(String key); - Future> getListItem(); + Future> getAll(); Future updateItem(String key, T newObject); diff --git a/lib/features/caching/config/hive_cache_config.dart b/lib/features/caching/config/hive_cache_config.dart index c07632be0..35567968d 100644 --- a/lib/features/caching/config/hive_cache_config.dart +++ b/lib/features/caching/config/hive_cache_config.dart @@ -1,29 +1,28 @@ import 'dart:io'; import 'package:hive/hive.dart'; -import 'package:model/caching/mailbox/mailbox_rights_cache.dart'; -import 'package:model/model.dart'; import 'package:path_provider/path_provider.dart' as pathProvider; -import 'package:tmail_ui_user/features/caching/config/cache_config.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; -class HiveCacheConfig extends CacheConfig { +class HiveCacheConfig { Future setUp() async { await initializeDatabase(); registerAdapter(); } - @override Future initializeDatabase() async { Directory directory = await pathProvider.getApplicationDocumentsDirectory(); Hive.init(directory.path); } - @override void registerAdapter() { Hive.registerAdapter(MailboxCacheAdapter()); Hive.registerAdapter(MailboxRightsCacheAdapter()); - Hive.registerAdapter(StateDaoAdapter()); + Hive.registerAdapter(StateCacheAdapter()); Hive.registerAdapter(StateTypeAdapter()); } } \ No newline at end of file diff --git a/lib/features/caching/mailbox_cache_client.dart b/lib/features/caching/mailbox_cache_client.dart index 8b66666a2..662e6a0dc 100644 --- a/lib/features/caching/mailbox_cache_client.dart +++ b/lib/features/caching/mailbox_cache_client.dart @@ -1,9 +1,9 @@ import 'package:hive/hive.dart'; -import 'package:model/model.dart'; -import 'package:tmail_ui_user/features/caching/config/cache_client.dart'; +import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; -class MailboxCacheClient extends CacheClient { +class MailboxCacheClient extends HiveCacheClient { @override String get tableName => 'MailboxCache'; @@ -51,7 +51,7 @@ class MailboxCacheClient extends CacheClient { } @override - Future> getListItem() { + Future> getAll() { return Future.sync(() async { final boxMailbox = await openTable(); return boxMailbox.values.toList(); diff --git a/lib/features/caching/state_cache_client.dart b/lib/features/caching/state_cache_client.dart index c08f6668c..71ffefd64 100644 --- a/lib/features/caching/state_cache_client.dart +++ b/lib/features/caching/state_cache_client.dart @@ -1,20 +1,20 @@ import 'package:hive/hive.dart'; -import 'package:model/model.dart'; -import 'package:tmail_ui_user/features/caching/config/cache_client.dart'; +import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; -class StateCacheClient extends CacheClient { +class StateCacheClient extends HiveCacheClient { @override String get tableName => 'StateCache'; @override - Future> openTable() { + Future> openTable() { return Future.sync(() async { if (Hive.isBoxOpen(tableName)) { - return Hive.box(tableName); + return Hive.box(tableName); } - return await Hive.openBox(tableName); + return await Hive.openBox(tableName); }).catchError((error) { throw error; }); @@ -41,7 +41,7 @@ class StateCacheClient extends CacheClient { } @override - Future getItem(String key) { + Future getItem(String key) { return Future.sync(() async { final boxState = await openTable(); return boxState.get(key); @@ -51,7 +51,7 @@ class StateCacheClient extends CacheClient { } @override - Future> getListItem() { + Future> getAll() { return Future.sync(() async { final boxState = await openTable(); return boxState.values.toList(); @@ -61,7 +61,7 @@ class StateCacheClient extends CacheClient { } @override - Future insertItem(String key, StateDao newObject) { + Future insertItem(String key, StateCache newObject) { return Future.sync(() async { final boxState = await openTable(); boxState.put(key, newObject); @@ -71,7 +71,7 @@ class StateCacheClient extends CacheClient { } @override - Future insertMultipleItem(Map mapObject) { + Future insertMultipleItem(Map mapObject) { return Future.sync(() async { final boxState = await openTable(); boxState.putAll(mapObject); @@ -81,7 +81,7 @@ class StateCacheClient extends CacheClient { } @override - Future updateItem(String key, StateDao newObject) { + Future updateItem(String key, StateCache newObject) { return Future.sync(() async { final boxState = await openTable(); boxState.put(key, newObject); @@ -110,7 +110,7 @@ class StateCacheClient extends CacheClient { } @override - Future updateMultipleItem(Map mapObject) { + Future updateMultipleItem(Map mapObject) { return Future.sync(() async { final boxState = await openTable(); boxState.putAll(mapObject); diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart index 8601c4adb..9b5c80155 100644 --- a/lib/features/composer/presentation/composer_controller.dart +++ b/lib/features/composer/presentation/composer_controller.dart @@ -187,6 +187,7 @@ class ComposerController extends BaseController { } else if (fromEmailAddress != null && fromEmailAddress.isNotEmpty) { listReplyToEmailAddress.value = fromEmailAddress.toList(); } + listToEmailAddress = listReplyToEmailAddress; } _updateStatusEmailSendButton(); } diff --git a/lib/features/destination_picker/presentation/destination_picker_bindings.dart b/lib/features/destination_picker/presentation/destination_picker_bindings.dart index 0ce0b00c3..0bfb82ff0 100644 --- a/lib/features/destination_picker/presentation/destination_picker_bindings.dart +++ b/lib/features/destination_picker/presentation/destination_picker_bindings.dart @@ -1,11 +1,14 @@ import 'package:core/core.dart'; import 'package:get/get.dart'; +import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; import 'package:tmail_ui_user/features/destination_picker/presentation/destination_picker_controller.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart'; import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart'; -import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_cache_manager.dart'; +import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart'; import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; @@ -17,10 +20,15 @@ class DestinationPickerBindings extends Bindings { Get.lazyPut(() => MailboxDataSourceImpl(Get.find())); Get.lazyPut(() => Get.find()); Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find())); - Get.lazyPut(() => MailboxRepositoryImpl({ - DataSourceType.network: Get.find(), - DataSourceType.local: Get.find(), - })); + Get.lazyPut(() => StateDataSourceImpl(Get.find())); + Get.lazyPut(() => Get.find()); + Get.lazyPut(() => MailboxRepositoryImpl( + { + DataSourceType.network: Get.find(), + DataSourceType.local: Get.find() + }, + Get.find() + )); Get.lazyPut(() => Get.find()); Get.lazyPut(() => GetAllMailboxInteractor(Get.find())); Get.lazyPut(() => TreeBuilder()); diff --git a/lib/features/mailbox/data/datasource/mailbox_datasource.dart b/lib/features/mailbox/data/datasource/mailbox_datasource.dart index e2983109c..3fb602968 100644 --- a/lib/features/mailbox/data/datasource/mailbox_datasource.dart +++ b/lib/features/mailbox/data/datasource/mailbox_datasource.dart @@ -1,19 +1,16 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/state.dart'; -import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_response.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache_response.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; abstract class MailboxDataSource { - Future getAllMailbox(AccountId accountId, {Properties? properties}); + Future getAllMailbox(AccountId accountId, {Properties? properties}); + + Future> getAllMailboxCache(); Future getChanges(AccountId accountId, State sinceState); - Future getAllMailboxCache(); - - Future combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List mailboxList); - - Future asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse); + Future update({List? updated, List? created, List? destroyed}); } \ No newline at end of file diff --git a/lib/features/mailbox/data/datasource/state_datasource.dart b/lib/features/mailbox/data/datasource/state_datasource.dart new file mode 100644 index 000000000..fcce4a121 --- /dev/null +++ b/lib/features/mailbox/data/datasource/state_datasource.dart @@ -0,0 +1,9 @@ +import 'package:jmap_dart_client/jmap/core/state.dart'; +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 getState(StateType stateType); + + Future saveState(StateCache stateCache); +} \ No newline at end of file diff --git a/lib/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart b/lib/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart index 539e3e4da..eac31b4e6 100644 --- a/lib/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart +++ b/lib/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart @@ -1,12 +1,11 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/state.dart'; -import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_response.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache_response.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; -import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_cache_manager.dart'; +import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; class MailboxCacheDataSourceImpl extends MailboxDataSource { @@ -15,37 +14,28 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource { MailboxCacheDataSourceImpl(this._mailboxCacheManager); @override - Future getAllMailbox(AccountId accountId, {Properties? properties}) { + Future getAllMailbox(AccountId accountId, {Properties? properties}) { throw UnimplementedError(); } - @override - Future getAllMailboxCache() { - return Future.sync(() async { - return await _mailboxCacheManager.getAllMailbox(); - }).catchError((error) { - throw error; - }); - } - - @override - Future asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) { - return Future.sync(() async { - return await _mailboxCacheManager.asyncUpdateCache(mailboxChangeResponse); - }).catchError((error) { - throw error; - }); - } - @override Future getChanges(AccountId accountId, State sinceState) { throw UnimplementedError(); } @override - Future combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List mailboxList) { + Future update({List? updated, List? created, List? destroyed}) { return Future.sync(() async { - return await _mailboxCacheManager.combineMailboxCache(mailboxChangeResponse, mailboxList); + return await _mailboxCacheManager.update(updated: updated, created: created, destroyed: destroyed); + }).catchError((error) { + throw error; + }); + } + + @override + Future> getAllMailboxCache() { + return Future.sync(() async { + return await _mailboxCacheManager.getAllMailbox(); }).catchError((error) { throw error; }); diff --git a/lib/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart b/lib/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart index 5ac4705b9..2d4e210a4 100644 --- a/lib/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart +++ b/lib/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart @@ -1,21 +1,20 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/state.dart'; -import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_response.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache_response.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart'; class MailboxDataSourceImpl extends MailboxDataSource { final MailboxAPI mailboxAPI; - MailboxDataSourceImpl(this.mailboxAPI,); + MailboxDataSourceImpl(this.mailboxAPI); @override - Future getAllMailbox(AccountId accountId, {Properties? properties}) { + Future getAllMailbox(AccountId accountId, {Properties? properties}) { return Future.sync(() async { return await mailboxAPI.getAllMailbox(accountId, properties: properties); }).catchError((error) { @@ -23,16 +22,6 @@ class MailboxDataSourceImpl extends MailboxDataSource { }); } - @override - Future getAllMailboxCache() { - throw UnimplementedError(); - } - - @override - Future asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) { - throw UnimplementedError(); - } - @override Future getChanges(AccountId accountId, State sinceState) { return Future.sync(() async { @@ -43,7 +32,12 @@ class MailboxDataSourceImpl extends MailboxDataSource { } @override - Future combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List mailboxList) { + Future update({List? updated, List? created, List? destroyed}) { + throw UnimplementedError(); + } + + @override + Future> getAllMailboxCache() { throw UnimplementedError(); } } \ No newline at end of file diff --git a/lib/features/mailbox/data/datasource_impl/state_datasource_impl.dart b/lib/features/mailbox/data/datasource_impl/state_datasource_impl.dart new file mode 100644 index 000000000..a320308b4 --- /dev/null +++ b/lib/features/mailbox/data/datasource_impl/state_datasource_impl.dart @@ -0,0 +1,38 @@ + +import 'package:jmap_dart_client/jmap/core/state.dart'; +import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; +import 'package:tmail_ui_user/features/mailbox/data/extensions/state_cache_extension.dart'; + +class StateDataSourceImpl extends StateDataSource { + + final StateCacheClient _stateCacheClient; + + StateDataSourceImpl(this._stateCacheClient); + + @override + Future getState(StateType stateType) { + return Future.sync(() async { + final stateCache = await _stateCacheClient.getItem(stateType.value); + return stateCache != null ? stateCache.toState() : null; + }).catchError((error) { + throw error; + }); + } + + @override + Future saveState(StateCache stateCache) { + return Future.sync(() async { + final stateCacheExist = await _stateCacheClient.isExistTable(); + if (stateCacheExist) { + return await _stateCacheClient.updateItem(stateCache.type.value, stateCache); + } else { + return await _stateCacheClient.insertItem(stateCache.type.value, stateCache); + } + }).catchError((error) { + throw error; + }); + } +} \ No newline at end of file diff --git a/model/lib/extensions/list_mailbox_cache_extension.dart b/lib/features/mailbox/data/extensions/list_mailbox_cache_extension.dart similarity index 56% rename from model/lib/extensions/list_mailbox_cache_extension.dart rename to lib/features/mailbox/data/extensions/list_mailbox_cache_extension.dart index 7885355b2..692baa1cf 100644 --- a/model/lib/extensions/list_mailbox_cache_extension.dart +++ b/lib/features/mailbox/data/extensions/list_mailbox_cache_extension.dart @@ -1,6 +1,5 @@ -import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; -import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; extension ListMailboxCacheExtension on List { Map toMap() { @@ -9,8 +8,4 @@ extension ListMailboxCacheExtension on List { key: (mailboxCache) => mailboxCache.id, value: (mailboxCache) => mailboxCache); } - - List toMailboxList() { - return map((mailboxCache) => mailboxCache.toMailbox()).toList(); - } } \ No newline at end of file diff --git a/model/lib/extensions/mailbox_cache_extension.dart b/lib/features/mailbox/data/extensions/mailbox_cache_extension.dart similarity index 84% rename from model/lib/extensions/mailbox_cache_extension.dart rename to lib/features/mailbox/data/extensions/mailbox_cache_extension.dart index b8606dfa6..38c97d2d2 100644 --- a/model/lib/extensions/mailbox_cache_extension.dart +++ b/lib/features/mailbox/data/extensions/mailbox_cache_extension.dart @@ -2,7 +2,8 @@ import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/unsigned_int.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; -import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_rights_cache_extension.dart'; extension MailboxCacheExtension on MailboxCache { Mailbox toMailbox() { diff --git a/lib/features/mailbox/data/extensions/mailbox_change_response_extension.dart b/lib/features/mailbox/data/extensions/mailbox_change_response_extension.dart new file mode 100644 index 000000000..0a3dcb86a --- /dev/null +++ b/lib/features/mailbox/data/extensions/mailbox_change_response_extension.dart @@ -0,0 +1,18 @@ + +import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; + +extension MailboxChangeResponseExtension on MailboxChangeResponse { + + MailboxChangeResponse updatedMailboxChangeResponse(List? updatedMailbox) { + return MailboxChangeResponse( + updated: updatedMailbox, + created: created, + destroyed: destroyed, + newStateMailbox: newStateMailbox, + newStateChanges: newStateChanges, + hasMoreChanges: hasMoreChanges, + updatedProperties: updatedProperties + ); + } +} \ No newline at end of file diff --git a/lib/features/mailbox/data/extensions/mailbox_extension.dart b/lib/features/mailbox/data/extensions/mailbox_extension.dart new file mode 100644 index 000000000..c69e19071 --- /dev/null +++ b/lib/features/mailbox/data/extensions/mailbox_extension.dart @@ -0,0 +1,22 @@ +import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_rights_extension.dart'; + +extension MailboxExtension on Mailbox { + + MailboxCache toMailboxCache() { + return MailboxCache( + id.id.value, + name: name?.name, + parentId: parentId?.id.value, + role: role?.value, + sortOrder: sortOrder?.value.value.round(), + totalEmails: totalEmails?.value.value.round(), + unreadEmails: unreadEmails?.value.value.round(), + totalThreads: totalThreads?.value.value.round(), + unreadThreads: unreadThreads?.value.value.round(), + myRights: myRights != null ? myRights!.toMailboxRightsCache() : null, + isSubscribed: isSubscribed?.value + ); + } +} \ No newline at end of file diff --git a/model/lib/extensions/mailbox_rights_cache_extension.dart b/lib/features/mailbox/data/extensions/mailbox_rights_cache_extension.dart similarity index 81% rename from model/lib/extensions/mailbox_rights_cache_extension.dart rename to lib/features/mailbox/data/extensions/mailbox_rights_cache_extension.dart index da38f9ec7..a349ccbb7 100644 --- a/model/lib/extensions/mailbox_rights_cache_extension.dart +++ b/lib/features/mailbox/data/extensions/mailbox_rights_cache_extension.dart @@ -1,5 +1,5 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart'; -import 'package:model/caching/mailbox/mailbox_rights_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart'; extension MailboxRightsCacheExtension on MailboxRightsCache { MailboxRights toMailboxRights() { diff --git a/model/lib/extensions/mailbox_rights_extension.dart b/lib/features/mailbox/data/extensions/mailbox_rights_extension.dart similarity index 81% rename from model/lib/extensions/mailbox_rights_extension.dart rename to lib/features/mailbox/data/extensions/mailbox_rights_extension.dart index 234c28786..cf8e291fe 100644 --- a/model/lib/extensions/mailbox_rights_extension.dart +++ b/lib/features/mailbox/data/extensions/mailbox_rights_extension.dart @@ -1,5 +1,5 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart'; -import 'package:model/caching/mailbox/mailbox_rights_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart'; extension MailboxRightsExtension on MailboxRights { MailboxRightsCache toMailboxRightsCache() { diff --git a/lib/features/mailbox/data/extensions/state_cache_extension.dart b/lib/features/mailbox/data/extensions/state_cache_extension.dart new file mode 100644 index 000000000..f4d74fd32 --- /dev/null +++ b/lib/features/mailbox/data/extensions/state_cache_extension.dart @@ -0,0 +1,9 @@ + +import 'package:jmap_dart_client/jmap/core/state.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; + +extension StateCacheExtension on StateCache { + State toState() { + return State(state); + } +} \ No newline at end of file diff --git a/lib/features/mailbox/data/extensions/state_extension.dart b/lib/features/mailbox/data/extensions/state_extension.dart new file mode 100644 index 000000000..6eaaf5b5d --- /dev/null +++ b/lib/features/mailbox/data/extensions/state_extension.dart @@ -0,0 +1,10 @@ + +import 'package:jmap_dart_client/jmap/core/state.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; + +extension StateExtension on State { + StateCache toStateCache(StateType stateType) { + return StateCache(stateType, value); + } +} \ No newline at end of file diff --git a/lib/features/mailbox/data/local/mailbox_cache_manager.dart b/lib/features/mailbox/data/local/mailbox_cache_manager.dart new file mode 100644 index 000000000..9d3c3578b --- /dev/null +++ b/lib/features/mailbox/data/local/mailbox_cache_manager.dart @@ -0,0 +1,41 @@ + +import 'package:jmap_dart_client/jmap/mail/mailbox/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/mailbox_cache_extension.dart'; +import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_extension.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart'; + +class MailboxCacheManager { + + final MailboxCacheClient _mailboxCacheClient; + + MailboxCacheManager(this._mailboxCacheClient); + + Future> getAllMailbox() async { + final mailboxCacheList = await _mailboxCacheClient.getAll(); + final mailboxList = mailboxCacheList.map((mailboxCache) => mailboxCache.toMailbox()).toList(); + return mailboxList; + } + + Future update({List? updated, List? created, List? destroyed}) async { + final mailboxCacheExist = await _mailboxCacheClient.isExistTable(); + if (mailboxCacheExist) { + final updatedCacheMailboxes = updated + ?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? []; + final createdCacheMailboxes = created + ?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? []; + final destroyedCacheMailboxes = destroyed + ?.map((mailboxId) => mailboxId.id.value).toList() ?? []; + await Future.wait([ + _mailboxCacheClient.updateMultipleItem(updatedCacheMailboxes.toMap()), + _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()), + _mailboxCacheClient.deleteMultipleItem(destroyedCacheMailboxes) + ]); + } else { + final createdCacheMailboxes = created + ?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? []; + await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()); + } + } +} \ No newline at end of file diff --git a/model/lib/caching/mailbox/mailbox_cache.dart b/lib/features/mailbox/data/model/mailbox_cache.dart similarity index 87% rename from model/lib/caching/mailbox/mailbox_cache.dart rename to lib/features/mailbox/data/model/mailbox_cache.dart index 058586ab4..4c2efcddf 100644 --- a/model/lib/caching/mailbox/mailbox_cache.dart +++ b/lib/features/mailbox/data/model/mailbox_cache.dart @@ -1,8 +1,8 @@ import 'package:equatable/equatable.dart'; import 'package:hive/hive.dart'; -import 'package:model/caching/mailbox/mailbox_rights_cache.dart'; -import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart'; +import 'package:tmail_ui_user/features/mailbox/data/utils/caching_constants.dart'; part 'mailbox_cache.g.dart'; diff --git a/lib/features/mailbox/data/model/mailbox_cache.g.dart b/lib/features/mailbox/data/model/mailbox_cache.g.dart new file mode 100644 index 000000000..232fb51a6 --- /dev/null +++ b/lib/features/mailbox/data/model/mailbox_cache.g.dart @@ -0,0 +1,74 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mailbox_cache.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class MailboxCacheAdapter extends TypeAdapter { + @override + final int typeId = 1; + + @override + MailboxCache read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return MailboxCache( + fields[0] as String, + name: fields[1] as String?, + parentId: fields[2] as String?, + role: fields[3] as String?, + sortOrder: fields[4] as int?, + totalEmails: fields[5] as int?, + unreadEmails: fields[6] as int?, + totalThreads: fields[7] as int?, + unreadThreads: fields[8] as int?, + myRights: fields[9] as MailboxRightsCache?, + isSubscribed: fields[10] as bool?, + lastOpened: fields[11] as DateTime?, + ); + } + + @override + void write(BinaryWriter writer, MailboxCache obj) { + writer + ..writeByte(12) + ..writeByte(0) + ..write(obj.id) + ..writeByte(1) + ..write(obj.name) + ..writeByte(2) + ..write(obj.parentId) + ..writeByte(3) + ..write(obj.role) + ..writeByte(4) + ..write(obj.sortOrder) + ..writeByte(5) + ..write(obj.totalEmails) + ..writeByte(6) + ..write(obj.unreadEmails) + ..writeByte(7) + ..write(obj.totalThreads) + ..writeByte(8) + ..write(obj.unreadThreads) + ..writeByte(9) + ..write(obj.myRights) + ..writeByte(10) + ..write(obj.isSubscribed) + ..writeByte(11) + ..write(obj.lastOpened); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is MailboxCacheAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/features/mailbox/data/model/mailbox_cache_response.dart b/lib/features/mailbox/data/model/mailbox_cache_response.dart deleted file mode 100644 index 6866e1cd0..000000000 --- a/lib/features/mailbox/data/model/mailbox_cache_response.dart +++ /dev/null @@ -1,16 +0,0 @@ - -import 'package:equatable/equatable.dart'; -import 'package:model/model.dart'; - -class MailboxCacheResponse with EquatableMixin { - final List? mailboxCaches; - final StateDao? oldState; - - MailboxCacheResponse({ - this.mailboxCaches, - this.oldState - }); - - @override - List get props => [mailboxCaches, oldState]; -} \ No newline at end of file diff --git a/lib/features/mailbox/data/model/mailbox_change_response.dart b/lib/features/mailbox/data/model/mailbox_change_response.dart index 68a30f405..1b3972448 100644 --- a/lib/features/mailbox/data/model/mailbox_change_response.dart +++ b/lib/features/mailbox/data/model/mailbox_change_response.dart @@ -8,17 +8,29 @@ class MailboxChangeResponse with EquatableMixin { final List? updated; final List? created; final List? destroyed; - final State? newState; + final State? newStateMailbox; + final State? newStateChanges; + final bool hasMoreChanges; final Properties? updatedProperties; MailboxChangeResponse({ this.updated, this.created, this.destroyed, - this.newState, + this.newStateMailbox, + this.newStateChanges, + this.hasMoreChanges = false, this.updatedProperties, }); @override - List get props => [updated, created, destroyed, newState, updatedProperties]; + List get props => [ + updated, + created, + destroyed, + newStateMailbox, + newStateChanges, + hasMoreChanges, + updatedProperties + ]; } \ No newline at end of file diff --git a/lib/features/mailbox/data/model/mailbox_response.dart b/lib/features/mailbox/data/model/mailbox_response.dart new file mode 100644 index 000000000..8b07a0e5e --- /dev/null +++ b/lib/features/mailbox/data/model/mailbox_response.dart @@ -0,0 +1,23 @@ + +import 'package:equatable/equatable.dart'; +import 'package:jmap_dart_client/jmap/core/state.dart'; +import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; + +class MailboxResponse with EquatableMixin { + final List? mailboxes; + final State? state; + + MailboxResponse({ + this.mailboxes, + this.state + }); + + bool hasData() { + return mailboxes != null + && mailboxes!.isNotEmpty + && state != null; + } + + @override + List get props => [mailboxes, state]; +} \ No newline at end of file diff --git a/model/lib/caching/mailbox/mailbox_rights_cache.dart b/lib/features/mailbox/data/model/mailbox_rights_cache.dart similarity index 92% rename from model/lib/caching/mailbox/mailbox_rights_cache.dart rename to lib/features/mailbox/data/model/mailbox_rights_cache.dart index 50a402623..bb5b7186d 100644 --- a/model/lib/caching/mailbox/mailbox_rights_cache.dart +++ b/lib/features/mailbox/data/model/mailbox_rights_cache.dart @@ -1,7 +1,7 @@ import 'package:equatable/equatable.dart'; import 'package:hive/hive.dart'; -import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/mailbox/data/utils/caching_constants.dart'; part 'mailbox_rights_cache.g.dart'; diff --git a/lib/features/mailbox/data/model/mailbox_rights_cache.g.dart b/lib/features/mailbox/data/model/mailbox_rights_cache.g.dart new file mode 100644 index 000000000..36101cff3 --- /dev/null +++ b/lib/features/mailbox/data/model/mailbox_rights_cache.g.dart @@ -0,0 +1,65 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'mailbox_rights_cache.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class MailboxRightsCacheAdapter extends TypeAdapter { + @override + final int typeId = 2; + + @override + MailboxRightsCache read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return MailboxRightsCache( + fields[0] as bool, + fields[1] as bool, + fields[2] as bool, + fields[3] as bool, + fields[4] as bool, + fields[5] as bool, + fields[6] as bool, + fields[7] as bool, + fields[8] as bool, + ); + } + + @override + void write(BinaryWriter writer, MailboxRightsCache obj) { + writer + ..writeByte(9) + ..writeByte(0) + ..write(obj.mayReadItems) + ..writeByte(1) + ..write(obj.mayAddItems) + ..writeByte(2) + ..write(obj.mayRemoveItems) + ..writeByte(3) + ..write(obj.maySetSeen) + ..writeByte(4) + ..write(obj.maySetKeywords) + ..writeByte(5) + ..write(obj.mayCreateChild) + ..writeByte(6) + ..write(obj.mayRename) + ..writeByte(7) + ..write(obj.mayDelete) + ..writeByte(8) + ..write(obj.maySubmit); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is MailboxRightsCacheAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/features/mailbox/data/model/state_cache.dart b/lib/features/mailbox/data/model/state_cache.dart new file mode 100644 index 000000000..7aa4771f3 --- /dev/null +++ b/lib/features/mailbox/data/model/state_cache.dart @@ -0,0 +1,22 @@ + +import 'package:equatable/equatable.dart'; +import 'package:hive/hive.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; +import 'package:tmail_ui_user/features/mailbox/data/utils/caching_constants.dart'; + +part 'state_cache.g.dart'; + +@HiveType(typeId: CachingConstants.STATE_CACHE_IDENTIFY) +class StateCache extends HiveObject with EquatableMixin { + + @HiveField(0) + final StateType type; + + @HiveField(1) + final String state; + + StateCache(this.type, this.state); + + @override + List get props => [type, state]; +} \ No newline at end of file diff --git a/lib/features/mailbox/data/model/state_cache.g.dart b/lib/features/mailbox/data/model/state_cache.g.dart new file mode 100644 index 000000000..31d0cf86a --- /dev/null +++ b/lib/features/mailbox/data/model/state_cache.g.dart @@ -0,0 +1,44 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'state_cache.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class StateCacheAdapter extends TypeAdapter { + @override + final int typeId = 3; + + @override + StateCache read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return StateCache( + fields[0] as StateType, + fields[1] as String, + ); + } + + @override + void write(BinaryWriter writer, StateCache obj) { + writer + ..writeByte(2) + ..writeByte(0) + ..write(obj.type) + ..writeByte(1) + ..write(obj.state); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is StateCacheAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/model/lib/caching/state/state_type.dart b/lib/features/mailbox/data/model/state_type.dart similarity index 79% rename from model/lib/caching/state/state_type.dart rename to lib/features/mailbox/data/model/state_type.dart index 3ef70a065..699c5fd5a 100644 --- a/model/lib/caching/state/state_type.dart +++ b/lib/features/mailbox/data/model/state_type.dart @@ -1,6 +1,6 @@ import 'package:hive/hive.dart'; -import 'package:model/model.dart'; +import 'package:tmail_ui_user/features/mailbox/data/utils/caching_constants.dart'; part 'state_type.g.dart'; diff --git a/lib/features/mailbox/data/model/state_type.g.dart b/lib/features/mailbox/data/model/state_type.g.dart new file mode 100644 index 000000000..357af1922 --- /dev/null +++ b/lib/features/mailbox/data/model/state_type.g.dart @@ -0,0 +1,41 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'state_type.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class StateTypeAdapter extends TypeAdapter { + @override + final int typeId = 4; + + @override + StateType read(BinaryReader reader) { + switch (reader.readByte()) { + case 0: + return StateType.mailbox; + default: + return StateType.mailbox; + } + } + + @override + void write(BinaryWriter writer, StateType obj) { + switch (obj) { + case StateType.mailbox: + writer.writeByte(0); + break; + } + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is StateTypeAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/features/mailbox/data/network/mailbox_api.dart b/lib/features/mailbox/data/network/mailbox_api.dart index 9277af546..892b274de 100644 --- a/lib/features/mailbox/data/network/mailbox_api.dart +++ b/lib/features/mailbox/data/network/mailbox_api.dart @@ -13,6 +13,7 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_method.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/get/get_mailbox_response.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; class MailboxAPI { @@ -20,7 +21,7 @@ class MailboxAPI { MailboxAPI(this.httpClient); - Future getAllMailbox(AccountId accountId, {Properties? properties}) async { + Future getAllMailbox(AccountId accountId, {Properties? properties}) async { final processingInvocation = ProcessingInvocation(); final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation); @@ -38,7 +39,7 @@ class MailboxAPI { queryInvocation.methodCallId, GetMailboxResponse.deserialize); - return resultCreated; + return MailboxResponse(mailboxes: resultCreated?.list, state: resultCreated?.state); } Future getChanges(AccountId accountId, State sinceState) async { @@ -85,19 +86,13 @@ class MailboxAPI { final listMailboxIdDestroyed = resultChanges?.destroyed.map((id) => MailboxId(id)).toList() ?? []; - final updatedProperties = resultChanges?.updatedProperties; - - final listMailboxUpdated = resultUpdated?.list ?? []; - - final listMailboxCreated = resultCreated?.list ?? []; - - final newState = resultChanges?.newState; - return MailboxChangeResponse( - updated: listMailboxUpdated, - created: listMailboxCreated, + updated: resultUpdated?.list, + created: resultCreated?.list, destroyed: listMailboxIdDestroyed, - newState: newState, - updatedProperties: updatedProperties); + newStateMailbox: resultUpdated?.state, + newStateChanges: resultChanges?.newState, + hasMoreChanges: resultChanges?.hasMoreChanges ?? false, + updatedProperties: resultChanges?.updatedProperties); } } \ No newline at end of file diff --git a/lib/features/mailbox/data/network/mailbox_cache_manager.dart b/lib/features/mailbox/data/network/mailbox_cache_manager.dart deleted file mode 100644 index d8be739b5..000000000 --- a/lib/features/mailbox/data/network/mailbox_cache_manager.dart +++ /dev/null @@ -1,105 +0,0 @@ - -import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; -import 'package:model/model.dart'; -import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; -import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache_response.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; - -class MailboxCacheManager { - - final MailboxCacheClient _mailboxCacheClient; - final StateCacheClient _stateCacheClient; - - MailboxCacheManager(this._mailboxCacheClient, this._stateCacheClient); - - Future getAllMailbox() async { - return await Future.wait( - [ - _stateCacheClient.getItem(StateType.mailbox.value), - _mailboxCacheClient.getListItem() - ], - eagerError: true - ).then((List responses) { - return MailboxCacheResponse(mailboxCaches: responses.last, oldState: responses.first); - }); - } - - Future combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List mailboxList) async { - - final mailboxUpdated = mailboxChangeResponse.updated; - final updatedProperties = mailboxChangeResponse.updatedProperties; - - if (mailboxUpdated != null && mailboxUpdated.isNotEmpty) { - final newListMailboxUpdated = mailboxUpdated.map((mailboxUpdated) { - if (updatedProperties == null) { - return mailboxUpdated; - } else { - final mailboxOld = findMailbox(mailboxUpdated.id, mailboxList); - if (mailboxOld != null) { - return mailboxOld.combineMailbox(mailboxUpdated, updatedProperties); - } else { - return mailboxUpdated; - } - } - }).toList(); - - final newMailboxChangeResponse = MailboxChangeResponse( - created: mailboxChangeResponse.created, - destroyed: mailboxChangeResponse.destroyed, - updated: newListMailboxUpdated, - newState: mailboxChangeResponse.newState, - updatedProperties: mailboxChangeResponse.updatedProperties - ); - - return newMailboxChangeResponse; - } - return mailboxChangeResponse; - } - - Mailbox? findMailbox(MailboxId mailboxId, List mailboxList) { - try { - return mailboxList.firstWhere((element) => element.id == mailboxId); - } catch (e) { - return null; - } - } - - Future asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) async { - if (mailboxChangeResponse.newState != null) { - final stateCacheExist = await _stateCacheClient.isExistTable(); - if (stateCacheExist) { - _stateCacheClient.updateItem( - StateType.mailbox.value, - mailboxChangeResponse.newState!.toStateDao(StateType.mailbox)); - } else { - _stateCacheClient.insertItem( - StateType.mailbox.value, - mailboxChangeResponse.newState!.toStateDao(StateType.mailbox)); - } - } - - final mailboxCacheExist = await _mailboxCacheClient.isExistTable(); - if (mailboxCacheExist) { - final updatedCacheMailboxes = mailboxChangeResponse.updated - ?.map((mailbox) => mailbox.toMailboxCache()) - .toList() ?? []; - final createdCacheMailboxes = mailboxChangeResponse.created - ?.map((mailbox) => mailbox.toMailboxCache()) - .toList() ?? []; - final destroyedCacheMailboxes = mailboxChangeResponse.destroyed - ?.map((mailboxId) => mailboxId.id.value) - .toList() ?? []; - await Future.wait([ - _mailboxCacheClient.updateMultipleItem(updatedCacheMailboxes.toMap()), - _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()), - _mailboxCacheClient.deleteMultipleItem(destroyedCacheMailboxes) - ]); - } else { - final createdCacheMailboxes = mailboxChangeResponse.created - ?.map((mailbox) => mailbox.toMailboxCache()) - .toList() ?? []; - await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()); - } - } -} \ No newline at end of file diff --git a/lib/features/mailbox/data/repository/mailbox_repository_impl.dart b/lib/features/mailbox/data/repository/mailbox_repository_impl.dart index f5d7b771d..862e30d67 100644 --- a/lib/features/mailbox/data/repository/mailbox_repository_impl.dart +++ b/lib/features/mailbox/data/repository/mailbox_repository_impl.dart @@ -1,65 +1,137 @@ import 'package:core/core.dart'; -import 'package:model/model.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/state.dart'; import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; +import 'package:model/model.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; -import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_change_response.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/extensions/state_extension.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/state_type.dart'; import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; class MailboxRepositoryImpl extends MailboxRepository { final Map mapDataSource; + final StateDataSource stateDataSource; - MailboxRepositoryImpl(this.mapDataSource); + MailboxRepositoryImpl(this.mapDataSource, this.stateDataSource); @override - Stream> getAllMailbox(AccountId accountId, {Properties? properties}) async* { - final mailboxCacheResponse = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(); + Stream getAllMailbox(AccountId accountId, {Properties? properties}) async* { + final localMailboxResponse = await Future.wait([ + mapDataSource[DataSourceType.local]!.getAllMailboxCache(), + stateDataSource.getState(StateType.mailbox) + ]).then((List response) { + return MailboxResponse(mailboxes: response.first, state: response.last); + }); - final mailboxList = mailboxCacheResponse.mailboxCaches != null - ? mailboxCacheResponse.mailboxCaches!.toMailboxList() - : []; - final oldState = mailboxCacheResponse.oldState?.state; + yield localMailboxResponse; - yield mailboxList; + if (localMailboxResponse.hasData()) { + bool hasMoreChanges = true; + State? sinceState = localMailboxResponse.state!; - if (mailboxList.isNotEmpty && oldState != null) { - final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, State(oldState)); + while(hasMoreChanges && sinceState != null) { + final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, sinceState); - final newChangesResponse = await mapDataSource[DataSourceType.local]!.combineMailboxCache(changesResponse, mailboxList); + hasMoreChanges = changesResponse.hasMoreChanges; + sinceState = changesResponse.newStateChanges; - await mapDataSource[DataSourceType.local]!.asyncUpdateCache(newChangesResponse); + final newMailboxUpdated = await _combineMailboxCache( + mailboxUpdated: changesResponse.updated, + updatedProperties: changesResponse.updatedProperties, + mailboxCacheList: localMailboxResponse.mailboxes!); + + await Future.wait([ + mapDataSource[DataSourceType.local]!.update( + updated: newMailboxUpdated, + created: changesResponse.created, + destroyed: changesResponse.destroyed), + if (changesResponse.newStateMailbox != null) + stateDataSource.saveState(changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)), + ]); + } } else { - final getMailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(accountId); + final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(accountId); - await mapDataSource[DataSourceType.local]!.asyncUpdateCache(MailboxChangeResponse( - created: getMailboxResponse?.list, - newState: getMailboxResponse?.state)); + await Future.wait([ + mapDataSource[DataSourceType.local]!.update(created: mailboxResponse.mailboxes), + if (mailboxResponse.state != null) + stateDataSource.saveState(mailboxResponse.state!.toStateCache(StateType.mailbox)), + ]); } - final newMailboxCacheResponse = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(); + final newMailboxResponse = await Future.wait([ + mapDataSource[DataSourceType.local]!.getAllMailboxCache(), + stateDataSource.getState(StateType.mailbox) + ]).then((List response) { + return MailboxResponse(mailboxes: response.first, state: response.last); + }); - final newMailboxList = newMailboxCacheResponse.mailboxCaches != null - ? newMailboxCacheResponse.mailboxCaches!.toMailboxList() - : []; + yield newMailboxResponse; + } - yield newMailboxList; + Future?> _combineMailboxCache({ + List? mailboxUpdated, + Properties? updatedProperties, + List? mailboxCacheList + }) async { + if (mailboxUpdated != null && mailboxUpdated.isNotEmpty) { + final newMailboxUpdated = mailboxUpdated.map((mailboxUpdated) { + if (updatedProperties == null) { + return mailboxUpdated; + } else { + final mailboxOld = mailboxCacheList?.findMailbox(mailboxUpdated.id); + if (mailboxOld != null) { + return mailboxOld.combineMailbox(mailboxUpdated, updatedProperties); + } else { + return mailboxUpdated; + } + } + }).toList(); + + return newMailboxUpdated; + } + return mailboxUpdated; } @override - Stream> refresh(AccountId accountId, State currentState) async* { - final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, currentState); + Stream refresh(AccountId accountId, State currentState) async* { + final localMailboxList = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(); - await mapDataSource[DataSourceType.local]!.asyncUpdateCache(changesResponse); + bool hasMoreChanges = true; + State? sinceState = currentState; - final newMailboxCacheResponse = await mapDataSource[DataSourceType.local]!.getAllMailboxCache(); + while(hasMoreChanges && sinceState != null) { + final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, sinceState); - final newMailboxList = newMailboxCacheResponse.mailboxCaches != null - ? newMailboxCacheResponse.mailboxCaches!.toMailboxList() - : []; + hasMoreChanges = changesResponse.hasMoreChanges; + sinceState = changesResponse.newStateChanges; - yield newMailboxList; + final newMailboxUpdated = await _combineMailboxCache( + mailboxUpdated: changesResponse.updated, + updatedProperties: changesResponse.updatedProperties, + mailboxCacheList: localMailboxList); + + await Future.wait([ + mapDataSource[DataSourceType.local]!.update( + updated: newMailboxUpdated, + created: changesResponse.created, + destroyed: changesResponse.destroyed), + if (changesResponse.newStateMailbox != null) + stateDataSource.saveState(changesResponse.newStateMailbox!.toStateCache(StateType.mailbox)), + ]); + } + + final newMailboxResponse = await Future.wait([ + mapDataSource[DataSourceType.local]!.getAllMailboxCache(), + stateDataSource.getState(StateType.mailbox) + ]).then((List response) { + return MailboxResponse(mailboxes: response.first, state: response.last); + }); + + yield newMailboxResponse; } } \ No newline at end of file diff --git a/model/lib/caching/caching_constants.dart b/lib/features/mailbox/data/utils/caching_constants.dart similarity index 79% rename from model/lib/caching/caching_constants.dart rename to lib/features/mailbox/data/utils/caching_constants.dart index 1b98ffc4a..bf4db343f 100644 --- a/model/lib/caching/caching_constants.dart +++ b/lib/features/mailbox/data/utils/caching_constants.dart @@ -2,6 +2,6 @@ class CachingConstants { static const int MAILBOX_CACHE_IDENTIFY = 1; static const int MAILBOX_RIGHTS_CACHE_IDENTIFY = 2; - static const int STATE_DAO_IDENTIFY = 3; + static const int STATE_CACHE_IDENTIFY = 3; static const int STATE_TYPE_IDENTIFY = 4; } \ No newline at end of file diff --git a/lib/features/mailbox/domain/repository/mailbox_repository.dart b/lib/features/mailbox/domain/repository/mailbox_repository.dart index e0953aea8..896270e02 100644 --- a/lib/features/mailbox/domain/repository/mailbox_repository.dart +++ b/lib/features/mailbox/domain/repository/mailbox_repository.dart @@ -1,10 +1,10 @@ import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; import 'package:jmap_dart_client/jmap/core/state.dart'; -import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; abstract class MailboxRepository { - Stream> getAllMailbox(AccountId accountId, {Properties? properties}); + Stream getAllMailbox(AccountId accountId, {Properties? properties}); - Stream> refresh(AccountId accountId, State currentState); + Stream refresh(AccountId accountId, State currentState); } \ No newline at end of file diff --git a/lib/features/mailbox/domain/state/get_all_mailboxes_state.dart b/lib/features/mailbox/domain/state/get_all_mailboxes_state.dart index eab518346..31a8861c8 100644 --- a/lib/features/mailbox/domain/state/get_all_mailboxes_state.dart +++ b/lib/features/mailbox/domain/state/get_all_mailboxes_state.dart @@ -1,14 +1,20 @@ import 'package:core/core.dart'; +import 'package:jmap_dart_client/jmap/core/state.dart'; import 'package:model/mailbox/presentation_mailbox.dart'; class GetAllMailboxSuccess extends UIState { final List defaultMailboxList; final List folderMailboxList; + final State? currentMailboxState; - GetAllMailboxSuccess({required this.defaultMailboxList, required this.folderMailboxList}); + GetAllMailboxSuccess({ + required this.defaultMailboxList, + required this.folderMailboxList, + required this.currentMailboxState + }); @override - List get props => [folderMailboxList]; + List get props => [defaultMailboxList, folderMailboxList, currentMailboxState]; } class GetAllMailboxFailure extends FeatureFailure { diff --git a/lib/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart b/lib/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart index 0b55dbb1f..4900d81a5 100644 --- a/lib/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart +++ b/lib/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart @@ -2,6 +2,7 @@ import 'package:core/core.dart'; import 'package:dartz/dartz.dart'; import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/core/properties/properties.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_extension.dart'; @@ -16,18 +17,21 @@ class GetAllMailboxInteractor { try { yield Right(LoadingState()); - final streamListMailbox = _mailboxRepository.getAllMailbox(accountId, properties: properties); - - final streamResult = streamListMailbox.asyncExpand((mailboxList) async* { - final tupleList = mailboxList.splitMailboxList((mailbox) => mailbox.hasRole()); - yield Right(GetAllMailboxSuccess( - defaultMailboxList: tupleList.value1, - folderMailboxList: tupleList.value2)); - }); - - yield* streamResult; + yield* _mailboxRepository + .getAllMailbox(accountId, properties: properties) + .map(_toGetMailboxState); } catch (e) { yield Left(GetAllMailboxFailure(e)); } } + + Either _toGetMailboxState(MailboxResponse mailboxResponse) { + final tupleList = mailboxResponse.mailboxes + ?.splitMailboxList((mailbox) => mailbox.hasRole()) ?? Tuple2([], []); + + return Right(GetAllMailboxSuccess( + defaultMailboxList: tupleList.value1, + folderMailboxList: tupleList.value2, + currentMailboxState: mailboxResponse.state)); + } } \ No newline at end of file diff --git a/lib/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart b/lib/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart new file mode 100644 index 000000000..4cfa129b0 --- /dev/null +++ b/lib/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart @@ -0,0 +1,37 @@ +import 'package:core/core.dart'; +import 'package:dartz/dartz.dart'; +import 'package:jmap_dart_client/jmap/account_id.dart'; +import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_extension.dart'; +import 'package:model/model.dart'; +import 'package:jmap_dart_client/jmap/core/state.dart' as jmapState; + +class RefreshAllMailboxInteractor { + final MailboxRepository _mailboxRepository; + + RefreshAllMailboxInteractor(this._mailboxRepository); + + Stream> execute(AccountId accountId, jmapState.State currentState) async* { + try { + yield Right(LoadingState()); + + yield* _mailboxRepository + .refresh(accountId, currentState) + .map(_toGetMailboxState); + } catch (e) { + yield Left(GetAllMailboxFailure(e)); + } + } + + Either _toGetMailboxState(MailboxResponse mailboxResponse) { + final tupleList = mailboxResponse.mailboxes + ?.splitMailboxList((mailbox) => mailbox.hasRole()) ?? Tuple2([], []); + + return Right(GetAllMailboxSuccess( + defaultMailboxList: tupleList.value1, + folderMailboxList: tupleList.value2, + currentMailboxState: mailboxResponse.state)); + } +} \ No newline at end of file diff --git a/lib/features/mailbox/presentation/mailbox_bindings.dart b/lib/features/mailbox/presentation/mailbox_bindings.dart index 7cd42c594..cd168ce62 100644 --- a/lib/features/mailbox/presentation/mailbox_bindings.dart +++ b/lib/features/mailbox/presentation/mailbox_bindings.dart @@ -1,17 +1,21 @@ import 'package:core/core.dart'; import 'package:get/get.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; import 'package:tmail_ui_user/features/login/data/repository/credential_repository_impl.dart'; import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart'; import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource/mailbox_datasource.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource/state_datasource.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_cache_datasource_impl.dart'; import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/mailbox_datasource_impl.dart'; +import 'package:tmail_ui_user/features/mailbox/data/datasource_impl/state_datasource_impl.dart'; import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart'; -import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_cache_manager.dart'; +import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repository_impl.dart'; import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/mailbox_controller.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; @@ -24,16 +28,23 @@ class MailboxBindings extends Bindings { Get.lazyPut(() => MailboxDataSourceImpl(Get.find())); Get.lazyPut(() => Get.find()); Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find())); - Get.lazyPut(() => MailboxRepositoryImpl({ - DataSourceType.network: Get.find(), - DataSourceType.local: Get.find(), - })); + Get.lazyPut(() => StateDataSourceImpl(Get.find())); + Get.lazyPut(() => Get.find()); + Get.lazyPut(() => MailboxRepositoryImpl( + { + DataSourceType.network: Get.find(), + DataSourceType.local: Get.find() + }, + Get.find() + )); Get.lazyPut(() => Get.find()); Get.lazyPut(() => GetAllMailboxInteractor(Get.find())); + Get.lazyPut(() => RefreshAllMailboxInteractor(Get.find())); Get.lazyPut(() => TreeBuilder()); Get.put(MailboxController( Get.find(), Get.find(), + Get.find(), Get.find(), Get.find())); } diff --git a/lib/features/mailbox/presentation/mailbox_controller.dart b/lib/features/mailbox/presentation/mailbox_controller.dart index 81b4687e0..4537ad5a2 100644 --- a/lib/features/mailbox/presentation/mailbox_controller.dart +++ b/lib/features/mailbox/presentation/mailbox_controller.dart @@ -11,6 +11,7 @@ import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_read_sta import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/domain/state/get_all_mailboxes_state.dart'; import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_interactor.dart'; +import 'package:tmail_ui_user/features/mailbox/domain/usecases/refresh_all_mailbox_interactor.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_node.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart'; import 'package:tmail_ui_user/features/mailbox/presentation/extensions/list_mailbox_node_extension.dart'; @@ -19,21 +20,26 @@ import 'package:tmail_ui_user/features/thread/domain/state/mark_as_multiple_emai import 'package:tmail_ui_user/features/thread/domain/state/move_multiple_email_to_mailbox_state.dart'; import 'package:tmail_ui_user/main/routes/app_routes.dart'; import 'package:tmail_ui_user/main/routes/route_navigation.dart'; +import 'package:jmap_dart_client/jmap/core/state.dart' as jmapState; class MailboxController extends BaseController { final mailboxDashBoardController = Get.find(); final GetAllMailboxInteractor _getAllMailboxInteractor; final DeleteCredentialInteractor _deleteCredentialInteractor; + final RefreshAllMailboxInteractor _refreshAllMailboxInteractor; final TreeBuilder _treeBuilder; final ResponsiveUtils responsiveUtils; final defaultMailboxList = [].obs; final folderMailboxNodeList = [].obs; + jmapState.State? currentMailboxState; + MailboxController( this._getAllMailboxInteractor, this._deleteCredentialInteractor, + this._refreshAllMailboxInteractor, this._treeBuilder, this.responsiveUtils ); @@ -52,11 +58,11 @@ class MailboxController extends BaseController { if (success is MarkAsEmailReadSuccess || success is MarkAsMultipleEmailReadAllSuccess || success is MarkAsMultipleEmailReadHasSomeEmailFailure) { - refreshGetAllMailboxAction(); + refreshMailboxChanges(); } else if (success is MoveMultipleEmailToMailboxAllSuccess || success is MoveMultipleEmailToMailboxHasSomeEmailFailure) { mailboxDashBoardController.clearState(); - refreshGetAllMailboxAction(); + refreshMailboxChanges(); } }); }); @@ -68,17 +74,6 @@ class MailboxController extends BaseController { super.onClose(); } - void refreshGetAllMailboxAction() { - final accountId = mailboxDashBoardController.accountId.value; - if (accountId != null) { - getAllMailboxAction(accountId); - } - } - - void getAllMailboxAction(AccountId accountId) async { - consumeState(_getAllMailboxInteractor.execute(accountId)); - } - @override void onData(Either newState) { super.onData(newState); @@ -93,6 +88,7 @@ class MailboxController extends BaseController { void onDone() { viewState.value.map((success) { if (success is GetAllMailboxSuccess) { + currentMailboxState = success.currentMailboxState; defaultMailboxList.value = success.defaultMailboxList; _setUpMapMailboxIdDefault(success.defaultMailboxList); } @@ -100,8 +96,24 @@ class MailboxController extends BaseController { } @override - void onError(error) { - print('$error'); + void onError(error) {} + + void getAllMailboxAction(AccountId accountId) async { + consumeState(_getAllMailboxInteractor.execute(accountId)); + } + + void refreshAllMailbox() { + final accountId = mailboxDashBoardController.accountId.value; + if (accountId != null) { + consumeState(_getAllMailboxInteractor.execute(accountId)); + } + } + + void refreshMailboxChanges() { + final accountId = mailboxDashBoardController.accountId.value; + if (accountId != null && currentMailboxState != null) { + consumeState(_refreshAllMailboxInteractor.execute(accountId, currentMailboxState!)); + } } void _buildTree(List folderMailboxList) async { diff --git a/lib/features/mailbox/presentation/mailbox_view.dart b/lib/features/mailbox/presentation/mailbox_view.dart index 41886849a..29d8ccca0 100644 --- a/lib/features/mailbox/presentation/mailbox_view.dart +++ b/lib/features/mailbox/presentation/mailbox_view.dart @@ -31,7 +31,7 @@ class MailboxView extends GetWidget { left: false, child: RefreshIndicator( color: AppColor.primaryColor, - onRefresh: () async => controller.refreshGetAllMailboxAction(), + onRefresh: () async => controller.refreshAllMailbox(), child: SingleChildScrollView( physics: AlwaysScrollableScrollPhysics(), child: Padding( diff --git a/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_controller.dart b/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_controller.dart index 2c7dbe871..30514ce96 100644 --- a/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_controller.dart +++ b/lib/features/mailbox_dashboard/presentation/mailbox_dashboard_controller.dart @@ -55,7 +55,7 @@ class MailboxDashBoardController extends BaseController { (failure) { if (failure is SendEmailFailure) { if (Get.context != null) { - _appToast.showSuccessToast(AppLocalizations.of(Get.context!).error_message_sent); + _appToast.showErrorToast(AppLocalizations.of(Get.context!).error_message_sent); clearState(); } } diff --git a/lib/main/bindings/local/local_bindings.dart b/lib/main/bindings/local/local_bindings.dart index 93ac94ca4..f01c99944 100644 --- a/lib/main/bindings/local/local_bindings.dart +++ b/lib/main/bindings/local/local_bindings.dart @@ -3,7 +3,7 @@ import 'package:core/core.dart'; import 'package:get/get.dart'; import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart'; import 'package:tmail_ui_user/features/caching/state_cache_client.dart'; -import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_cache_manager.dart'; +import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; class LocalBindings extends Bindings { @@ -20,6 +20,6 @@ class LocalBindings extends Bindings { void _bindingCaching() { Get.put(MailboxCacheClient()); Get.put(StateCacheClient()); - Get.put(MailboxCacheManager(Get.find(), Get.find())); + Get.put(MailboxCacheManager(Get.find())); } } \ No newline at end of file diff --git a/model/lib/caching/state/state_dao.dart b/model/lib/caching/state/state_dao.dart deleted file mode 100644 index b842aa7d8..000000000 --- a/model/lib/caching/state/state_dao.dart +++ /dev/null @@ -1,21 +0,0 @@ - -import 'package:equatable/equatable.dart'; -import 'package:hive/hive.dart'; -import 'package:model/model.dart'; - -part 'state_dao.g.dart'; - -@HiveType(typeId: CachingConstants.STATE_DAO_IDENTIFY) -class StateDao extends HiveObject with EquatableMixin { - - @HiveField(0) - final StateType type; - - @HiveField(1) - final String state; - - StateDao(this.type, this.state); - - @override - List get props => [type, state]; -} \ No newline at end of file diff --git a/model/lib/extensions/list_mailbox_extension.dart b/model/lib/extensions/list_mailbox_extension.dart new file mode 100644 index 000000000..4fcb2d441 --- /dev/null +++ b/model/lib/extensions/list_mailbox_extension.dart @@ -0,0 +1,13 @@ + +import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; + +extension ListMailboxExtension on List { + + Mailbox? findMailbox(MailboxId mailboxId) { + try { + return firstWhere((element) => element.id == mailboxId); + } catch (e) { + return null; + } + } +} \ No newline at end of file diff --git a/model/lib/extensions/mailbox_extension.dart b/model/lib/extensions/mailbox_extension.dart index 38be79f62..2e623c50e 100644 --- a/model/lib/extensions/mailbox_extension.dart +++ b/model/lib/extensions/mailbox_extension.dart @@ -23,22 +23,6 @@ extension MailboxExtension on Mailbox { ); } - MailboxCache toMailboxCache() { - return MailboxCache( - id.id.value, - name: name?.name, - parentId: parentId?.id.value, - role: role?.value, - sortOrder: sortOrder?.value.value.round(), - totalEmails: totalEmails?.value.value.round(), - unreadEmails: unreadEmails?.value.value.round(), - totalThreads: totalThreads?.value.value.round(), - unreadThreads: unreadThreads?.value.value.round(), - myRights: myRights != null ? myRights!.toMailboxRightsCache() : null, - isSubscribed: isSubscribed?.value - ); - } - Mailbox combineMailbox(Mailbox newMailbox, Properties updatedProperties) { return Mailbox( newMailbox.id, diff --git a/model/lib/extensions/state_extension.dart b/model/lib/extensions/state_extension.dart deleted file mode 100644 index 6f7c721d8..000000000 --- a/model/lib/extensions/state_extension.dart +++ /dev/null @@ -1,9 +0,0 @@ - -import 'package:jmap_dart_client/jmap/core/state.dart'; -import 'package:model/model.dart'; - -extension StateExtension on State { - StateDao toStateDao(StateType stateType) { - return StateDao(stateType, value); - } -} \ No newline at end of file diff --git a/model/lib/model.dart b/model/lib/model.dart index 21711d4c3..db70ffed1 100644 --- a/model/lib/model.dart +++ b/model/lib/model.dart @@ -44,12 +44,8 @@ export 'extensions/list_email_id_extension.dart'; export 'extensions/mailbox_id_extension.dart'; export 'extensions/mailbox_extension.dart'; export 'extensions/mailbox_name_extension.dart'; -export 'extensions/list_mailbox_cache_extension.dart'; -export 'extensions/state_extension.dart'; -export 'extensions/mailbox_rights_extension.dart'; -export 'extensions/mailbox_rights_cache_extension.dart'; -export 'extensions/mailbox_cache_extension.dart'; export 'extensions/properties_extension.dart'; +export 'extensions/list_mailbox_extension.dart'; // Download export 'download/download_task_id.dart'; @@ -61,10 +57,4 @@ export 'contact/device_contact.dart'; // Upload export 'upload/file_info.dart'; export 'upload/upload_request.dart'; -export 'upload/upload_response.dart'; - -// Caching -export 'caching/caching_constants.dart'; -export 'caching/mailbox/mailbox_cache.dart'; -export 'caching/state/state_dao.dart'; -export 'caching/state/state_type.dart'; \ No newline at end of file +export 'upload/upload_response.dart'; \ No newline at end of file diff --git a/model/pubspec.yaml b/model/pubspec.yaml index 4401c05b1..ef8a5b102 100644 --- a/model/pubspec.yaml +++ b/model/pubspec.yaml @@ -55,9 +55,6 @@ dependencies: # http_parser http_parser: 4.0.0 - # hive - hive: 2.0.4 - dev_dependencies: flutter_test: sdk: flutter @@ -65,8 +62,6 @@ dev_dependencies: build_runner: 2.0.5 json_serializable: 4.1.3 - - hive_generator: 1.1.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/pubspec.yaml b/pubspec.yaml index 455a5b5a2..71feb47e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -132,6 +132,8 @@ dev_dependencies: build_runner: 2.0.5 mockito: 5.0.10 + + hive_generator: 1.1.1 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec