TF-32 Add domain layer of export attachment for ios platform
This commit is contained in:
@@ -25,7 +25,6 @@ import 'package:tmail_ui_user/features/composer/domain/usecases/send_email_inter
|
||||
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/constants/email_constants.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/extensions/email_content_extension.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/attachment_file.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/message_content.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/model.dart';
|
||||
@@ -16,4 +17,12 @@ abstract class EmailRepository {
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
);
|
||||
|
||||
Future<String> exportAttachment(
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
CancelToken cancelToken
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:core/core.dart';
|
||||
|
||||
class ExportAttachmentSuccess extends UIState {
|
||||
final String filePath;
|
||||
|
||||
ExportAttachmentSuccess(this.filePath);
|
||||
|
||||
@override
|
||||
List<Object> get props => [filePath];
|
||||
}
|
||||
|
||||
class ExportAttachmentFailure extends FeatureFailure {
|
||||
final exception;
|
||||
|
||||
ExportAttachmentFailure(this.exception);
|
||||
|
||||
@override
|
||||
List<Object> get props => [exception];
|
||||
}
|
||||
@@ -12,11 +12,11 @@ class DownloadAttachmentsInteractor {
|
||||
|
||||
DownloadAttachmentsInteractor(this.emailRepository, this.credentialRepository);
|
||||
|
||||
Future<Either<Failure, Success>> execute(
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl
|
||||
) async {
|
||||
) async* {
|
||||
try {
|
||||
final taskIds = await Future.wait(
|
||||
[credentialRepository.getUserName(), credentialRepository.getPassword()],
|
||||
@@ -30,9 +30,9 @@ class DownloadAttachmentsInteractor {
|
||||
accountRequest);
|
||||
});
|
||||
|
||||
return Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
} catch (e) {
|
||||
return Left<Failure, Success>(DownloadAttachmentsFailure(e));
|
||||
yield Left<Failure, Success>(DownloadAttachmentsFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/export_attachment_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
|
||||
class ExportAttachmentInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
final CredentialRepository credentialRepository;
|
||||
|
||||
ExportAttachmentInteractor(this.emailRepository, this.credentialRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
CancelToken cancelToken
|
||||
) async* {
|
||||
try {
|
||||
final filePath = await Future.wait(
|
||||
[credentialRepository.getUserName(), credentialRepository.getPassword()],
|
||||
eagerError: true
|
||||
).then((List responses) async {
|
||||
final accountRequest = AccountRequest(responses.first, responses.last);
|
||||
return await emailRepository.exportAttachment(
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
cancelToken);
|
||||
});
|
||||
yield Right<Failure, Success>(ExportAttachmentSuccess(filePath));
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(ExportAttachmentFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user