TF-56 Implement upload multiple attachment

This commit is contained in:
dab246
2021-09-17 18:57:26 +07:00
committed by Dat H. Pham
parent 39ca213285
commit a3b0ae0d53
7 changed files with 105 additions and 22 deletions
@@ -1,4 +1,5 @@
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:model/model.dart';
class UploadAttachmentLoadingState extends UIState {
@@ -22,6 +23,33 @@ class UploadAttachmentFailure extends FeatureFailure {
UploadAttachmentFailure(this.exception);
@override
List<Object> get props => [exception];
}
class UploadAttachmentAllSuccess extends UIState {
final List<Either<Failure, Success>> listResults;
UploadAttachmentAllSuccess(this.listResults);
@override
List<Object?> get props => [listResults];
}
class UploadAttachmentHasSomeFailure extends UIState {
final List<Either<Failure, Success>> listResults;
UploadAttachmentHasSomeFailure(this.listResults);
@override
List<Object?> get props => [listResults];
}
class UploadAttachmentAllFailure extends FeatureFailure {
final exception;
UploadAttachmentAllFailure(this.exception);
@override
List<Object> get props => [exception];
}
@@ -14,7 +14,6 @@ class UploadAttachmentInteractor {
Stream<Either<Failure, Success>> execute(FileInfo fileInfo, AccountId accountId, Uri uploadUrl) async* {
try {
yield Right<Failure, Success>(UploadAttachmentLoadingState());
final result = await Future.wait(
[_credentialRepository.getUserName(), _credentialRepository.getPassword()],
eagerError: true
@@ -0,0 +1,36 @@
import 'package:core/core.dart';
import 'package:dartz/dartz.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/composer/domain/state/upload_attachment_state.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/upload_attachment_interactor.dart';
class UploadMultipleAttachmentInteractor {
final UploadAttachmentInteractor _uploadAttachmentInteractor;
UploadMultipleAttachmentInteractor(this._uploadAttachmentInteractor);
Stream<Either<Failure, Success>> execute(List<FileInfo> listFiles, AccountId accountId, Uri uploadUrl) async* {
try {
yield Right<Failure, Success>(UploadAttachmentLoadingState());
final listResult = await Future.wait(
listFiles.map((fileInfo) async {
final result = await _uploadAttachmentInteractor.execute(fileInfo, accountId, uploadUrl).toList();
return result.first;
})
);
if (listResult.length == 1) {
yield listResult.first;
} else {
final listResultSuccess = listResult.where((either) => either.isRight()).toList();
if (listResultSuccess.length == listResult.length) {
yield Right<Failure, Success>(UploadAttachmentHasSomeFailure(listResultSuccess));
} else {
yield Right<Failure, Success>(UploadAttachmentAllSuccess(listResult));
}
}
} catch (e) {
yield Left<Failure, Success>(UploadAttachmentAllFailure(e));
}
}
}