Skip to content

Commit

Permalink
TF-3372 Implement Clean SPAM and TRASH folder usecase with new Empty API
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangdat committed Dec 27, 2024
1 parent adaee38 commit 5b42dc9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
11 changes: 6 additions & 5 deletions lib/features/thread/domain/state/empty_spam_folder_state.dart
Original file line number Diff line number Diff line change
@@ -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<EmailId> emailIds;

EmptySpamFolderSuccess(this.emailIds);
EmptySpamFolderSuccess();

@override
List<Object?> get props => [emailIds];
List<Object?> get props => [];
}

class EmptySpamFolderFailure extends FeatureFailure {

EmptySpamFolderFailure(dynamic exception) : super(exception: exception);
}

class CannotEmptySpamFolderException implements Exception {
CannotEmptySpamFolderException();
}
11 changes: 6 additions & 5 deletions lib/features/thread/domain/state/empty_trash_folder_state.dart
Original file line number Diff line number Diff line change
@@ -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<EmailId> emailIds;

EmptyTrashFolderSuccess(this.emailIds);
EmptyTrashFolderSuccess();

@override
List<Object?> get props => [emailIds];
List<Object?> get props => [];
}

class EmptyTrashFolderFailure extends FeatureFailure {

EmptyTrashFolderFailure(dynamic exception) : super(exception: exception);
}

class CannotEmptyTrashException implements Exception {
CannotEmptyTrashException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class EmptySpamFolderInteractor {
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, MailboxId spamMailboxId) async* {
try {
yield Right<Failure, Success>(EmptySpamFolderLoading());
final emailIdDeleted = await threadRepository.emptySpamFolder(session, accountId, spamMailboxId);
yield Right<Failure, Success>(EmptySpamFolderSuccess(emailIdDeleted));
final success = await threadRepository.emptySpamFolder(session, accountId, spamMailboxId);
final finalState = success ? Right<Failure, Success>(EmptySpamFolderSuccess())
: Left<Failure, Success>(EmptySpamFolderFailure(CannotEmptySpamFolderException()));
yield finalState;
} catch (e) {
yield Left<Failure, Success>(EmptySpamFolderFailure(e));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class EmptyTrashFolderInteractor {
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, MailboxId trashMailboxId) async* {
try {
yield Right<Failure, Success>(EmptyTrashFolderLoading());
final emailIdDeleted = await threadRepository.emptyTrashFolder(session, accountId, trashMailboxId);
yield Right<Failure, Success>(EmptyTrashFolderSuccess(emailIdDeleted,));
final success = await threadRepository.emptyTrashFolder(session, accountId, trashMailboxId);
final finalState = success ? Right<Failure, Success>(EmptyTrashFolderSuccess())
: Left<Failure, Success>(EmptyTrashFolderFailure(CannotEmptyTrashException()));
yield finalState;
} catch (e) {
yield Left<Failure, Success>(EmptyTrashFolderFailure(e));
}
Expand Down

0 comments on commit 5b42dc9

Please sign in to comment.