TF-123 Implement refresh all mailbox
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
|
|
||||||
abstract class CacheConfig {
|
|
||||||
Future initializeDatabase();
|
|
||||||
|
|
||||||
void registerAdapter();
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
|
|
||||||
abstract class CacheClient<T> {
|
abstract class HiveCacheClient<T> {
|
||||||
|
|
||||||
String get tableName;
|
String get tableName;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ abstract class CacheClient<T> {
|
|||||||
|
|
||||||
Future<T?> getItem(String key);
|
Future<T?> getItem(String key);
|
||||||
|
|
||||||
Future<List<T>> getListItem();
|
Future<List<T>> getAll();
|
||||||
|
|
||||||
Future<void> updateItem(String key, T newObject);
|
Future<void> updateItem(String key, T newObject);
|
||||||
|
|
||||||
@@ -1,29 +1,28 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:hive/hive.dart';
|
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: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 {
|
Future setUp() async {
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
registerAdapter();
|
registerAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future initializeDatabase() async {
|
Future initializeDatabase() async {
|
||||||
Directory directory = await pathProvider.getApplicationDocumentsDirectory();
|
Directory directory = await pathProvider.getApplicationDocumentsDirectory();
|
||||||
Hive.init(directory.path);
|
Hive.init(directory.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void registerAdapter() {
|
void registerAdapter() {
|
||||||
Hive.registerAdapter(MailboxCacheAdapter());
|
Hive.registerAdapter(MailboxCacheAdapter());
|
||||||
Hive.registerAdapter(MailboxRightsCacheAdapter());
|
Hive.registerAdapter(MailboxRightsCacheAdapter());
|
||||||
Hive.registerAdapter(StateDaoAdapter());
|
Hive.registerAdapter(StateCacheAdapter());
|
||||||
Hive.registerAdapter(StateTypeAdapter());
|
Hive.registerAdapter(StateTypeAdapter());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/config/cache_client.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
|
||||||
|
|
||||||
class MailboxCacheClient extends CacheClient<MailboxCache> {
|
class MailboxCacheClient extends HiveCacheClient<MailboxCache> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get tableName => 'MailboxCache';
|
String get tableName => 'MailboxCache';
|
||||||
@@ -51,7 +51,7 @@ class MailboxCacheClient extends CacheClient<MailboxCache> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<MailboxCache>> getListItem() {
|
Future<List<MailboxCache>> getAll() {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxMailbox = await openTable();
|
final boxMailbox = await openTable();
|
||||||
return boxMailbox.values.toList();
|
return boxMailbox.values.toList();
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:tmail_ui_user/features/caching/config/hive_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/config/cache_client.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/state_cache.dart';
|
||||||
|
|
||||||
class StateCacheClient extends CacheClient<StateDao> {
|
class StateCacheClient extends HiveCacheClient<StateCache> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get tableName => 'StateCache';
|
String get tableName => 'StateCache';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<StateDao>> openTable() {
|
Future<Box<StateCache>> openTable() {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
if (Hive.isBoxOpen(tableName)) {
|
if (Hive.isBoxOpen(tableName)) {
|
||||||
return Hive.box<StateDao>(tableName);
|
return Hive.box<StateCache>(tableName);
|
||||||
}
|
}
|
||||||
return await Hive.openBox<StateDao>(tableName);
|
return await Hive.openBox<StateCache>(tableName);
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
@@ -41,7 +41,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<StateDao?> getItem(String key) {
|
Future<StateCache?> getItem(String key) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
return boxState.get(key);
|
return boxState.get(key);
|
||||||
@@ -51,7 +51,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<List<StateDao>> getListItem() {
|
Future<List<StateCache>> getAll() {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
return boxState.values.toList();
|
return boxState.values.toList();
|
||||||
@@ -61,7 +61,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> insertItem(String key, StateDao newObject) {
|
Future<void> insertItem(String key, StateCache newObject) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
boxState.put(key, newObject);
|
boxState.put(key, newObject);
|
||||||
@@ -71,7 +71,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> insertMultipleItem(Map<String, StateDao> mapObject) {
|
Future<void> insertMultipleItem(Map<String, StateCache> mapObject) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
boxState.putAll(mapObject);
|
boxState.putAll(mapObject);
|
||||||
@@ -81,7 +81,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateItem(String key, StateDao newObject) {
|
Future<void> updateItem(String key, StateCache newObject) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
boxState.put(key, newObject);
|
boxState.put(key, newObject);
|
||||||
@@ -110,7 +110,7 @@ class StateCacheClient extends CacheClient<StateDao> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> updateMultipleItem(Map<String, StateDao> mapObject) {
|
Future<void> updateMultipleItem(Map<String, StateCache> mapObject) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
final boxState = await openTable();
|
final boxState = await openTable();
|
||||||
boxState.putAll(mapObject);
|
boxState.putAll(mapObject);
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ class ComposerController extends BaseController {
|
|||||||
} else if (fromEmailAddress != null && fromEmailAddress.isNotEmpty) {
|
} else if (fromEmailAddress != null && fromEmailAddress.isNotEmpty) {
|
||||||
listReplyToEmailAddress.value = fromEmailAddress.toList();
|
listReplyToEmailAddress.value = fromEmailAddress.toList();
|
||||||
}
|
}
|
||||||
|
listToEmailAddress = listReplyToEmailAddress;
|
||||||
}
|
}
|
||||||
_updateStatusEmailSendButton();
|
_updateStatusEmailSendButton();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:get/get.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/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/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_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/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_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/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/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/get_all_mailbox_interactor.dart';
|
||||||
@@ -17,10 +20,15 @@ class DestinationPickerBindings extends Bindings {
|
|||||||
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>()));
|
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>()));
|
||||||
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
||||||
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
|
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
|
||||||
Get.lazyPut(() => MailboxRepositoryImpl({
|
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
|
||||||
DataSourceType.network: Get.find<MailboxDataSource>(),
|
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
|
||||||
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>(),
|
Get.lazyPut(() => MailboxRepositoryImpl(
|
||||||
}));
|
{
|
||||||
|
DataSourceType.network: Get.find<MailboxDataSource>(),
|
||||||
|
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
|
||||||
|
},
|
||||||
|
Get.find<StateDataSource>()
|
||||||
|
));
|
||||||
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
||||||
Get.lazyPut(() => GetAllMailboxInteractor(Get.find<MailboxRepository>()));
|
Get.lazyPut(() => GetAllMailboxInteractor(Get.find<MailboxRepository>()));
|
||||||
Get.lazyPut(() => TreeBuilder());
|
Get.lazyPut(() => TreeBuilder());
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import 'package:jmap_dart_client/jmap/account_id.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/properties/properties.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/state.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: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_change_response.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart';
|
||||||
|
|
||||||
abstract class MailboxDataSource {
|
abstract class MailboxDataSource {
|
||||||
Future<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties});
|
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties});
|
||||||
|
|
||||||
|
Future<List<Mailbox>> getAllMailboxCache();
|
||||||
|
|
||||||
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState);
|
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState);
|
||||||
|
|
||||||
Future<MailboxCacheResponse> getAllMailboxCache();
|
Future<void> update({List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed});
|
||||||
|
|
||||||
Future<MailboxChangeResponse> combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List<Mailbox> mailboxList);
|
|
||||||
|
|
||||||
Future<void> asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse);
|
|
||||||
}
|
}
|
||||||
@@ -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<State?> getState(StateType stateType);
|
||||||
|
|
||||||
|
Future<void> saveState(StateCache stateCache);
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
import 'package:jmap_dart_client/jmap/account_id.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/properties/properties.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/state.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: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/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_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 {
|
class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
||||||
|
|
||||||
@@ -15,37 +14,28 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
|||||||
MailboxCacheDataSourceImpl(this._mailboxCacheManager);
|
MailboxCacheDataSourceImpl(this._mailboxCacheManager);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<MailboxCacheResponse> getAllMailboxCache() {
|
|
||||||
return Future.sync(() async {
|
|
||||||
return await _mailboxCacheManager.getAllMailbox();
|
|
||||||
}).catchError((error) {
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) {
|
|
||||||
return Future.sync(() async {
|
|
||||||
return await _mailboxCacheManager.asyncUpdateCache(mailboxChangeResponse);
|
|
||||||
}).catchError((error) {
|
|
||||||
throw error;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
|
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MailboxChangeResponse> combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List<Mailbox> mailboxList) {
|
Future<void> update({List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||||
return Future.sync(() async {
|
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<List<Mailbox>> getAllMailboxCache() {
|
||||||
|
return Future.sync(() async {
|
||||||
|
return await _mailboxCacheManager.getAllMailbox();
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,21 +1,20 @@
|
|||||||
import 'package:jmap_dart_client/jmap/account_id.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/properties/properties.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/state.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: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/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_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';
|
import 'package:tmail_ui_user/features/mailbox/data/network/mailbox_api.dart';
|
||||||
|
|
||||||
class MailboxDataSourceImpl extends MailboxDataSource {
|
class MailboxDataSourceImpl extends MailboxDataSource {
|
||||||
|
|
||||||
final MailboxAPI mailboxAPI;
|
final MailboxAPI mailboxAPI;
|
||||||
|
|
||||||
MailboxDataSourceImpl(this.mailboxAPI,);
|
MailboxDataSourceImpl(this.mailboxAPI);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
return await mailboxAPI.getAllMailbox(accountId, properties: properties);
|
return await mailboxAPI.getAllMailbox(accountId, properties: properties);
|
||||||
}).catchError((error) {
|
}).catchError((error) {
|
||||||
@@ -23,16 +22,6 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
Future<MailboxCacheResponse> getAllMailboxCache() {
|
|
||||||
throw UnimplementedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<void> asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) {
|
|
||||||
throw UnimplementedError();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
|
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
|
||||||
return Future.sync(() async {
|
return Future.sync(() async {
|
||||||
@@ -43,7 +32,12 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<MailboxChangeResponse> combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List<Mailbox> mailboxList) {
|
Future<void> update({List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Mailbox>> getAllMailboxCache() {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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<State?> 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<void> 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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-6
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_cache.dart';
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
extension ListMailboxCacheExtension on List<MailboxCache> {
|
extension ListMailboxCacheExtension on List<MailboxCache> {
|
||||||
Map<String, MailboxCache> toMap() {
|
Map<String, MailboxCache> toMap() {
|
||||||
@@ -9,8 +8,4 @@ extension ListMailboxCacheExtension on List<MailboxCache> {
|
|||||||
key: (mailboxCache) => mailboxCache.id,
|
key: (mailboxCache) => mailboxCache.id,
|
||||||
value: (mailboxCache) => mailboxCache);
|
value: (mailboxCache) => mailboxCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Mailbox> toMailboxList() {
|
|
||||||
return map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -2,7 +2,8 @@
|
|||||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
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/core/unsigned_int.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.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 {
|
extension MailboxCacheExtension on MailboxCache {
|
||||||
Mailbox toMailbox() {
|
Mailbox toMailbox() {
|
||||||
@@ -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<Mailbox>? updatedMailbox) {
|
||||||
|
return MailboxChangeResponse(
|
||||||
|
updated: updatedMailbox,
|
||||||
|
created: created,
|
||||||
|
destroyed: destroyed,
|
||||||
|
newStateMailbox: newStateMailbox,
|
||||||
|
newStateChanges: newStateChanges,
|
||||||
|
hasMoreChanges: hasMoreChanges,
|
||||||
|
updatedProperties: updatedProperties
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
|
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 {
|
extension MailboxRightsCacheExtension on MailboxRightsCache {
|
||||||
MailboxRights toMailboxRights() {
|
MailboxRights toMailboxRights() {
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox_rights.dart';
|
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 {
|
extension MailboxRightsExtension on MailboxRights {
|
||||||
MailboxRightsCache toMailboxRightsCache() {
|
MailboxRightsCache toMailboxRightsCache() {
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<List<Mailbox>> getAllMailbox() async {
|
||||||
|
final mailboxCacheList = await _mailboxCacheClient.getAll();
|
||||||
|
final mailboxList = mailboxCacheList.map((mailboxCache) => mailboxCache.toMailbox()).toList();
|
||||||
|
return mailboxList;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> update({List<Mailbox>? updated, List<Mailbox>? created, List<MailboxId>? destroyed}) async {
|
||||||
|
final mailboxCacheExist = await _mailboxCacheClient.isExistTable();
|
||||||
|
if (mailboxCacheExist) {
|
||||||
|
final updatedCacheMailboxes = updated
|
||||||
|
?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? <MailboxCache>[];
|
||||||
|
final createdCacheMailboxes = created
|
||||||
|
?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? <MailboxCache>[];
|
||||||
|
final destroyedCacheMailboxes = destroyed
|
||||||
|
?.map((mailboxId) => mailboxId.id.value).toList() ?? <String>[];
|
||||||
|
await Future.wait([
|
||||||
|
_mailboxCacheClient.updateMultipleItem(updatedCacheMailboxes.toMap()),
|
||||||
|
_mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()),
|
||||||
|
_mailboxCacheClient.deleteMultipleItem(destroyedCacheMailboxes)
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
final createdCacheMailboxes = created
|
||||||
|
?.map((mailbox) => mailbox.toMailboxCache()).toList() ?? <MailboxCache>[];
|
||||||
|
await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:model/caching/mailbox/mailbox_rights_cache.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_rights_cache.dart';
|
||||||
import 'package:model/model.dart';
|
import 'package:tmail_ui_user/features/mailbox/data/utils/caching_constants.dart';
|
||||||
|
|
||||||
part 'mailbox_cache.g.dart';
|
part '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<MailboxCache> {
|
||||||
|
@override
|
||||||
|
final int typeId = 1;
|
||||||
|
|
||||||
|
@override
|
||||||
|
MailboxCache read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:model/model.dart';
|
|
||||||
|
|
||||||
class MailboxCacheResponse with EquatableMixin {
|
|
||||||
final List<MailboxCache>? mailboxCaches;
|
|
||||||
final StateDao? oldState;
|
|
||||||
|
|
||||||
MailboxCacheResponse({
|
|
||||||
this.mailboxCaches,
|
|
||||||
this.oldState
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object?> get props => [mailboxCaches, oldState];
|
|
||||||
}
|
|
||||||
@@ -8,17 +8,29 @@ class MailboxChangeResponse with EquatableMixin {
|
|||||||
final List<Mailbox>? updated;
|
final List<Mailbox>? updated;
|
||||||
final List<Mailbox>? created;
|
final List<Mailbox>? created;
|
||||||
final List<MailboxId>? destroyed;
|
final List<MailboxId>? destroyed;
|
||||||
final State? newState;
|
final State? newStateMailbox;
|
||||||
|
final State? newStateChanges;
|
||||||
|
final bool hasMoreChanges;
|
||||||
final Properties? updatedProperties;
|
final Properties? updatedProperties;
|
||||||
|
|
||||||
MailboxChangeResponse({
|
MailboxChangeResponse({
|
||||||
this.updated,
|
this.updated,
|
||||||
this.created,
|
this.created,
|
||||||
this.destroyed,
|
this.destroyed,
|
||||||
this.newState,
|
this.newStateMailbox,
|
||||||
|
this.newStateChanges,
|
||||||
|
this.hasMoreChanges = false,
|
||||||
this.updatedProperties,
|
this.updatedProperties,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [updated, created, destroyed, newState, updatedProperties];
|
List<Object?> get props => [
|
||||||
|
updated,
|
||||||
|
created,
|
||||||
|
destroyed,
|
||||||
|
newStateMailbox,
|
||||||
|
newStateChanges,
|
||||||
|
hasMoreChanges,
|
||||||
|
updatedProperties
|
||||||
|
];
|
||||||
}
|
}
|
||||||
@@ -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<Mailbox>? mailboxes;
|
||||||
|
final State? state;
|
||||||
|
|
||||||
|
MailboxResponse({
|
||||||
|
this.mailboxes,
|
||||||
|
this.state
|
||||||
|
});
|
||||||
|
|
||||||
|
bool hasData() {
|
||||||
|
return mailboxes != null
|
||||||
|
&& mailboxes!.isNotEmpty
|
||||||
|
&& state != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [mailboxes, state];
|
||||||
|
}
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:hive/hive.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';
|
part '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<MailboxRightsCache> {
|
||||||
|
@override
|
||||||
|
final int typeId = 2;
|
||||||
|
|
||||||
|
@override
|
||||||
|
MailboxRightsCache read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -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<Object?> get props => [type, state];
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'state_cache.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// TypeAdapterGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class StateCacheAdapter extends TypeAdapter<StateCache> {
|
||||||
|
@override
|
||||||
|
final int typeId = 3;
|
||||||
|
|
||||||
|
@override
|
||||||
|
StateCache read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
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;
|
||||||
|
}
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import 'package:hive/hive.dart';
|
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';
|
part '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<StateType> {
|
||||||
|
@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;
|
||||||
|
}
|
||||||
@@ -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/get/get_mailbox_response.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.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_change_response.dart';
|
||||||
|
import 'package:tmail_ui_user/features/mailbox/data/model/mailbox_response.dart';
|
||||||
|
|
||||||
class MailboxAPI {
|
class MailboxAPI {
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ class MailboxAPI {
|
|||||||
|
|
||||||
MailboxAPI(this.httpClient);
|
MailboxAPI(this.httpClient);
|
||||||
|
|
||||||
Future<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) async {
|
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) async {
|
||||||
final processingInvocation = ProcessingInvocation();
|
final processingInvocation = ProcessingInvocation();
|
||||||
|
|
||||||
final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);
|
final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);
|
||||||
@@ -38,7 +39,7 @@ class MailboxAPI {
|
|||||||
queryInvocation.methodCallId,
|
queryInvocation.methodCallId,
|
||||||
GetMailboxResponse.deserialize);
|
GetMailboxResponse.deserialize);
|
||||||
|
|
||||||
return resultCreated;
|
return MailboxResponse(mailboxes: resultCreated?.list, state: resultCreated?.state);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) async {
|
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) async {
|
||||||
@@ -85,19 +86,13 @@ class MailboxAPI {
|
|||||||
|
|
||||||
final listMailboxIdDestroyed = resultChanges?.destroyed.map((id) => MailboxId(id)).toList() ?? <MailboxId>[];
|
final listMailboxIdDestroyed = resultChanges?.destroyed.map((id) => MailboxId(id)).toList() ?? <MailboxId>[];
|
||||||
|
|
||||||
final updatedProperties = resultChanges?.updatedProperties;
|
|
||||||
|
|
||||||
final listMailboxUpdated = resultUpdated?.list ?? <Mailbox>[];
|
|
||||||
|
|
||||||
final listMailboxCreated = resultCreated?.list ?? <Mailbox>[];
|
|
||||||
|
|
||||||
final newState = resultChanges?.newState;
|
|
||||||
|
|
||||||
return MailboxChangeResponse(
|
return MailboxChangeResponse(
|
||||||
updated: listMailboxUpdated,
|
updated: resultUpdated?.list,
|
||||||
created: listMailboxCreated,
|
created: resultCreated?.list,
|
||||||
destroyed: listMailboxIdDestroyed,
|
destroyed: listMailboxIdDestroyed,
|
||||||
newState: newState,
|
newStateMailbox: resultUpdated?.state,
|
||||||
updatedProperties: updatedProperties);
|
newStateChanges: resultChanges?.newState,
|
||||||
|
hasMoreChanges: resultChanges?.hasMoreChanges ?? false,
|
||||||
|
updatedProperties: resultChanges?.updatedProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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<MailboxCacheResponse> 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<MailboxChangeResponse> combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List<Mailbox> 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<Mailbox> mailboxList) {
|
|
||||||
try {
|
|
||||||
return mailboxList.firstWhere((element) => element.id == mailboxId);
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> 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() ?? <MailboxCache>[];
|
|
||||||
final createdCacheMailboxes = mailboxChangeResponse.created
|
|
||||||
?.map((mailbox) => mailbox.toMailboxCache())
|
|
||||||
.toList() ?? <MailboxCache>[];
|
|
||||||
final destroyedCacheMailboxes = mailboxChangeResponse.destroyed
|
|
||||||
?.map((mailboxId) => mailboxId.id.value)
|
|
||||||
.toList() ?? <String>[];
|
|
||||||
await Future.wait([
|
|
||||||
_mailboxCacheClient.updateMultipleItem(updatedCacheMailboxes.toMap()),
|
|
||||||
_mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap()),
|
|
||||||
_mailboxCacheClient.deleteMultipleItem(destroyedCacheMailboxes)
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
final createdCacheMailboxes = mailboxChangeResponse.created
|
|
||||||
?.map((mailbox) => mailbox.toMailboxCache())
|
|
||||||
.toList() ?? <MailboxCache>[];
|
|
||||||
await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes.toMap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +1,137 @@
|
|||||||
import 'package:core/core.dart';
|
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/account_id.dart';
|
||||||
import 'package:jmap_dart_client/jmap/core/properties/properties.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/core/state.dart';
|
||||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.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/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';
|
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
|
||||||
|
|
||||||
class MailboxRepositoryImpl extends MailboxRepository {
|
class MailboxRepositoryImpl extends MailboxRepository {
|
||||||
|
|
||||||
final Map<DataSourceType, MailboxDataSource> mapDataSource;
|
final Map<DataSourceType, MailboxDataSource> mapDataSource;
|
||||||
|
final StateDataSource stateDataSource;
|
||||||
|
|
||||||
MailboxRepositoryImpl(this.mapDataSource);
|
MailboxRepositoryImpl(this.mapDataSource, this.stateDataSource);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<List<Mailbox>> getAllMailbox(AccountId accountId, {Properties? properties}) async* {
|
Stream<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) async* {
|
||||||
final mailboxCacheResponse = await mapDataSource[DataSourceType.local]!.getAllMailboxCache();
|
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
|
yield localMailboxResponse;
|
||||||
? mailboxCacheResponse.mailboxCaches!.toMailboxList()
|
|
||||||
: <Mailbox>[];
|
|
||||||
final oldState = mailboxCacheResponse.oldState?.state;
|
|
||||||
|
|
||||||
yield mailboxList;
|
if (localMailboxResponse.hasData()) {
|
||||||
|
bool hasMoreChanges = true;
|
||||||
|
State? sinceState = localMailboxResponse.state!;
|
||||||
|
|
||||||
if (mailboxList.isNotEmpty && oldState != null) {
|
while(hasMoreChanges && sinceState != null) {
|
||||||
final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, State(oldState));
|
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 {
|
} else {
|
||||||
final getMailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(accountId);
|
final mailboxResponse = await mapDataSource[DataSourceType.network]!.getAllMailbox(accountId);
|
||||||
|
|
||||||
await mapDataSource[DataSourceType.local]!.asyncUpdateCache(MailboxChangeResponse(
|
await Future.wait([
|
||||||
created: getMailboxResponse?.list,
|
mapDataSource[DataSourceType.local]!.update(created: mailboxResponse.mailboxes),
|
||||||
newState: getMailboxResponse?.state));
|
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
|
yield newMailboxResponse;
|
||||||
? newMailboxCacheResponse.mailboxCaches!.toMailboxList()
|
}
|
||||||
: <Mailbox>[];
|
|
||||||
|
|
||||||
yield newMailboxList;
|
Future<List<Mailbox>?> _combineMailboxCache({
|
||||||
|
List<Mailbox>? mailboxUpdated,
|
||||||
|
Properties? updatedProperties,
|
||||||
|
List<Mailbox>? 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
|
@override
|
||||||
Stream<List<Mailbox>> refresh(AccountId accountId, State currentState) async* {
|
Stream<MailboxResponse> refresh(AccountId accountId, State currentState) async* {
|
||||||
final changesResponse = await mapDataSource[DataSourceType.network]!.getChanges(accountId, currentState);
|
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
|
hasMoreChanges = changesResponse.hasMoreChanges;
|
||||||
? newMailboxCacheResponse.mailboxCaches!.toMailboxList()
|
sinceState = changesResponse.newStateChanges;
|
||||||
: <Mailbox>[];
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -2,6 +2,6 @@
|
|||||||
class CachingConstants {
|
class CachingConstants {
|
||||||
static const int MAILBOX_CACHE_IDENTIFY = 1;
|
static const int MAILBOX_CACHE_IDENTIFY = 1;
|
||||||
static const int MAILBOX_RIGHTS_CACHE_IDENTIFY = 2;
|
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;
|
static const int STATE_TYPE_IDENTIFY = 4;
|
||||||
}
|
}
|
||||||
@@ -1,10 +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/core/properties/properties.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/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 {
|
abstract class MailboxRepository {
|
||||||
Stream<List<Mailbox>> getAllMailbox(AccountId accountId, {Properties? properties});
|
Stream<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties});
|
||||||
|
|
||||||
Stream<List<Mailbox>> refresh(AccountId accountId, State currentState);
|
Stream<MailboxResponse> refresh(AccountId accountId, State currentState);
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,20 @@
|
|||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
|
import 'package:jmap_dart_client/jmap/core/state.dart';
|
||||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||||
|
|
||||||
class GetAllMailboxSuccess extends UIState {
|
class GetAllMailboxSuccess extends UIState {
|
||||||
final List<PresentationMailbox> defaultMailboxList;
|
final List<PresentationMailbox> defaultMailboxList;
|
||||||
final List<PresentationMailbox> folderMailboxList;
|
final List<PresentationMailbox> folderMailboxList;
|
||||||
|
final State? currentMailboxState;
|
||||||
|
|
||||||
GetAllMailboxSuccess({required this.defaultMailboxList, required this.folderMailboxList});
|
GetAllMailboxSuccess({
|
||||||
|
required this.defaultMailboxList,
|
||||||
|
required this.folderMailboxList,
|
||||||
|
required this.currentMailboxState
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [folderMailboxList];
|
List<Object?> get props => [defaultMailboxList, folderMailboxList, currentMailboxState];
|
||||||
}
|
}
|
||||||
|
|
||||||
class GetAllMailboxFailure extends FeatureFailure {
|
class GetAllMailboxFailure extends FeatureFailure {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:core/core.dart';
|
|||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:jmap_dart_client/jmap/account_id.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/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/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/state/get_all_mailboxes_state.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_extension.dart';
|
import 'package:tmail_ui_user/features/mailbox/domain/extensions/list_mailbox_extension.dart';
|
||||||
@@ -16,18 +17,21 @@ class GetAllMailboxInteractor {
|
|||||||
try {
|
try {
|
||||||
yield Right<Failure, Success>(LoadingState());
|
yield Right<Failure, Success>(LoadingState());
|
||||||
|
|
||||||
final streamListMailbox = _mailboxRepository.getAllMailbox(accountId, properties: properties);
|
yield* _mailboxRepository
|
||||||
|
.getAllMailbox(accountId, properties: properties)
|
||||||
final streamResult = streamListMailbox.asyncExpand((mailboxList) async* {
|
.map(_toGetMailboxState);
|
||||||
final tupleList = mailboxList.splitMailboxList((mailbox) => mailbox.hasRole());
|
|
||||||
yield Right<Failure, Success>(GetAllMailboxSuccess(
|
|
||||||
defaultMailboxList: tupleList.value1,
|
|
||||||
folderMailboxList: tupleList.value2));
|
|
||||||
});
|
|
||||||
|
|
||||||
yield* streamResult;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yield Left<Failure, Success>(GetAllMailboxFailure(e));
|
yield Left<Failure, Success>(GetAllMailboxFailure(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Either<Failure, Success> _toGetMailboxState(MailboxResponse mailboxResponse) {
|
||||||
|
final tupleList = mailboxResponse.mailboxes
|
||||||
|
?.splitMailboxList((mailbox) => mailbox.hasRole()) ?? Tuple2([], []);
|
||||||
|
|
||||||
|
return Right<Failure, Success>(GetAllMailboxSuccess(
|
||||||
|
defaultMailboxList: tupleList.value1,
|
||||||
|
folderMailboxList: tupleList.value2,
|
||||||
|
currentMailboxState: mailboxResponse.state));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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<Either<Failure, Success>> execute(AccountId accountId, jmapState.State currentState) async* {
|
||||||
|
try {
|
||||||
|
yield Right<Failure, Success>(LoadingState());
|
||||||
|
|
||||||
|
yield* _mailboxRepository
|
||||||
|
.refresh(accountId, currentState)
|
||||||
|
.map(_toGetMailboxState);
|
||||||
|
} catch (e) {
|
||||||
|
yield Left<Failure, Success>(GetAllMailboxFailure(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Either<Failure, Success> _toGetMailboxState(MailboxResponse mailboxResponse) {
|
||||||
|
final tupleList = mailboxResponse.mailboxes
|
||||||
|
?.splitMailboxList((mailbox) => mailbox.hasRole()) ?? Tuple2([], []);
|
||||||
|
|
||||||
|
return Right<Failure, Success>(GetAllMailboxSuccess(
|
||||||
|
defaultMailboxList: tupleList.value1,
|
||||||
|
folderMailboxList: tupleList.value2,
|
||||||
|
currentMailboxState: mailboxResponse.state));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,21 @@
|
|||||||
import 'package:core/core.dart';
|
import 'package:core/core.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.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/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/repository/credential_repository.dart';
|
||||||
import 'package:tmail_ui_user/features/login/domain/usecases/delete_credential_interactor.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/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_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/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_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/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/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/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/mailbox_controller.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.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<MailboxAPI>()));
|
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>()));
|
||||||
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
Get.lazyPut<MailboxDataSource>(() => Get.find<MailboxDataSourceImpl>());
|
||||||
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
|
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
|
||||||
Get.lazyPut(() => MailboxRepositoryImpl({
|
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
|
||||||
DataSourceType.network: Get.find<MailboxDataSource>(),
|
Get.lazyPut<StateDataSource>(() => Get.find<StateDataSourceImpl>());
|
||||||
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>(),
|
Get.lazyPut(() => MailboxRepositoryImpl(
|
||||||
}));
|
{
|
||||||
|
DataSourceType.network: Get.find<MailboxDataSource>(),
|
||||||
|
DataSourceType.local: Get.find<MailboxCacheDataSourceImpl>()
|
||||||
|
},
|
||||||
|
Get.find<StateDataSource>()
|
||||||
|
));
|
||||||
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
Get.lazyPut<MailboxRepository>(() => Get.find<MailboxRepositoryImpl>());
|
||||||
Get.lazyPut(() => GetAllMailboxInteractor(Get.find<MailboxRepository>()));
|
Get.lazyPut(() => GetAllMailboxInteractor(Get.find<MailboxRepository>()));
|
||||||
|
Get.lazyPut(() => RefreshAllMailboxInteractor(Get.find<MailboxRepository>()));
|
||||||
Get.lazyPut(() => TreeBuilder());
|
Get.lazyPut(() => TreeBuilder());
|
||||||
Get.put(MailboxController(
|
Get.put(MailboxController(
|
||||||
Get.find<GetAllMailboxInteractor>(),
|
Get.find<GetAllMailboxInteractor>(),
|
||||||
Get.find<DeleteCredentialInteractor>(),
|
Get.find<DeleteCredentialInteractor>(),
|
||||||
|
Get.find<RefreshAllMailboxInteractor>(),
|
||||||
Get.find<TreeBuilder>(),
|
Get.find<TreeBuilder>(),
|
||||||
Get.find<ResponsiveUtils>()));
|
Get.find<ResponsiveUtils>()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/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/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/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_node.dart';
|
||||||
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.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';
|
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/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/app_routes.dart';
|
||||||
import 'package:tmail_ui_user/main/routes/route_navigation.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 {
|
class MailboxController extends BaseController {
|
||||||
|
|
||||||
final mailboxDashBoardController = Get.find<MailboxDashBoardController>();
|
final mailboxDashBoardController = Get.find<MailboxDashBoardController>();
|
||||||
final GetAllMailboxInteractor _getAllMailboxInteractor;
|
final GetAllMailboxInteractor _getAllMailboxInteractor;
|
||||||
final DeleteCredentialInteractor _deleteCredentialInteractor;
|
final DeleteCredentialInteractor _deleteCredentialInteractor;
|
||||||
|
final RefreshAllMailboxInteractor _refreshAllMailboxInteractor;
|
||||||
final TreeBuilder _treeBuilder;
|
final TreeBuilder _treeBuilder;
|
||||||
final ResponsiveUtils responsiveUtils;
|
final ResponsiveUtils responsiveUtils;
|
||||||
|
|
||||||
final defaultMailboxList = <PresentationMailbox>[].obs;
|
final defaultMailboxList = <PresentationMailbox>[].obs;
|
||||||
final folderMailboxNodeList = <MailboxNode>[].obs;
|
final folderMailboxNodeList = <MailboxNode>[].obs;
|
||||||
|
|
||||||
|
jmapState.State? currentMailboxState;
|
||||||
|
|
||||||
MailboxController(
|
MailboxController(
|
||||||
this._getAllMailboxInteractor,
|
this._getAllMailboxInteractor,
|
||||||
this._deleteCredentialInteractor,
|
this._deleteCredentialInteractor,
|
||||||
|
this._refreshAllMailboxInteractor,
|
||||||
this._treeBuilder,
|
this._treeBuilder,
|
||||||
this.responsiveUtils
|
this.responsiveUtils
|
||||||
);
|
);
|
||||||
@@ -52,11 +58,11 @@ class MailboxController extends BaseController {
|
|||||||
if (success is MarkAsEmailReadSuccess ||
|
if (success is MarkAsEmailReadSuccess ||
|
||||||
success is MarkAsMultipleEmailReadAllSuccess ||
|
success is MarkAsMultipleEmailReadAllSuccess ||
|
||||||
success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
success is MarkAsMultipleEmailReadHasSomeEmailFailure) {
|
||||||
refreshGetAllMailboxAction();
|
refreshMailboxChanges();
|
||||||
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
} else if (success is MoveMultipleEmailToMailboxAllSuccess
|
||||||
|| success is MoveMultipleEmailToMailboxHasSomeEmailFailure) {
|
|| success is MoveMultipleEmailToMailboxHasSomeEmailFailure) {
|
||||||
mailboxDashBoardController.clearState();
|
mailboxDashBoardController.clearState();
|
||||||
refreshGetAllMailboxAction();
|
refreshMailboxChanges();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -68,17 +74,6 @@ class MailboxController extends BaseController {
|
|||||||
super.onClose();
|
super.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void refreshGetAllMailboxAction() {
|
|
||||||
final accountId = mailboxDashBoardController.accountId.value;
|
|
||||||
if (accountId != null) {
|
|
||||||
getAllMailboxAction(accountId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getAllMailboxAction(AccountId accountId) async {
|
|
||||||
consumeState(_getAllMailboxInteractor.execute(accountId));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onData(Either<Failure, Success> newState) {
|
void onData(Either<Failure, Success> newState) {
|
||||||
super.onData(newState);
|
super.onData(newState);
|
||||||
@@ -93,6 +88,7 @@ class MailboxController extends BaseController {
|
|||||||
void onDone() {
|
void onDone() {
|
||||||
viewState.value.map((success) {
|
viewState.value.map((success) {
|
||||||
if (success is GetAllMailboxSuccess) {
|
if (success is GetAllMailboxSuccess) {
|
||||||
|
currentMailboxState = success.currentMailboxState;
|
||||||
defaultMailboxList.value = success.defaultMailboxList;
|
defaultMailboxList.value = success.defaultMailboxList;
|
||||||
_setUpMapMailboxIdDefault(success.defaultMailboxList);
|
_setUpMapMailboxIdDefault(success.defaultMailboxList);
|
||||||
}
|
}
|
||||||
@@ -100,8 +96,24 @@ class MailboxController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onError(error) {
|
void onError(error) {}
|
||||||
print('$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<PresentationMailbox> folderMailboxList) async {
|
void _buildTree(List<PresentationMailbox> folderMailboxList) async {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class MailboxView extends GetWidget<MailboxController> {
|
|||||||
left: false,
|
left: false,
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
color: AppColor.primaryColor,
|
color: AppColor.primaryColor,
|
||||||
onRefresh: () async => controller.refreshGetAllMailboxAction(),
|
onRefresh: () async => controller.refreshAllMailbox(),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
physics: AlwaysScrollableScrollPhysics(),
|
physics: AlwaysScrollableScrollPhysics(),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class MailboxDashBoardController extends BaseController {
|
|||||||
(failure) {
|
(failure) {
|
||||||
if (failure is SendEmailFailure) {
|
if (failure is SendEmailFailure) {
|
||||||
if (Get.context != null) {
|
if (Get.context != null) {
|
||||||
_appToast.showSuccessToast(AppLocalizations.of(Get.context!).error_message_sent);
|
_appToast.showErrorToast(AppLocalizations.of(Get.context!).error_message_sent);
|
||||||
clearState();
|
clearState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import 'package:core/core.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.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/caching/state_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 {
|
class LocalBindings extends Bindings {
|
||||||
|
|
||||||
@@ -20,6 +20,6 @@ class LocalBindings extends Bindings {
|
|||||||
void _bindingCaching() {
|
void _bindingCaching() {
|
||||||
Get.put(MailboxCacheClient());
|
Get.put(MailboxCacheClient());
|
||||||
Get.put(StateCacheClient());
|
Get.put(StateCacheClient());
|
||||||
Get.put(MailboxCacheManager(Get.find<MailboxCacheClient>(), Get.find<StateCacheClient>()));
|
Get.put(MailboxCacheManager(Get.find<MailboxCacheClient>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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<Object?> get props => [type, state];
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||||
|
|
||||||
|
extension ListMailboxExtension on List<Mailbox> {
|
||||||
|
|
||||||
|
Mailbox? findMailbox(MailboxId mailboxId) {
|
||||||
|
try {
|
||||||
|
return firstWhere((element) => element.id == mailboxId);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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) {
|
Mailbox combineMailbox(Mailbox newMailbox, Properties updatedProperties) {
|
||||||
return Mailbox(
|
return Mailbox(
|
||||||
newMailbox.id,
|
newMailbox.id,
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-12
@@ -44,12 +44,8 @@ export 'extensions/list_email_id_extension.dart';
|
|||||||
export 'extensions/mailbox_id_extension.dart';
|
export 'extensions/mailbox_id_extension.dart';
|
||||||
export 'extensions/mailbox_extension.dart';
|
export 'extensions/mailbox_extension.dart';
|
||||||
export 'extensions/mailbox_name_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/properties_extension.dart';
|
||||||
|
export 'extensions/list_mailbox_extension.dart';
|
||||||
|
|
||||||
// Download
|
// Download
|
||||||
export 'download/download_task_id.dart';
|
export 'download/download_task_id.dart';
|
||||||
@@ -61,10 +57,4 @@ export 'contact/device_contact.dart';
|
|||||||
// Upload
|
// Upload
|
||||||
export 'upload/file_info.dart';
|
export 'upload/file_info.dart';
|
||||||
export 'upload/upload_request.dart';
|
export 'upload/upload_request.dart';
|
||||||
export 'upload/upload_response.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';
|
|
||||||
@@ -55,9 +55,6 @@ dependencies:
|
|||||||
# http_parser
|
# http_parser
|
||||||
http_parser: 4.0.0
|
http_parser: 4.0.0
|
||||||
|
|
||||||
# hive
|
|
||||||
hive: 2.0.4
|
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
@@ -65,8 +62,6 @@ dev_dependencies:
|
|||||||
build_runner: 2.0.5
|
build_runner: 2.0.5
|
||||||
|
|
||||||
json_serializable: 4.1.3
|
json_serializable: 4.1.3
|
||||||
|
|
||||||
hive_generator: 1.1.1
|
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
|||||||
@@ -132,6 +132,8 @@ dev_dependencies:
|
|||||||
build_runner: 2.0.5
|
build_runner: 2.0.5
|
||||||
|
|
||||||
mockito: 5.0.10
|
mockito: 5.0.10
|
||||||
|
|
||||||
|
hive_generator: 1.1.1
|
||||||
# For information on the generic Dart part of this file, see the
|
# For information on the generic Dart part of this file, see the
|
||||||
# following page: https://dart.dev/tools/pub/pubspec
|
# following page: https://dart.dev/tools/pub/pubspec
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user