TF-657 Add interactor/repository/datasource for SendReceiptToSender

This commit is contained in:
dab246
2022-10-19 21:09:37 +07:00
committed by Dat H. Pham
parent 398654a79d
commit 4d7ba01f00
11 changed files with 191 additions and 15 deletions
@@ -0,0 +1,21 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:jmap_dart_client/jmap/mdn/mdn.dart';
class SendReceiptToSenderRequest with EquatableMixin {
final MDN mdn;
final IdentityId identityId;
final Id sendId;
SendReceiptToSenderRequest({
required this.mdn,
required this.identityId,
required this.sendId
});
@override
List<Object?> get props => [mdn, identityId, sendId];
}
@@ -0,0 +1,9 @@
import 'dart:async';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mdn/mdn.dart';
import 'package:tmail_ui_user/features/email/domain/model/send_receipt_to_sender_request.dart';
abstract class MdnRepository {
Future<MDN?> sendReceiptToSender(AccountId accountId, SendReceiptToSenderRequest request);
}
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/model.dart';
class GetEmailContentLoading extends UIState {
@@ -13,13 +14,13 @@ class GetEmailContentSuccess extends UIState {
final List<EmailContent> emailContents;
final List<EmailContent> emailContentsDisplayed;
final List<Attachment> attachments;
final bool readReceiptRequested;
final Email? emailCurrent;
GetEmailContentSuccess(
this.emailContents,
this.emailContentsDisplayed,
this.attachments,
this.readReceiptRequested
this.emailCurrent
);
@override
@@ -27,7 +28,7 @@ class GetEmailContentSuccess extends UIState {
emailContents,
emailContentsDisplayed,
attachments,
readReceiptRequested
emailCurrent
];
}
@@ -0,0 +1,25 @@
import 'package:core/presentation/state/failure.dart';
import 'package:core/presentation/state/success.dart';
import 'package:jmap_dart_client/jmap/mdn/mdn.dart';
class SendReceiptToSenderLoading extends UIState {}
class SendReceiptToSenderSuccess extends UIState {
final MDN mdn;
SendReceiptToSenderSuccess(this.mdn);
@override
List<Object?> get props => [mdn];
}
class SendReceiptToSenderFailure extends FeatureFailure {
final dynamic exception;
SendReceiptToSenderFailure(this.exception);
@override
List<Object?> get props => [exception];
}
@@ -30,19 +30,11 @@ class GetEmailContentInteractor {
newEmailContents,
newEmailContentsDisplayed,
email.allAttachments,
email.needShowNotificationMessageReadReceipt));
email));
} else if (email.allAttachments.isNotEmpty) {
yield Right<Failure, Success>(GetEmailContentSuccess(
[],
[],
email.allAttachments,
email.needShowNotificationMessageReadReceipt));
yield Right<Failure, Success>(GetEmailContentSuccess([], [], email.allAttachments, email));
} else if (email.headers?.isNotEmpty == true) {
yield Right<Failure, Success>(GetEmailContentSuccess(
[],
[],
[],
email.needShowNotificationMessageReadReceipt));
yield Right<Failure, Success>(GetEmailContentSuccess([], [], [], email));
} else {
yield Left(GetEmailContentFailure(null));
}
@@ -0,0 +1,26 @@
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/send_receipt_to_sender_request.dart';
import 'package:tmail_ui_user/features/email/domain/repository/mdn_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/send_receipt_to_sender_state.dart';
class SendReceiptToSenderInteractor {
final MdnRepository _mdnRepository;
SendReceiptToSenderInteractor(this._mdnRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, SendReceiptToSenderRequest request) async* {
try {
yield Right<Failure, Success>(SendReceiptToSenderLoading());
final mdn = await _mdnRepository.sendReceiptToSender(accountId, request);
if (mdn != null) {
yield Right<Failure, Success>(SendReceiptToSenderSuccess(mdn));
} else {
yield Left<Failure, Success>(SendReceiptToSenderFailure(null));
}
} catch (e) {
yield Left<Failure, Success>(SendReceiptToSenderFailure(e));
}
}
}