TF-3334 Skip getting stored state in interactor when performing actions with email and mailbox

This commit is contained in:
dab246
2024-12-23 16:10:36 +07:00
committed by Dat H. Pham
parent ba93e7b514
commit 01b320ce89
52 changed files with 138 additions and 602 deletions
@@ -1,14 +1,7 @@
import 'package:core/presentation/state/failure.dart';
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';
import 'package:core/presentation/state/success.dart';
class RemoveEmailDraftsSuccess extends UIActionState {
RemoveEmailDraftsSuccess({
jmap.State? currentEmailState,
jmap.State? currentMailboxState,
}) : super(currentEmailState, currentMailboxState);
}
class RemoveEmailDraftsSuccess extends UIState {}
class RemoveEmailDraftsFailure extends FeatureFailure {
@@ -1,33 +1,22 @@
import 'package:core/core.dart';
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:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/state/remove_email_drafts_state.dart';
class RemoveEmailDraftsInteractor {
final EmailRepository _emailRepository;
final MailboxRepository _mailboxRepository;
RemoveEmailDraftsInteractor(this._emailRepository, this._mailboxRepository);
RemoveEmailDraftsInteractor(this._emailRepository);
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, EmailId emailId) async* {
try {
final listState = await Future.wait([
_mailboxRepository.getMailboxState(session, accountId),
_emailRepository.getEmailState(session, accountId),
], eagerError: true);
final currentMailboxState = listState.first;
final currentEmailState = listState.last;
final result = await _emailRepository.removeEmailDrafts(session, accountId, emailId);
if (result) {
yield Right<Failure, Success>(RemoveEmailDraftsSuccess(
currentEmailState: currentEmailState,
currentMailboxState: currentMailboxState));
yield Right<Failure, Success>(RemoveEmailDraftsSuccess());
} else {
yield Left<Failure, Success>(RemoveEmailDraftsFailure(result));
}
@@ -275,53 +275,30 @@ class MailboxDashBoardBindings extends BaseBindings {
@override
void bindingsInteractor() {
Get.lazyPut(() => RemoveEmailDraftsInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()));
Get.lazyPut(() => MoveToMailboxInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()));
Get.lazyPut(() => DeleteEmailPermanentlyInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()));
Get.lazyPut(() => RemoveEmailDraftsInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => MoveToMailboxInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => DeleteEmailPermanentlyInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => SaveRecentSearchInteractor(Get.find<SearchRepository>()));
Get.lazyPut(() => GetAllRecentSearchLatestInteractor(Get.find<SearchRepository>()));
Get.lazyPut(() => SearchEmailInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => SearchMoreEmailInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => RefreshChangesSearchEmailInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => QuickSearchEmailInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => MarkAsMailboxReadInteractor(
Get.find<MailboxRepository>(),
Get.find<EmailRepository>())
);
Get.lazyPut(() => MarkAsMailboxReadInteractor(Get.find<MailboxRepository>()));
Get.lazyPut(() => GetComposerCacheOnWebInteractor(Get.find<ComposerCacheRepository>()));
Get.lazyPut(() => RemoveComposerCacheOnWebInteractor(Get.find<ComposerCacheRepository>()));
Get.lazyPut(() => MarkAsEmailReadInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()
));
Get.lazyPut(() => MarkAsEmailReadInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => MarkAsStarEmailInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => MarkAsMultipleEmailReadInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()
));
Get.lazyPut(() => MarkAsStarMultipleEmailInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => MoveMultipleEmailToMailboxInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()
));
Get.lazyPut(() => DeleteMultipleEmailsPermanentlyInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()));
Get.lazyPut(() => EmptyTrashFolderInteractor(
Get.find<ThreadRepository>(),
Get.find<MailboxRepository>(),
Get.find<EmailRepository>()));
Get.lazyPut(() => EmptySpamFolderInteractor(
Get.find<ThreadRepository>(),
Get.find<MailboxRepository>(),
Get.find<EmailRepository>()
));
Get.lazyPut(() => DeleteMultipleEmailsPermanentlyInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => EmptyTrashFolderInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => EmptySpamFolderInteractor(Get.find<ThreadRepository>()));
Get.lazyPut(() => GetAppDashboardConfigurationInteractor(
Get.find<AppConfigLoader>()));
Get.lazyPut(() => GetEmailByIdInteractor(
@@ -336,17 +313,11 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.lazyPut(() => GetSpamReportStateInteractor(
Get.find<SpamReportRepository>()));
Get.lazyPut(() => GetSpamMailboxCachedInteractor(Get.find<SpamReportRepository>()));
Get.lazyPut(() => SendEmailInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>(),
));
Get.lazyPut(() => SendEmailInteractor(Get.find<EmailRepository>()));
SendingQueueInteractorBindings().dependencies();
Get.lazyPut(() => StoreSessionInteractor(Get.find<SessionRepository>()));
Get.lazyPut(() => UnsubscribeEmailInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => RestoredDeletedMessageInteractor(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()
));
Get.lazyPut(() => RestoredDeletedMessageInteractor(Get.find<EmailRepository>()));
Get.lazyPut(() => GetRestoredDeletedMessageInterator(
Get.find<EmailRepository>(),
Get.find<MailboxRepository>()
@@ -404,7 +404,6 @@ class MailboxDashBoardController extends ReloadableController with UserSettingPo
} else if (success is UnsubscribeEmailSuccess) {
_handleUnsubscribeMailSuccess();
} else if (success is RestoreDeletedMessageSuccess) {
dispatchMailboxUIAction(RefreshChangeMailboxAction(success.currentMailboxState));
_handleRestoreDeletedMessageSuccess(success.emailRecoveryAction.id!);
} else if (success is GetRestoredDeletedMessageSuccess) {
_handleGetRestoredDeletedMessageSuccess(success);