TF-123 Implement refresh all mailbox

This commit is contained in:
dab246
2021-09-28 15:51:10 +07:00
committed by Dat H. Pham
parent 8f5171d581
commit eb29f514dc
52 changed files with 745 additions and 368 deletions
@@ -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<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) {
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
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
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
throw UnimplementedError();
}
@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 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) {
throw error;
});
@@ -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<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) {
Future<MailboxResponse> 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<MailboxCacheResponse> getAllMailboxCache() {
throw UnimplementedError();
}
@override
Future<void> asyncUpdateCache(MailboxChangeResponse mailboxChangeResponse) {
throw UnimplementedError();
}
@override
Future<MailboxChangeResponse> getChanges(AccountId accountId, State sinceState) {
return Future.sync(() async {
@@ -43,7 +32,12 @@ class MailboxDataSourceImpl extends MailboxDataSource {
}
@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();
}
}
@@ -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;
});
}
}