TF-123 Implement caching mailbox when get all mailbox
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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';
|
||||
|
||||
class MailboxCacheDataSourceImpl extends MailboxDataSource {
|
||||
|
||||
final MailboxCacheManager _mailboxCacheManager;
|
||||
|
||||
MailboxCacheDataSourceImpl(this._mailboxCacheManager);
|
||||
|
||||
@override
|
||||
Future<GetMailboxResponse?> 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) {
|
||||
return Future.sync(() async {
|
||||
return await _mailboxCacheManager.combineMailboxCache(mailboxChangeResponse, mailboxList);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,7 +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_api.dart';
|
||||
|
||||
class MailboxDataSourceImpl extends MailboxDataSource {
|
||||
@@ -11,11 +15,35 @@ class MailboxDataSourceImpl extends MailboxDataSource {
|
||||
MailboxDataSourceImpl(this.mailboxAPI,);
|
||||
|
||||
@override
|
||||
Future<List<Mailbox>> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
||||
Future<GetMailboxResponse?> getAllMailbox(AccountId accountId, {Properties? properties}) {
|
||||
return Future.sync(() async {
|
||||
return await mailboxAPI.getAllMailbox(accountId, properties: properties);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@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 {
|
||||
return await mailboxAPI.getChanges(accountId, sinceState);
|
||||
}).catchError((error) {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<MailboxChangeResponse> combineMailboxCache(MailboxChangeResponse mailboxChangeResponse, List<Mailbox> mailboxList) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user