TF-56 Send email with attachment
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
import 'package:core/core.dart';
|
||||
|
||||
class SendingEmailState extends UIState {
|
||||
SendingEmailState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class SendEmailSuccess extends UIState {
|
||||
|
||||
SendEmailSuccess();
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:model/model.dart';
|
||||
|
||||
class UploadAttachmentLoadingState extends UIState {
|
||||
UploadAttachmentLoadingState();
|
||||
class UploadingAttachmentState extends UIState {
|
||||
UploadingAttachmentState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
@@ -27,28 +27,37 @@ class UploadAttachmentFailure extends FeatureFailure {
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
|
||||
class UploadAttachmentAllSuccess extends UIState {
|
||||
class UploadMultipleAttachmentAllSuccess extends UIState {
|
||||
final List<Either<Failure, Success>> listResults;
|
||||
|
||||
UploadAttachmentAllSuccess(this.listResults);
|
||||
UploadMultipleAttachmentAllSuccess(this.listResults);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [listResults];
|
||||
}
|
||||
|
||||
class UploadAttachmentHasSomeFailure extends UIState {
|
||||
class UploadMultipleAttachmentHasSomeFailure extends UIState {
|
||||
final List<Either<Failure, Success>> listResults;
|
||||
|
||||
UploadAttachmentHasSomeFailure(this.listResults);
|
||||
UploadMultipleAttachmentHasSomeFailure(this.listResults);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [listResults];
|
||||
}
|
||||
|
||||
class UploadAttachmentAllFailure extends FeatureFailure {
|
||||
class UploadMultipleAttachmentAllFailure extends FeatureFailure {
|
||||
final List<Either<Failure, Success>> listResults;
|
||||
|
||||
UploadMultipleAttachmentAllFailure(this.listResults);
|
||||
|
||||
@override
|
||||
List<Object> get props => [listResults];
|
||||
}
|
||||
|
||||
class UploadMultipleAttachmentFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
UploadAttachmentAllFailure(this.exception);
|
||||
UploadMultipleAttachmentFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
|
||||
@@ -12,15 +12,15 @@ class SendEmailInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute(AccountId accountId, EmailRequest emailRequest) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LoadingState());
|
||||
yield Right<Failure, Success>(SendingEmailState());
|
||||
final result = await emailRepository.sendEmail(accountId, emailRequest);
|
||||
if (result) {
|
||||
yield Right<Failure, Success>(SendEmailSuccess());
|
||||
} else {
|
||||
yield Left(SendEmailFailure(result));
|
||||
yield Left<Failure, Success>(SendEmailFailure(result));
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left(SendEmailFailure(e));
|
||||
yield Left<Failure, Success>(SendEmailFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,23 +4,16 @@ import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/repository/composer_repository.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/state/upload_attachment_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
|
||||
class UploadAttachmentInteractor {
|
||||
final ComposerRepository _composerRepository;
|
||||
final CredentialRepository _credentialRepository;
|
||||
|
||||
UploadAttachmentInteractor(this._composerRepository, this._credentialRepository);
|
||||
UploadAttachmentInteractor(this._composerRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(FileInfo fileInfo, AccountId accountId, Uri uploadUrl) async* {
|
||||
try {
|
||||
final result = await Future.wait(
|
||||
[_credentialRepository.getUserName(), _credentialRepository.getPassword()],
|
||||
eagerError: true
|
||||
).then((List responses) async {
|
||||
final accountRequest = AccountRequest(responses.first, responses.last);
|
||||
return await _composerRepository.uploadAttachment(UploadRequest(uploadUrl, accountId, fileInfo, accountRequest));
|
||||
});
|
||||
final result = await _composerRepository.uploadAttachment(
|
||||
UploadRequest(uploadUrl, accountId, fileInfo));
|
||||
yield Right<Failure, Success>(UploadAttachmentSuccess(result));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(UploadAttachmentFailure(e));
|
||||
|
||||
@@ -12,7 +12,7 @@ class UploadMultipleAttachmentInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute(List<FileInfo> listFiles, AccountId accountId, Uri uploadUrl) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(UploadAttachmentLoadingState());
|
||||
yield Right<Failure, Success>(UploadingAttachmentState());
|
||||
final listResult = await Future.wait(
|
||||
listFiles.map((fileInfo) async {
|
||||
final result = await _uploadAttachmentInteractor.execute(fileInfo, accountId, uploadUrl).toList();
|
||||
@@ -24,13 +24,15 @@ class UploadMultipleAttachmentInteractor {
|
||||
} else {
|
||||
final listResultSuccess = listResult.where((either) => either.isRight()).toList();
|
||||
if (listResultSuccess.length == listResult.length) {
|
||||
yield Right<Failure, Success>(UploadAttachmentHasSomeFailure(listResultSuccess));
|
||||
yield Right<Failure, Success>(UploadMultipleAttachmentAllSuccess(listResultSuccess));
|
||||
} else if (listResultSuccess.length == 0) {
|
||||
yield Left<Failure, Success>(UploadMultipleAttachmentAllFailure(listResult));
|
||||
} else {
|
||||
yield Right<Failure, Success>(UploadAttachmentAllSuccess(listResult));
|
||||
yield Right<Failure, Success>(UploadMultipleAttachmentHasSomeFailure(listResultSuccess));
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(UploadAttachmentAllFailure(e));
|
||||
yield Left<Failure, Success>(UploadMultipleAttachmentFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user