From 5b42dc99b0db77d91f26b0cb0d319da1c1e0d25b Mon Sep 17 00:00:00 2001 From: Dat PHAM HOANG Date: Fri, 27 Dec 2024 14:41:28 +0700 Subject: [PATCH] TF-3372 Implement Clean SPAM and TRASH folder usecase with new Empty API --- .../thread/domain/state/empty_spam_folder_state.dart | 11 ++++++----- .../thread/domain/state/empty_trash_folder_state.dart | 11 ++++++----- .../domain/usecases/empty_spam_folder_interactor.dart | 6 ++++-- .../usecases/empty_trash_folder_interactor.dart | 6 ++++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/features/thread/domain/state/empty_spam_folder_state.dart b/lib/features/thread/domain/state/empty_spam_folder_state.dart index fedb07ae34..6cfcb03a98 100644 --- a/lib/features/thread/domain/state/empty_spam_folder_state.dart +++ b/lib/features/thread/domain/state/empty_spam_folder_state.dart @@ -1,20 +1,21 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; -import 'package:jmap_dart_client/jmap/mail/email/email.dart'; class EmptySpamFolderLoading extends LoadingState {} class EmptySpamFolderSuccess extends UIState { - final List emailIds; - - EmptySpamFolderSuccess(this.emailIds); + EmptySpamFolderSuccess(); @override - List get props => [emailIds]; + List get props => []; } class EmptySpamFolderFailure extends FeatureFailure { EmptySpamFolderFailure(dynamic exception) : super(exception: exception); +} + +class CannotEmptySpamFolderException implements Exception { + CannotEmptySpamFolderException(); } \ No newline at end of file diff --git a/lib/features/thread/domain/state/empty_trash_folder_state.dart b/lib/features/thread/domain/state/empty_trash_folder_state.dart index 577eb6d7cc..7056435241 100644 --- a/lib/features/thread/domain/state/empty_trash_folder_state.dart +++ b/lib/features/thread/domain/state/empty_trash_folder_state.dart @@ -1,20 +1,21 @@ import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/state/success.dart'; -import 'package:jmap_dart_client/jmap/mail/email/email.dart'; class EmptyTrashFolderLoading extends LoadingState {} class EmptyTrashFolderSuccess extends UIState { - final List emailIds; - - EmptyTrashFolderSuccess(this.emailIds); + EmptyTrashFolderSuccess(); @override - List get props => [emailIds]; + List get props => []; } class EmptyTrashFolderFailure extends FeatureFailure { EmptyTrashFolderFailure(dynamic exception) : super(exception: exception); +} + +class CannotEmptyTrashException implements Exception { + CannotEmptyTrashException(); } \ No newline at end of file diff --git a/lib/features/thread/domain/usecases/empty_spam_folder_interactor.dart b/lib/features/thread/domain/usecases/empty_spam_folder_interactor.dart index 601998a4cc..e2c6a7829e 100644 --- a/lib/features/thread/domain/usecases/empty_spam_folder_interactor.dart +++ b/lib/features/thread/domain/usecases/empty_spam_folder_interactor.dart @@ -15,8 +15,10 @@ class EmptySpamFolderInteractor { Stream> execute(Session session, AccountId accountId, MailboxId spamMailboxId) async* { try { yield Right(EmptySpamFolderLoading()); - final emailIdDeleted = await threadRepository.emptySpamFolder(session, accountId, spamMailboxId); - yield Right(EmptySpamFolderSuccess(emailIdDeleted)); + final success = await threadRepository.emptySpamFolder(session, accountId, spamMailboxId); + final finalState = success ? Right(EmptySpamFolderSuccess()) + : Left(EmptySpamFolderFailure(CannotEmptySpamFolderException())); + yield finalState; } catch (e) { yield Left(EmptySpamFolderFailure(e)); } diff --git a/lib/features/thread/domain/usecases/empty_trash_folder_interactor.dart b/lib/features/thread/domain/usecases/empty_trash_folder_interactor.dart index 5a540c8b91..430a5df3af 100644 --- a/lib/features/thread/domain/usecases/empty_trash_folder_interactor.dart +++ b/lib/features/thread/domain/usecases/empty_trash_folder_interactor.dart @@ -15,8 +15,10 @@ class EmptyTrashFolderInteractor { Stream> execute(Session session, AccountId accountId, MailboxId trashMailboxId) async* { try { yield Right(EmptyTrashFolderLoading()); - final emailIdDeleted = await threadRepository.emptyTrashFolder(session, accountId, trashMailboxId); - yield Right(EmptyTrashFolderSuccess(emailIdDeleted,)); + final success = await threadRepository.emptyTrashFolder(session, accountId, trashMailboxId); + final finalState = success ? Right(EmptyTrashFolderSuccess()) + : Left(EmptyTrashFolderFailure(CannotEmptyTrashException())); + yield finalState; } catch (e) { yield Left(EmptyTrashFolderFailure(e)); }