Get spam mailbox cache by AccountId
(cherry picked from commit c35685bf34f5f4fbf28c4cbca9842c20dee61ffc)
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/list_mailbox_id_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/data/extensions/mailbox_cache_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart';
|
||||
|
||||
class MailboxCacheManager {
|
||||
@@ -42,12 +41,13 @@ class MailboxCacheManager {
|
||||
final createdCacheMailboxes = created?.toMapCache(accountId) ?? {};
|
||||
await _mailboxCacheClient.insertMultipleItem(createdCacheMailboxes);
|
||||
}
|
||||
return Future.value();
|
||||
}
|
||||
|
||||
Future<Mailbox> getSpamMailbox() async {
|
||||
final mailboxCachedList = await _mailboxCacheClient.getAll();
|
||||
Future<Mailbox> getSpamMailbox(AccountId accountId) async {
|
||||
final mailboxCachedList = await _mailboxCacheClient.getListByCollectionId(accountId.asString);
|
||||
final listSpamMailboxCached = mailboxCachedList
|
||||
.map((mailboxCached) => mailboxCached.toMailbox())
|
||||
.toMailboxList()
|
||||
.where((mailbox) => mailbox.role == PresentationMailbox.roleSpam)
|
||||
.toList();
|
||||
|
||||
|
||||
@@ -28,5 +28,5 @@ abstract class SpamReportDataSource {
|
||||
|
||||
Future<void> deleteSpamReportState();
|
||||
|
||||
Future<Mailbox> getSpamMailboxCached();
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId);
|
||||
}
|
||||
+1
-1
@@ -70,7 +70,7 @@ class SharePreferenceSpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached() {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -37,9 +37,9 @@ class SpamReportCacheDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached() {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
return Future.sync(() async {
|
||||
return await _mailboxCacheManager.getSpamMailbox();
|
||||
return await _mailboxCacheManager.getSpamMailbox(accountId);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ class SpamReportDataSourceImpl extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached() {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -62,7 +62,7 @@ class SharePreferenceSpamReportDataSource extends SpamReportDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached() {
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class SpamReportRepositoryImpl extends SpamReportRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Mailbox> getSpamMailboxCached() {
|
||||
return mapDataSource[DataSourceType.cache]!.getSpamMailboxCached();
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId) {
|
||||
return mapDataSource[DataSourceType.cache]!.getSpamMailboxCached(accountId);
|
||||
}
|
||||
}
|
||||
@@ -28,5 +28,5 @@ abstract class SpamReportRepository {
|
||||
|
||||
Future<void> deleteSpamReportState();
|
||||
|
||||
Future<Mailbox> getSpamMailboxCached();
|
||||
Future<Mailbox> getSpamMailboxCached(AccountId accountId);
|
||||
}
|
||||
+3
-2
@@ -2,6 +2,7 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/spam_report_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_number_of_unread_spam_emails_state.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/get_spam_mailbox_cached_state.dart';
|
||||
@@ -12,7 +13,7 @@ class GetSpamMailboxCachedInteractor {
|
||||
|
||||
GetSpamMailboxCachedInteractor(this._spamReportRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetSpamMailboxCachedLoading());
|
||||
|
||||
@@ -21,7 +22,7 @@ class GetSpamMailboxCachedInteractor {
|
||||
final checkTimeCondition = timeLast.inHours > MailboxDashboardConstant.spamReportBannerDisplayTimeOut;
|
||||
|
||||
if (checkTimeCondition) {
|
||||
final spamMailbox = await _spamReportRepository.getSpamMailboxCached();
|
||||
final spamMailbox = await _spamReportRepository.getSpamMailboxCached(accountId);
|
||||
final countUnreadSpamMailbox = spamMailbox.unreadEmails?.value.value.toInt() ?? 0;
|
||||
if (countUnreadSpamMailbox > 0) {
|
||||
yield Right<Failure, Success>(GetSpamMailboxCachedSuccess(spamMailbox));
|
||||
|
||||
+2
-2
@@ -1579,8 +1579,8 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
}
|
||||
|
||||
void refreshSpamReportBanner() {
|
||||
if (spamReportController.enableSpamReport) {
|
||||
spamReportController.getSpamMailboxCached();
|
||||
if (spamReportController.enableSpamReport && accountId.value != null) {
|
||||
spamReportController.getSpamMailboxCached(accountId.value!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ class SpamReportController extends BaseController {
|
||||
mailboxFilterCondition: MailboxFilterCondition(role: Role('Spam'))));
|
||||
}
|
||||
|
||||
void getSpamMailboxCached() {
|
||||
consumeState(_getSpamMailboxCachedInteractor.execute());
|
||||
void getSpamMailboxCached(AccountId accountId) {
|
||||
consumeState(_getSpamMailboxCachedInteractor.execute(accountId));
|
||||
}
|
||||
|
||||
void _storeLastTimeDismissedSpamReportedAction() {
|
||||
|
||||
Reference in New Issue
Block a user