TF-1080 Implement delete multiple mailbox folder
This commit is contained in:
@@ -1,19 +1,40 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:tmail_ui_user/features/base/state/ui_action_state.dart';
|
||||
|
||||
class DeleteMultipleMailboxSuccess extends UIActionState {
|
||||
class DeleteMultipleMailboxAllSuccess extends UIActionState {
|
||||
|
||||
final MailboxId mailboxIdDeleted;
|
||||
final List<MailboxId> listMailboxIdDeleted;
|
||||
|
||||
DeleteMultipleMailboxSuccess(this.mailboxIdDeleted, {
|
||||
DeleteMultipleMailboxAllSuccess(this.listMailboxIdDeleted, {
|
||||
jmap.State? currentEmailState,
|
||||
jmap.State? currentMailboxState,
|
||||
}) : super(currentEmailState, currentMailboxState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mailboxIdDeleted];
|
||||
List<Object?> get props => [listMailboxIdDeleted];
|
||||
}
|
||||
|
||||
class DeleteMultipleMailboxHasSomeSuccess extends UIActionState {
|
||||
|
||||
final List<MailboxId> listMailboxIdDeleted;
|
||||
|
||||
DeleteMultipleMailboxHasSomeSuccess(this.listMailboxIdDeleted, {
|
||||
jmap.State? currentEmailState,
|
||||
jmap.State? currentMailboxState,
|
||||
}) : super(currentEmailState, currentMailboxState);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [listMailboxIdDeleted];
|
||||
}
|
||||
|
||||
class DeleteMultipleMailboxAllFailure extends FeatureFailure {
|
||||
|
||||
DeleteMultipleMailboxAllFailure();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class DeleteMultipleMailboxFailure extends FeatureFailure {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.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';
|
||||
@@ -11,17 +13,38 @@ class DeleteMultipleMailboxInteractor {
|
||||
|
||||
DeleteMultipleMailboxInteractor(this._mailboxRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId, List<MailboxId> mailboxIds, MailboxId mailboxIdDeleted) async* {
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Map<MailboxId, List<MailboxId>> mapMailboxIdToDelete,
|
||||
List<MailboxId> listMailboxIdToDelete
|
||||
) async* {
|
||||
try {
|
||||
final currentMailboxState = await _mailboxRepository.getMailboxState();
|
||||
final result = await _mailboxRepository.deleteMultipleMailbox(session, accountId, mailboxIds);
|
||||
if (result) {
|
||||
yield Right<Failure, Success>(DeleteMultipleMailboxSuccess(
|
||||
mailboxIdDeleted,
|
||||
|
||||
final listResult = await Future.wait(
|
||||
mapMailboxIdToDelete.keys.map((mailboxId) {
|
||||
final mailboxIdsToDelete = mapMailboxIdToDelete[mailboxId]!;
|
||||
return _mailboxRepository.deleteMultipleMailbox(
|
||||
session,
|
||||
accountId,
|
||||
mailboxIdsToDelete);
|
||||
})
|
||||
);
|
||||
|
||||
final allSuccess = listResult.every((result) => result);
|
||||
final allFailed = listResult.every((result) => !result);
|
||||
|
||||
if (allSuccess) {
|
||||
yield Right<Failure, Success>(DeleteMultipleMailboxAllSuccess(
|
||||
listMailboxIdToDelete,
|
||||
currentMailboxState: currentMailboxState));
|
||||
} else if (allFailed) {
|
||||
yield Left<Failure, Success>(DeleteMultipleMailboxAllFailure());
|
||||
} else {
|
||||
logError('DeleteMultipleMailboxInteractor::execute(): failed');
|
||||
yield Left<Failure, Success>(DeleteMultipleMailboxFailure(null));
|
||||
yield Right<Failure, Success>(DeleteMultipleMailboxHasSomeSuccess(
|
||||
listMailboxIdToDelete,
|
||||
currentMailboxState: currentMailboxState));
|
||||
}
|
||||
} catch (e) {
|
||||
logError('DeleteMultipleMailboxInteractor::execute(): exception: $e');
|
||||
|
||||
Reference in New Issue
Block a user