TF-314 Implement delete an email in EmailView
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class MoveToTrashRequest with EquatableMixin {
|
||||
|
||||
final List<EmailId> emailIds;
|
||||
final MailboxId currentMailboxId;
|
||||
final MailboxId trashMailboxId;
|
||||
final MoveAction moveAction;
|
||||
|
||||
MoveToTrashRequest(
|
||||
this.emailIds,
|
||||
this.currentMailboxId,
|
||||
this.trashMailboxId,
|
||||
this.moveAction,
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
emailIds,
|
||||
currentMailboxId,
|
||||
trashMailboxId,
|
||||
moveAction,
|
||||
];
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/model/email_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_trash_request.dart';
|
||||
|
||||
abstract class EmailRepository {
|
||||
Future<Email> getEmailContent(AccountId accountId, EmailId emailId);
|
||||
@@ -36,6 +37,8 @@ abstract class EmailRepository {
|
||||
|
||||
Future<List<EmailId>> moveToMailbox(AccountId accountId, MoveRequest moveRequest);
|
||||
|
||||
Future<List<EmailId>> moveToTrash(AccountId accountId, MoveToTrashRequest moveRequest);
|
||||
|
||||
Future<List<Email>> markAsStar(
|
||||
AccountId accountId,
|
||||
List<Email> emails,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class MoveToTrashSuccess extends UIState {
|
||||
final EmailId emailId;
|
||||
final MailboxId currentMailboxId;
|
||||
final MailboxId trashMailboxId;
|
||||
final MoveAction moveAction;
|
||||
|
||||
MoveToTrashSuccess(
|
||||
this.emailId,
|
||||
this.currentMailboxId,
|
||||
this.trashMailboxId,
|
||||
this.moveAction
|
||||
);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
emailId,
|
||||
currentMailboxId,
|
||||
trashMailboxId,
|
||||
moveAction
|
||||
];
|
||||
}
|
||||
|
||||
class MoveToTrashFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
MoveToTrashFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_trash_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/move_to_trash_state.dart';
|
||||
|
||||
class MoveToTrashInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
|
||||
MoveToTrashInteractor(this.emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, MoveToTrashRequest moveRequest) async* {
|
||||
try {
|
||||
final result = await emailRepository.moveToTrash(accountId, moveRequest);
|
||||
if (result.isNotEmpty) {
|
||||
yield Right(MoveToTrashSuccess(
|
||||
result.first,
|
||||
moveRequest.currentMailboxId,
|
||||
moveRequest.trashMailboxId,
|
||||
moveRequest.moveAction));
|
||||
} else {
|
||||
yield Left(MoveToTrashFailure(null));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(MoveToTrashFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user