TF-4128 Separate download handling into independent class to decouple from views on web
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -16,7 +12,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
@@ -57,13 +52,6 @@ abstract class EmailDataSource {
|
||||
ReadActions readActions,
|
||||
);
|
||||
|
||||
Future<List<DownloadTaskId>> downloadAttachments(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
);
|
||||
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
@@ -72,16 +60,6 @@ abstract class EmailDataSource {
|
||||
CancelToken cancelToken
|
||||
);
|
||||
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
@@ -149,6 +127,7 @@ abstract class EmailDataSource {
|
||||
AccountId accountId,
|
||||
List<EmailId> emailIds,
|
||||
);
|
||||
|
||||
Future<bool> deleteEmailPermanently(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
@@ -214,17 +193,6 @@ abstract class EmailDataSource {
|
||||
|
||||
Future<EMLPreviewer> getPreviewEMLContentInMemory(String keyStored);
|
||||
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
Future<DownloadedResponse> exportAllAttachments(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/model/preview_attachment.dart';
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/domain/extensions/datetime_extension.dart';
|
||||
import 'package:core/presentation/extensions/html_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:core/utils/preview_eml_file_utils.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -109,18 +105,6 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DownloadTaskId>> downloadAttachments(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.downloadAttachments(attachments, accountId, baseDownloadUrl, accountRequest);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
Attachment attachment,
|
||||
@@ -261,28 +245,6 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await emailAPI.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
onReceiveController,
|
||||
cancelToken: cancelToken);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
@@ -567,29 +529,6 @@ class EmailDataSourceImpl extends EmailDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) => Future.sync(() async {
|
||||
return await emailAPI.downloadAllAttachmentsForWeb(
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadAllUrl,
|
||||
outputFileName,
|
||||
accountRequest,
|
||||
taskId,
|
||||
onReceiveController,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAllAttachments(
|
||||
AccountId accountId,
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -20,7 +16,6 @@ import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
@@ -112,24 +107,6 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DownloadTaskId>> downloadAttachments(List<Attachment> attachments, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAttachment(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest, CancelToken cancelToken) {
|
||||
throw UnimplementedError();
|
||||
@@ -589,20 +566,6 @@ class EmailHiveCacheDataSourceImpl extends EmailDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAllAttachments(AccountId accountId, EmailId emailId, String baseDownloadAllUrl, String outputFileName, AccountRequest accountRequest, {CancelToken? cancelToken}) {
|
||||
throw UnimplementedError();
|
||||
|
||||
@@ -1,18 +1,14 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/model/preview_attachment.dart';
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/domain/extensions/datetime_extension.dart';
|
||||
import 'package:core/presentation/extensions/html_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/file_utils.dart';
|
||||
import 'package:core/utils/preview_eml_file_utils.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -26,7 +22,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
@@ -80,16 +75,6 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(DownloadTaskId taskId, Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest, StreamController<Either<Failure, Success>> onReceiveController, {CancelToken? cancelToken}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DownloadTaskId>> downloadAttachments(List<Attachment> attachments, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAttachment(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest, CancelToken cancelToken) {
|
||||
throw UnimplementedError();
|
||||
@@ -264,21 +249,7 @@ class EmailLocalStorageDataSourceImpl extends EmailDataSource {
|
||||
Future<void> markAsForwarded(Session session, AccountId accountId, List<EmailId> emailIds) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAllAttachments(AccountId accountId, EmailId emailId, String baseDownloadAllUrl, String outputFileName, AccountRequest accountRequest, {CancelToken? cancelToken}) {
|
||||
throw UnimplementedError();
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -18,7 +14,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/read_actions.dart';
|
||||
@@ -65,16 +60,6 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(DownloadTaskId taskId, Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest, StreamController<Either<Failure, Success>> onReceiveController, {CancelToken? cancelToken}) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DownloadTaskId>> downloadAttachments(List<Attachment> attachments, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAttachment(Attachment attachment, AccountId accountId, String baseDownloadUrl, AccountRequest accountRequest, CancelToken cancelToken) {
|
||||
throw UnimplementedError();
|
||||
@@ -247,21 +232,7 @@ class EmailSessionStorageDatasourceImpl extends EmailDataSource {
|
||||
Future<void> markAsForwarded(Session session, AccountId accountId, List<EmailId> emailIds) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
throw UnimplementedError();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAllAttachments(AccountId accountId, EmailId emailId, String baseDownloadAllUrl, String outputFileName, AccountRequest accountRequest, {CancelToken? cancelToken}) {
|
||||
throw UnimplementedError();
|
||||
|
||||
@@ -12,8 +12,6 @@ import 'package:email_recovery/email_recovery/get/get_email_recovery_action_meth
|
||||
import 'package:email_recovery/email_recovery/get/get_email_recovery_action_response.dart';
|
||||
import 'package:email_recovery/email_recovery/set/set_email_recovery_action_method.dart';
|
||||
import 'package:email_recovery/email_recovery/set/set_email_recovery_action_response.dart';
|
||||
import 'package:external_path/external_path.dart';
|
||||
import 'package:flutter_downloader/flutter_downloader.dart';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
@@ -57,7 +55,6 @@ import 'package:model/extensions/list_email_id_extension.dart';
|
||||
import 'package:model/extensions/list_id_extension.dart';
|
||||
import 'package:model/extensions/mailbox_id_extension.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
@@ -67,7 +64,6 @@ import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_reques
|
||||
import 'package:tmail_ui_user/features/email/domain/model/restore_deleted_message_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_all_attachments_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/thread/domain/constants/thread_constants.dart';
|
||||
import 'package:tmail_ui_user/main/error/capability_validator.dart';
|
||||
@@ -298,49 +294,6 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
return (emailIdsSuccess: updatedEmailIds, mapErrors: mapErrors);
|
||||
}
|
||||
|
||||
Future<List<DownloadTaskId>> downloadAttachments(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
) async {
|
||||
if (accountRequest.authenticationType == AuthenticationType.oidc &&
|
||||
accountRequest.token?.isExpired == true &&
|
||||
accountRequest.token?.refreshToken.isNotEmpty == true) {
|
||||
throw DownloadAttachmentHasTokenExpiredException(accountRequest.token!.refreshToken);
|
||||
}
|
||||
|
||||
String externalStorageDirPath;
|
||||
if (Platform.isAndroid) {
|
||||
externalStorageDirPath = await ExternalPath.getExternalStoragePublicDirectory(ExternalPath.DIRECTORY_DOWNLOAD);
|
||||
} else if (Platform.isIOS) {
|
||||
externalStorageDirPath = (await getApplicationDocumentsDirectory()).absolute.path;
|
||||
} else {
|
||||
throw DeviceNotSupportedException();
|
||||
}
|
||||
|
||||
final authentication = accountRequest.authenticationType == AuthenticationType.oidc
|
||||
? accountRequest.bearerToken
|
||||
: accountRequest.basicAuth;
|
||||
|
||||
final taskIds = await Future.wait(
|
||||
attachments.map((attachment) async => await FlutterDownloader.enqueue(
|
||||
url: attachment.getDownloadUrl(baseDownloadUrl, accountId),
|
||||
savedDir: externalStorageDirPath,
|
||||
headers: {
|
||||
HttpHeaders.authorizationHeader: authentication,
|
||||
HttpHeaders.acceptHeader: DioClient.jmapHeader
|
||||
},
|
||||
fileName: attachment.name,
|
||||
showNotification: true,
|
||||
openFileFromNotification: true)));
|
||||
|
||||
return taskIds
|
||||
.where((taskId) => taskId != null)
|
||||
.map((taskId) => DownloadTaskId(taskId!))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
@@ -361,14 +314,14 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
}
|
||||
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest, {
|
||||
StreamController<Either<Failure, Success>>? onReceiveController,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
final authentication = accountRequest.authenticationType == AuthenticationType.oidc
|
||||
? accountRequest.bearerToken
|
||||
: accountRequest.basicAuth;
|
||||
@@ -392,7 +345,7 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
progress = (downloaded / total) * 100;
|
||||
}
|
||||
log('EmailAPI::downloadFileForWeb(): progress = ${progress.round()}%');
|
||||
onReceiveController.add(Right(DownloadingAttachmentForWeb(
|
||||
onReceiveController?.add(Right(DownloadingAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
progress,
|
||||
@@ -410,10 +363,10 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) async {
|
||||
DownloadTaskId taskId, {
|
||||
StreamController<Either<Failure, Success>>? onReceiveController,
|
||||
CancelToken? cancelToken,
|
||||
}) async {
|
||||
final authentication = accountRequest.authenticationType == AuthenticationType.oidc
|
||||
? accountRequest.bearerToken
|
||||
: accountRequest.basicAuth;
|
||||
@@ -441,7 +394,7 @@ class EmailAPI with HandleSetErrorMixin {
|
||||
progress = (downloaded / total) * 100;
|
||||
}
|
||||
log('EmailAPI::downloadFileForWeb(): progress = ${progress.round()}%');
|
||||
onReceiveController.add(Right(DownloadingAllAttachmentsForWeb(
|
||||
onReceiveController?.add(Right(DownloadingAllAttachmentsForWeb(
|
||||
taskId,
|
||||
downloadFileName,
|
||||
progress,
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/model/source_type/data_source_type.dart';
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -19,7 +15,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
@@ -142,16 +137,6 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<DownloadTaskId>> downloadAttachments(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.downloadAttachments(attachments, accountId, baseDownloadUrl, accountRequest);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
Attachment attachment,
|
||||
@@ -395,26 +380,6 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) {
|
||||
return emailDataSource[DataSourceType.network]!.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
onReceiveController,
|
||||
cancelToken: cancelToken);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
@@ -575,28 +540,7 @@ class EmailRepositoryImpl extends EmailRepository {
|
||||
htmlContent,
|
||||
configuration);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) => emailDataSource[DataSourceType.network]!.downloadAllAttachmentsForWeb(
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadAllUrl,
|
||||
outputFileName,
|
||||
accountRequest,
|
||||
taskId,
|
||||
onReceiveController,
|
||||
cancelToken: cancelToken,
|
||||
);
|
||||
|
||||
|
||||
@override
|
||||
Future<DownloadedResponse> exportAllAttachments(
|
||||
AccountId accountId,
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:core/data/network/download/downloaded_response.dart';
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action.dart';
|
||||
import 'package:email_recovery/email_recovery/email_recovery_action_id.dart';
|
||||
@@ -17,7 +13,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/state.dart' as jmap;
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/email/email_content.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
@@ -59,13 +54,6 @@ abstract class EmailRepository {
|
||||
ReadActions readActions,
|
||||
);
|
||||
|
||||
Future<List<DownloadTaskId>> downloadAttachments(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest
|
||||
);
|
||||
|
||||
Future<DownloadedResponse> exportAttachment(
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
@@ -74,16 +62,6 @@ abstract class EmailRepository {
|
||||
CancelToken cancelToken
|
||||
);
|
||||
|
||||
Future<Uint8List> downloadAttachmentForWeb(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
AccountRequest accountRequest,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
Future<({
|
||||
List<EmailId> emailIdsSuccess,
|
||||
Map<Id, SetError> mapErrors,
|
||||
@@ -212,16 +190,7 @@ abstract class EmailRepository {
|
||||
String htmlContent,
|
||||
TransformConfiguration configuration);
|
||||
|
||||
Future<void> downloadAllAttachmentsForWeb(
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
String outputFileName,
|
||||
AccountRequest accountRequest,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
);
|
||||
|
||||
|
||||
Future<DownloadedResponse> exportAllAttachments(
|
||||
AccountId accountId,
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
|
||||
class DownloadAttachmentsSuccess extends UIState {
|
||||
final List<DownloadTaskId> taskIds;
|
||||
|
||||
DownloadAttachmentsSuccess(this.taskIds);
|
||||
|
||||
@override
|
||||
List<Object> get props => [taskIds];
|
||||
}
|
||||
|
||||
class DownloadAttachmentsFailure extends FeatureFailure {
|
||||
|
||||
DownloadAttachmentsFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
+10
-10
@@ -13,21 +13,21 @@ import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_all_attachments_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
|
||||
|
||||
class DownloadAllAttachmentsForWebInteractor {
|
||||
const DownloadAllAttachmentsForWebInteractor(
|
||||
this._emailRepository,
|
||||
this._downloadRepository,
|
||||
this._accountRepository,
|
||||
this._authenticationOIDCRepository,
|
||||
this.credentialRepository,
|
||||
);
|
||||
|
||||
final EmailRepository _emailRepository;
|
||||
final DownloadRepository _downloadRepository;
|
||||
final AccountRepository _accountRepository;
|
||||
final AuthenticationOIDCRepository _authenticationOIDCRepository;
|
||||
final CredentialRepository credentialRepository;
|
||||
@@ -37,16 +37,16 @@ class DownloadAllAttachmentsForWebInteractor {
|
||||
EmailId emailId,
|
||||
String baseDownloadAllUrl,
|
||||
Attachment attachment,
|
||||
DownloadTaskId taskId,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken}
|
||||
) async* {
|
||||
DownloadTaskId taskId, {
|
||||
StreamController<Either<Failure, Success>>? onReceiveController,
|
||||
CancelToken? cancelToken,
|
||||
}) async* {
|
||||
try {
|
||||
yield Right(StartDownloadAllAttachmentsForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
));
|
||||
onReceiveController.add(Right(StartDownloadAllAttachmentsForWeb(
|
||||
onReceiveController?.add(Right(StartDownloadAllAttachmentsForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
cancelToken: cancelToken,
|
||||
@@ -64,14 +64,14 @@ class DownloadAllAttachmentsForWebInteractor {
|
||||
);
|
||||
}
|
||||
|
||||
await _emailRepository.downloadAllAttachmentsForWeb(
|
||||
await _downloadRepository.downloadAllAttachmentsForWeb(
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadAllUrl,
|
||||
attachment.name!,
|
||||
accountRequest,
|
||||
taskId,
|
||||
onReceiveController,
|
||||
onReceiveController: onReceiveController,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
|
||||
|
||||
@@ -11,36 +11,36 @@ import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/domain/repository/download_repository.dart';
|
||||
|
||||
class DownloadAttachmentForWebInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
final DownloadRepository _downloadRepository;
|
||||
final CredentialRepository credentialRepository;
|
||||
final AccountRepository _accountRepository;
|
||||
final AuthenticationOIDCRepository _authenticationOIDCRepository;
|
||||
|
||||
DownloadAttachmentForWebInteractor(
|
||||
this.emailRepository,
|
||||
this._downloadRepository,
|
||||
this.credentialRepository,
|
||||
this._accountRepository,
|
||||
this._authenticationOIDCRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
StreamController<Either<Failure, Success>> onReceiveController,
|
||||
{CancelToken? cancelToken,
|
||||
bool previewerSupported = false,
|
||||
DownloadTaskId taskId,
|
||||
Attachment attachment,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl, {
|
||||
StreamController<Either<Failure, Success>>? onReceiveController,
|
||||
CancelToken? cancelToken,
|
||||
bool previewerSupported = false,
|
||||
}) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken, previewerSupported));
|
||||
onReceiveController.add(Right(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken, previewerSupported)));
|
||||
onReceiveController?.add(Right(StartDownloadAttachmentForWeb(taskId, attachment, cancelToken, previewerSupported)));
|
||||
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
AccountRequest? accountRequest;
|
||||
@@ -56,13 +56,13 @@ class DownloadAttachmentForWebInteractor {
|
||||
);
|
||||
}
|
||||
|
||||
final bytesDownloaded = await emailRepository.downloadAttachmentForWeb(
|
||||
final bytesDownloaded = await _downloadRepository.downloadAttachmentForWeb(
|
||||
taskId,
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest,
|
||||
onReceiveController,
|
||||
onReceiveController: onReceiveController,
|
||||
cancelToken: cancelToken
|
||||
);
|
||||
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/user_name.dart';
|
||||
import 'package:model/account/account_request.dart';
|
||||
import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:model/oidc/token_oidc.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachments_state.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/extensions/oidc_configuration_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
|
||||
class DownloadAttachmentsInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
final CredentialRepository credentialRepository;
|
||||
final AccountRepository _accountRepository;
|
||||
final AuthenticationOIDCRepository _authenticationOIDCRepository;
|
||||
final AuthorizationInterceptors _authorizationInterceptors;
|
||||
|
||||
DownloadAttachmentsInteractor(
|
||||
this.emailRepository,
|
||||
this.credentialRepository,
|
||||
this._accountRepository,
|
||||
this._authenticationOIDCRepository,
|
||||
this._authorizationInterceptors,
|
||||
);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
List<Attachment> attachments,
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl
|
||||
) async* {
|
||||
try {
|
||||
final currentAccount = await _accountRepository.getCurrentAccount();
|
||||
|
||||
AccountRequest? accountRequest;
|
||||
|
||||
if (currentAccount.authenticationType == AuthenticationType.oidc) {
|
||||
final tokenOidc = await _authenticationOIDCRepository.getStoredTokenOIDC(currentAccount.id);
|
||||
accountRequest = AccountRequest.withOidc(token: tokenOidc);
|
||||
} else {
|
||||
final authenticationInfoCache = await credentialRepository.getAuthenticationInfoStored();
|
||||
accountRequest = AccountRequest.withBasic(
|
||||
userName: UserName(authenticationInfoCache.username),
|
||||
password: Password(authenticationInfoCache.password),
|
||||
);
|
||||
}
|
||||
|
||||
final taskIds = await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest
|
||||
);
|
||||
|
||||
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
} catch (exception) {
|
||||
logError('DownloadAttachmentsInteractor::execute(): $exception');
|
||||
if (exception is DownloadAttachmentHasTokenExpiredException &&
|
||||
exception.refreshToken.isNotEmpty) {
|
||||
yield* _retryDownloadAttachments(
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
attachments,
|
||||
exception.refreshToken);
|
||||
} else {
|
||||
yield Left<Failure, Success>(DownloadAttachmentsFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Stream<Either<Failure, Success>> _retryDownloadAttachments(
|
||||
AccountId accountId,
|
||||
String baseDownloadUrl,
|
||||
List<Attachment> attachments,
|
||||
String refreshToken) async* {
|
||||
log('DownloadAttachmentsInteractor::_retryDownloadAttachments(): $refreshToken');
|
||||
try {
|
||||
final accountCurrent = await _accountRepository.getCurrentAccount();
|
||||
final oidcConfig = await _authenticationOIDCRepository.getStoredOidcConfiguration();
|
||||
final newTokenOIDC = await _authenticationOIDCRepository.refreshingTokensOIDC(
|
||||
oidcConfig.clientId,
|
||||
oidcConfig.redirectUrl,
|
||||
oidcConfig.discoveryUrl,
|
||||
oidcConfig.scopes,
|
||||
refreshToken);
|
||||
|
||||
await _accountRepository.deleteCurrentAccount(accountCurrent.id);
|
||||
|
||||
await _authenticationOIDCRepository.persistTokenOIDC(newTokenOIDC);
|
||||
|
||||
await _accountRepository.setCurrentAccount(
|
||||
PersonalAccount(
|
||||
newTokenOIDC.tokenIdHash,
|
||||
AuthenticationType.oidc,
|
||||
isSelected: true,
|
||||
accountId: accountId,
|
||||
apiUrl: accountCurrent.apiUrl,
|
||||
userName: accountCurrent.userName
|
||||
)
|
||||
);
|
||||
|
||||
_authorizationInterceptors.setTokenAndAuthorityOidc(
|
||||
newToken: newTokenOIDC,
|
||||
newConfig: oidcConfig);
|
||||
|
||||
final accountRequest = AccountRequest.withOidc(token: newTokenOIDC);
|
||||
|
||||
final taskIds = await emailRepository.downloadAttachments(
|
||||
attachments,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
accountRequest);
|
||||
|
||||
yield Right<Failure, Success>(DownloadAttachmentsSuccess(taskIds));
|
||||
} catch (e) {
|
||||
logError('RefreshTokenOIDCInteractor::execute(): $e');
|
||||
yield Left<Failure, Success>(DownloadAttachmentsFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-11
@@ -9,14 +9,19 @@ import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_html_content_from_attachment_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
|
||||
class GetHtmlContentFromAttachmentInteractor {
|
||||
GetHtmlContentFromAttachmentInteractor(this._downloadAttachmentForWebInteractor);
|
||||
GetHtmlContentFromAttachmentInteractor(
|
||||
this._downloadAttachmentForWebInteractor,
|
||||
this._emailRepository,
|
||||
);
|
||||
|
||||
final DownloadAttachmentForWebInteractor _downloadAttachmentForWebInteractor;
|
||||
final EmailRepository _emailRepository;
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
AccountId accountId,
|
||||
@@ -25,7 +30,6 @@ class GetHtmlContentFromAttachmentInteractor {
|
||||
String baseDownloadUrl,
|
||||
TransformConfiguration transformConfiguration,
|
||||
) async* {
|
||||
final onReceiveController = StreamController<Either<Failure, Success>>();
|
||||
try {
|
||||
yield Right(GettingHtmlContentFromAttachment(attachment: attachment));
|
||||
final downloadState = await _downloadAttachmentForWebInteractor.execute(
|
||||
@@ -33,7 +37,6 @@ class GetHtmlContentFromAttachmentInteractor {
|
||||
attachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
onReceiveController,
|
||||
).last;
|
||||
|
||||
Either<Failure, Success>? sanitizeState;
|
||||
@@ -62,7 +65,6 @@ class GetHtmlContentFromAttachmentInteractor {
|
||||
},
|
||||
);
|
||||
|
||||
onReceiveController.close();
|
||||
if (sanitizeState != null) {
|
||||
yield sanitizeState!;
|
||||
} else {
|
||||
@@ -74,7 +76,6 @@ class GetHtmlContentFromAttachmentInteractor {
|
||||
|
||||
} catch (e) {
|
||||
logError('GetHtmlContentFromAttachmentInteractor:exception: $e');
|
||||
onReceiveController.close();
|
||||
yield Left(GetHtmlContentFromAttachmentFailure(
|
||||
exception: e,
|
||||
attachment: attachment,
|
||||
@@ -88,12 +89,10 @@ class GetHtmlContentFromAttachmentInteractor {
|
||||
Attachment attachment,
|
||||
) async {
|
||||
try {
|
||||
final sanitizedHtmlContent = await _downloadAttachmentForWebInteractor
|
||||
.emailRepository
|
||||
.sanitizeHtmlContent(
|
||||
htmlContent,
|
||||
transformConfiguration,
|
||||
);
|
||||
final sanitizedHtmlContent = await _emailRepository.sanitizeHtmlContent(
|
||||
htmlContent,
|
||||
transformConfiguration,
|
||||
);
|
||||
return Right(GetHtmlContentFromAttachmentSuccess(
|
||||
sanitizedHtmlContent: sanitizedHtmlContent,
|
||||
htmlAttachmentTitle: attachment.generateFileName(),
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import 'package:core/core.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_all_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
@@ -29,18 +25,14 @@ class EmailBindings extends Bindings {
|
||||
Get.put(SingleEmailController(
|
||||
Get.find<GetEmailContentInteractor>(),
|
||||
Get.find<MarkAsEmailReadInteractor>(),
|
||||
Get.find<DownloadAttachmentsInteractor>(),
|
||||
Get.find<DeviceManager>(),
|
||||
Get.find<ExportAttachmentInteractor>(),
|
||||
Get.find<MarkAsStarEmailInteractor>(),
|
||||
Get.find<DownloadAttachmentForWebInteractor>(),
|
||||
Get.find<GetAllIdentitiesInteractor>(),
|
||||
Get.find<StoreOpenedEmailInteractor>(),
|
||||
Get.find<PrintEmailInteractor>(),
|
||||
Get.find<ParseEmailByBlobIdInteractor>(),
|
||||
Get.find<PreviewEmailFromEmlFileInteractor>(),
|
||||
Get.find<GetHtmlContentFromAttachmentInteractor>(),
|
||||
Get.find<DownloadAllAttachmentsForWebInteractor>(),
|
||||
Get.find<ExportAllAttachmentsInteractor>(),
|
||||
currentEmailId: currentEmailId,
|
||||
), tag: tag);
|
||||
|
||||
@@ -16,9 +16,7 @@ import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/network/email_api.dart';
|
||||
import 'package:tmail_ui_user/features/email/data/repository/email_repository_impl.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_all_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
@@ -32,7 +30,6 @@ import 'package:tmail_ui_user/features/email/domain/usecases/parse_email_by_blob
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/preview_email_from_eml_file_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/print_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/store_opened_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/network/interceptors/authorization_interceptors.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_oidc_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
@@ -118,13 +115,6 @@ class EmailInteractorBindings extends InteractorsBindings {
|
||||
void bindingsInteractor() {
|
||||
Get.lazyPut(() => GetEmailContentInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => MarkAsEmailReadInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => DownloadAttachmentsInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<AuthenticationOIDCRepository>(),
|
||||
Get.find<AuthorizationInterceptors>(),
|
||||
));
|
||||
Get.lazyPut(() => ExportAttachmentInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
@@ -133,23 +123,16 @@ class EmailInteractorBindings extends InteractorsBindings {
|
||||
));
|
||||
Get.lazyPut(() => MoveToMailboxInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => MarkAsStarEmailInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => DownloadAttachmentForWebInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<CredentialRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<AuthenticationOIDCRepository>()));
|
||||
Get.lazyPut(() => GetStoredEmailStateInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => StoreOpenedEmailInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => PrintEmailInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => ParseEmailByBlobIdInteractor(Get.find<EmailRepository>()));
|
||||
Get.lazyPut(() => PreviewEmailFromEmlFileInteractor(Get.find<EmailRepository>()));
|
||||
IdentityInteractorsBindings().dependencies();
|
||||
Get.lazyPut(() => GetHtmlContentFromAttachmentInteractor(Get.find<DownloadAttachmentForWebInteractor>()));
|
||||
Get.lazyPut(() => DownloadAllAttachmentsForWebInteractor(
|
||||
Get.lazyPut(() => GetHtmlContentFromAttachmentInteractor(
|
||||
Get.find<DownloadAttachmentForWebInteractor>(),
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
Get.find<AuthenticationOIDCRepository>(),
|
||||
Get.find<CredentialRepository>()));
|
||||
));
|
||||
Get.lazyPut(() => ExportAllAttachmentsInteractor(
|
||||
Get.find<EmailRepository>(),
|
||||
Get.find<AccountRepository>(),
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:open_file/open_file.dart' as open_file;
|
||||
import 'package:core/core.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/text/sanitize_autolink_unescape_html_transformer.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/sanitize_hyper_link_tag_in_html_transformers.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/text/new_line_transformer.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/text/sanitize_autolink_unescape_html_transformer.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/text/standardize_html_sanitizing_transformers.dart';
|
||||
import 'package:core/utils/html/html_utils.dart';
|
||||
import 'package:core/presentation/utils/html_transformer/dom/sanitize_hyper_link_tag_in_html_transformers.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -15,8 +14,6 @@ import 'package:flutter/services.dart';
|
||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get_navigation/src/dialog/dialog_route.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/id.dart';
|
||||
@@ -31,10 +28,9 @@ import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/keyword_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/mdn/disposition.dart';
|
||||
import 'package:jmap_dart_client/jmap/mdn/mdn.dart';
|
||||
import 'package:model/email/eml_attachment.dart';
|
||||
import 'package:model/error_type_handler/unknown_uri_exception.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:open_file/open_file.dart' as open_file;
|
||||
import 'package:pointer_interceptor/pointer_interceptor.dart';
|
||||
import 'package:tmail_ui_user/features/base/base_controller.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
|
||||
@@ -53,9 +49,7 @@ import 'package:tmail_ui_user/features/email/domain/state/calendar_event_counter
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_maybe_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reject_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reply_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_all_attachments_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachments_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/export_all_attachments_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/export_attachment_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
|
||||
@@ -72,22 +66,19 @@ import 'package:tmail_ui_user/features/email/domain/state/send_receipt_to_sender
|
||||
import 'package:tmail_ui_user/features/email/domain/state/unsubscribe_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_accept_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_counter_accept_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_all_attachments_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_all_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_entire_message_as_document_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/calendar_event_reject_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_all_attachments_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/export_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_entire_message_as_document_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_html_content_from_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/maybe_calendar_event_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/parse_calendar_event_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/parse_email_by_blob_id_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/preview_email_from_eml_file_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/print_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_html_content_from_attachment_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/send_receipt_to_sender_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/store_opened_email_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/action/email_ui_action.dart';
|
||||
@@ -112,11 +103,12 @@ import 'package:tmail_ui_user/features/email_previewer/email_previewer_dialog_vi
|
||||
import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox/presentation/action/mailbox_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/action/download_ui_action.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/handle_download_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/open_and_close_composer_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/extensions/update_current_emails_flags_extension.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/dashboard_routes.dart';
|
||||
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/model/download/download_task_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/create_new_rule_filter_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/state/get_all_identities_state.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/usecases/create_new_email_rule_filter_interactor.dart';
|
||||
@@ -137,12 +129,6 @@ import 'package:tmail_ui_user/main/routes/navigation_router.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_utils.dart';
|
||||
import 'package:twake_previewer_flutter/core/constants/supported_charset.dart';
|
||||
import 'package:twake_previewer_flutter/core/previewer_options/options/previewer_state.dart';
|
||||
import 'package:twake_previewer_flutter/core/previewer_options/options/top_bar_options.dart';
|
||||
import 'package:twake_previewer_flutter/core/previewer_options/previewer_options.dart';
|
||||
import 'package:twake_previewer_flutter/twake_image_previewer/twake_image_previewer.dart';
|
||||
import 'package:twake_previewer_flutter/twake_plain_text_previewer/twake_plain_text_previewer.dart';
|
||||
|
||||
class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
@@ -152,18 +138,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
final GetEmailContentInteractor _getEmailContentInteractor;
|
||||
final MarkAsEmailReadInteractor _markAsEmailReadInteractor;
|
||||
final DownloadAttachmentsInteractor _downloadAttachmentsInteractor;
|
||||
final DeviceManager _deviceManager;
|
||||
final ExportAttachmentInteractor _exportAttachmentInteractor;
|
||||
final MarkAsStarEmailInteractor _markAsStarEmailInteractor;
|
||||
final DownloadAttachmentForWebInteractor _downloadAttachmentForWebInteractor;
|
||||
final GetAllIdentitiesInteractor _getAllIdentitiesInteractor;
|
||||
final StoreOpenedEmailInteractor _storeOpenedEmailInteractor;
|
||||
final PrintEmailInteractor _printEmailInteractor;
|
||||
final ParseEmailByBlobIdInteractor _parseEmailByBlobIdInteractor;
|
||||
final PreviewEmailFromEmlFileInteractor _previewEmailFromEmlFileInteractor;
|
||||
final GetHtmlContentFromAttachmentInteractor _getHtmlContentFromAttachmentInteractor;
|
||||
final DownloadAllAttachmentsForWebInteractor _downloadAllAttachmentsForWebInteractor;
|
||||
final ExportAllAttachmentsInteractor _exportAllAttachmentsInteractor;
|
||||
final EmailId? _currentEmailId;
|
||||
|
||||
@@ -197,10 +179,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
final obxListeners = <Worker>[];
|
||||
late final EmailActionReactor emailActionReactor;
|
||||
|
||||
final StreamController<Either<Failure, Success>> _downloadProgressStateController =
|
||||
StreamController<Either<Failure, Success>>.broadcast();
|
||||
Stream<Either<Failure, Success>> get downloadProgressState => _downloadProgressStateController.stream;
|
||||
|
||||
ThreadDetailController? get threadDetailController => _threadDetailController;
|
||||
|
||||
PresentationEmail? get currentEmail {
|
||||
@@ -235,18 +213,14 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
SingleEmailController(
|
||||
this._getEmailContentInteractor,
|
||||
this._markAsEmailReadInteractor,
|
||||
this._downloadAttachmentsInteractor,
|
||||
this._deviceManager,
|
||||
this._exportAttachmentInteractor,
|
||||
this._markAsStarEmailInteractor,
|
||||
this._downloadAttachmentForWebInteractor,
|
||||
this._getAllIdentitiesInteractor,
|
||||
this._storeOpenedEmailInteractor,
|
||||
this._printEmailInteractor,
|
||||
this._parseEmailByBlobIdInteractor,
|
||||
this._previewEmailFromEmlFileInteractor,
|
||||
this._getHtmlContentFromAttachmentInteractor,
|
||||
this._downloadAllAttachmentsForWebInteractor,
|
||||
this._exportAllAttachmentsInteractor, {
|
||||
EmailId? currentEmailId,
|
||||
}) : _currentEmailId = currentEmailId;
|
||||
@@ -259,14 +233,12 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_threadDetailController = getBinding<ThreadDetailController>();
|
||||
_injectCalendarEventBindings(session, accountId);
|
||||
_registerObxStreamListener();
|
||||
_listenDownloadAttachmentProgressState();
|
||||
emailActionReactor = EmailActionReactor(
|
||||
_markAsEmailReadInteractor,
|
||||
_markAsStarEmailInteractor,
|
||||
_createNewEmailRuleFilterInteractor,
|
||||
_printEmailInteractor,
|
||||
_getEmailContentInteractor,
|
||||
_downloadAttachmentForWebInteractor,
|
||||
);
|
||||
super.onInit();
|
||||
}
|
||||
@@ -274,7 +246,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
@override
|
||||
void onClose() {
|
||||
_threadDetailController = null;
|
||||
_downloadProgressStateController.close();
|
||||
CalendarEventInteractorBindings().dispose();
|
||||
MdnInteractorBindings().dispose();
|
||||
super.onClose();
|
||||
@@ -282,7 +253,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
@override
|
||||
void handleSuccessViewState(Success success) {
|
||||
super.handleSuccessViewState(success);
|
||||
if (success is GetEmailContentSuccess) {
|
||||
_getEmailContentSuccess(success);
|
||||
} else if (success is GetEmailContentFromCacheSuccess) {
|
||||
@@ -295,14 +265,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_exportAllAttachmentsSuccessAction(success);
|
||||
} else if (success is MarkAsStarEmailSuccess) {
|
||||
_markAsEmailStarSuccess(success);
|
||||
} else if (success is DownloadAttachmentForWebSuccess) {
|
||||
_downloadAttachmentForWebSuccessAction(success);
|
||||
} else if (success is StartDownloadAttachmentForWeb) {
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
} else if (success is DownloadingAttachmentForWeb) {
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
} else if (success is DownloadAllAttachmentsForWebSuccess) {
|
||||
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
||||
} else if (success is GetAllIdentitiesSuccess) {
|
||||
_getAllIdentitiesSuccess(success);
|
||||
} else if (success is SendReceiptToSenderSuccess) {
|
||||
@@ -337,24 +299,19 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
));
|
||||
} else if (success is GettingHtmlContentFromAttachment) {
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
} else {
|
||||
super.handleSuccessViewState(success);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleFailureViewState(Failure failure) {
|
||||
super.handleFailureViewState(failure);
|
||||
if (failure is MarkAsEmailReadFailure) {
|
||||
_handleMarkAsEmailReadFailure(failure);
|
||||
} else if (failure is DownloadAttachmentsFailure) {
|
||||
_downloadAttachmentsFailure(failure);
|
||||
} else if (failure is ExportAttachmentFailure) {
|
||||
_exportAttachmentFailureAction(failure);
|
||||
} else if (failure is ExportAllAttachmentsFailure) {
|
||||
_exportAllAttachmentsFailureAction(failure);
|
||||
} else if (failure is DownloadAttachmentForWebFailure) {
|
||||
_downloadAttachmentForWebFailureAction(failure);
|
||||
} else if (failure is DownloadAllAttachmentsForWebFailure) {
|
||||
_downloadAllAttachmentsForWebFailure(failure);
|
||||
} else if (failure is ParseCalendarEventFailure) {
|
||||
_handleParseCalendarEventFailure(failure);
|
||||
} else if (failure is GetEmailContentFailure) {
|
||||
@@ -371,6 +328,8 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_handleGetHtmlContentFromAttachmentFailure(failure);
|
||||
} else if (failure is PreviewPDFFileFailure) {
|
||||
_handlePreviewPDFFileFailure(failure);
|
||||
} else {
|
||||
super.handleFailureViewState(failure);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,6 +422,15 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
||||
obxListeners.add(ever(
|
||||
mailboxDashBoardController.downloadController.downloadUIAction,
|
||||
(action) {
|
||||
if (action is UpdateAttachmentsViewStateAction) {
|
||||
_updateAttachmentsViewState(action.blobId, Right(action.success));
|
||||
}
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
void _handleOpenEmailDetailedView() {
|
||||
@@ -494,78 +462,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_getEmailContentAction(emailId);
|
||||
}
|
||||
|
||||
void _listenDownloadAttachmentProgressState() {
|
||||
downloadProgressState.listen((state) {
|
||||
log('SingleEmailController::_listenDownloadAttachmentProgressState(): $state');
|
||||
state.fold(
|
||||
(failure) => null,
|
||||
(success) {
|
||||
if (success is StartDownloadAttachmentForWeb && !success.previewerSupported) {
|
||||
mailboxDashBoardController.addDownloadTask(
|
||||
DownloadTaskState(
|
||||
taskId: success.taskId,
|
||||
attachment: success.attachment,
|
||||
onCancel: () => success.cancelToken?.cancel(),
|
||||
),
|
||||
);
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null && !success.previewerSupported) {
|
||||
appToast.showToastMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).your_download_has_started,
|
||||
leadingSVGIconColor: AppColor.primaryColor,
|
||||
leadingSVGIcon: imagePaths.icDownload);
|
||||
}
|
||||
} else if (success is DownloadingAttachmentForWeb) {
|
||||
final percent = success.progress.round();
|
||||
log('SingleEmailController::DownloadingAttachmentForWeb(): $percent%');
|
||||
|
||||
mailboxDashBoardController.updateDownloadTask(
|
||||
success.taskId,
|
||||
(currentTask) {
|
||||
final newTask = currentTask.copyWith(
|
||||
progress: success.progress,
|
||||
downloaded: success.downloaded,
|
||||
total: success.total);
|
||||
|
||||
return newTask;
|
||||
});
|
||||
} else if (success is StartDownloadAllAttachmentsForWeb) {
|
||||
mailboxDashBoardController.addDownloadTask(
|
||||
DownloadTaskState(
|
||||
taskId: success.taskId,
|
||||
attachment: success.attachment,
|
||||
onCancel: () => success.cancelToken?.cancel(),
|
||||
),
|
||||
);
|
||||
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastSuccessMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).creatingAnArchiveForDownloading,
|
||||
leadingSVGIconColor: Colors.white,
|
||||
leadingSVGIcon: imagePaths.icDownloadAll,
|
||||
);
|
||||
}
|
||||
} else if (success is DownloadingAllAttachmentsForWeb) {
|
||||
final percent = success.progress.round();
|
||||
log('SingleEmailController::DownloadingAttachmentForWeb(): $percent%');
|
||||
|
||||
mailboxDashBoardController.updateDownloadTask(
|
||||
success.taskId,
|
||||
(currentTask) {
|
||||
final newTask = currentTask.copyWith(
|
||||
progress: success.progress,
|
||||
downloaded: success.downloaded,
|
||||
total: success.total);
|
||||
|
||||
return newTask;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void _injectAndGetInteractorBindings(Session? session, AccountId accountId) {
|
||||
injectRuleFilterBindings(session, accountId);
|
||||
injectMdnBindings(session, accountId);
|
||||
@@ -850,71 +746,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_threadDetailController?.markCollapsedEmailReadSuccess(success);
|
||||
}
|
||||
|
||||
void downloadAttachments(BuildContext context, List<Attachment> attachments) async {
|
||||
final needRequestPermission = await _deviceManager.isNeedRequestStoragePermissionOnAndroid();
|
||||
|
||||
if (needRequestPermission) {
|
||||
final status = await Permission.storage.status;
|
||||
switch (status) {
|
||||
case PermissionStatus.granted:
|
||||
_downloadAttachmentsAction(attachments);
|
||||
break;
|
||||
case PermissionStatus.permanentlyDenied:
|
||||
if (context.mounted && currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(context).you_need_to_grant_files_permission_to_download_attachments,
|
||||
);
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
final requested = await Permission.storage.request();
|
||||
switch (requested) {
|
||||
case PermissionStatus.granted:
|
||||
_downloadAttachmentsAction(attachments);
|
||||
break;
|
||||
default:
|
||||
if (context.mounted && currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(context).you_need_to_grant_files_permission_to_download_attachments,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_downloadAttachmentsAction(attachments);
|
||||
}
|
||||
}
|
||||
|
||||
void _downloadAttachmentsAction(List<Attachment> attachments) {
|
||||
if (accountId != null && session != null) {
|
||||
try {
|
||||
final baseDownloadUrl = session!.getDownloadUrl(
|
||||
jmapUrl: dynamicUrlInterceptors.jmapUrl,
|
||||
);
|
||||
consumeState(_downloadAttachmentsInteractor.execute(
|
||||
attachments,
|
||||
accountId!,
|
||||
baseDownloadUrl,
|
||||
));
|
||||
} catch (e) {
|
||||
logError('SingleEmailController::_downloadAttachmentsAction(): $e');
|
||||
consumeState(Stream.value(Left(DownloadAttachmentsFailure(e))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _downloadAttachmentsFailure(DownloadAttachmentsFailure failure) {
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).attachment_download_failed);
|
||||
}
|
||||
}
|
||||
|
||||
void exportAttachment(Attachment attachment) {
|
||||
final cancelToken = CancelToken();
|
||||
_showDownloadingFileDialog(attachment.name ?? '', cancelToken: cancelToken);
|
||||
@@ -1082,76 +913,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
await FlutterFileDialog.saveFile(params: params);
|
||||
}
|
||||
|
||||
void downloadAttachmentForWeb(Attachment attachment, {bool previewerSupported = false}) {
|
||||
if (accountId != null && session != null) {
|
||||
final generateTaskId = DownloadTaskId(uuid.v4());
|
||||
try {
|
||||
final baseDownloadUrl = session!.getDownloadUrl(
|
||||
jmapUrl: dynamicUrlInterceptors.jmapUrl,
|
||||
);
|
||||
final cancelToken = CancelToken();
|
||||
consumeState(_downloadAttachmentForWebInteractor.execute(
|
||||
generateTaskId,
|
||||
attachment,
|
||||
accountId!,
|
||||
baseDownloadUrl,
|
||||
_downloadProgressStateController,
|
||||
cancelToken: cancelToken,
|
||||
previewerSupported: previewerSupported,
|
||||
));
|
||||
} catch (e) {
|
||||
logError('SingleEmailController::downloadAttachmentForWeb(): $e');
|
||||
consumeState(Stream.value(Left(DownloadAttachmentForWebFailure(attachment: attachment, taskId: generateTaskId, exception: e))));
|
||||
}
|
||||
} else {
|
||||
consumeState(Stream.value(
|
||||
Left(DownloadAttachmentForWebFailure(
|
||||
attachment: attachment,
|
||||
exception: NotFoundSessionException()))
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void downloadAllAttachmentsForWeb(String outputFileName) {
|
||||
final taskId = DownloadTaskId(uuid.v4());
|
||||
final session = this.session;
|
||||
final accountId = this.accountId;
|
||||
|
||||
if (accountId == null || session == null) {
|
||||
consumeState(Stream.value(Left(DownloadAllAttachmentsForWebFailure(
|
||||
exception: NotFoundSessionException(),
|
||||
taskId: taskId,
|
||||
))));
|
||||
return;
|
||||
}
|
||||
|
||||
final downloadAllSupported = session.isDownloadAllSupported(accountId);
|
||||
final emailId = currentEmail?.id;
|
||||
|
||||
if (!downloadAllSupported || emailId == null) {
|
||||
consumeState(Stream.value(Left(DownloadAllAttachmentsForWebFailure(
|
||||
taskId: taskId,
|
||||
))));
|
||||
return;
|
||||
}
|
||||
|
||||
final baseDownloadAllUrl = session.getDownloadAllCapability(accountId)!.endpoint!;
|
||||
final downloadAttachment = Attachment(
|
||||
name: outputFileName,
|
||||
type: MediaType('application', 'zip'),
|
||||
);
|
||||
final cancelToken = CancelToken();
|
||||
consumeState(_downloadAllAttachmentsForWebInteractor.execute(
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadAllUrl,
|
||||
downloadAttachment,
|
||||
taskId,
|
||||
_downloadProgressStateController,
|
||||
cancelToken: cancelToken,
|
||||
));
|
||||
}
|
||||
|
||||
bool isDownloadAllSupported() {
|
||||
return session?.isDownloadAllSupported(accountId) ?? false;
|
||||
}
|
||||
@@ -1160,74 +921,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
return isDownloadAllSupported() && attachments.length > 1;
|
||||
}
|
||||
|
||||
void _downloadAllAttachmentsForWebFailure(
|
||||
DownloadAllAttachmentsForWebFailure failure,
|
||||
) {
|
||||
mailboxDashBoardController.deleteDownloadTask(failure.taskId);
|
||||
if (currentOverlayContext == null || currentContext == null) return;
|
||||
String message = AppLocalizations.of(currentContext!).attachment_download_failed;
|
||||
if (failure.cancelToken?.isCancelled == true) {
|
||||
message = AppLocalizations.of(currentContext!).downloadAttachmentHasBeenCancelled;
|
||||
}
|
||||
appToast.showToastErrorMessage(currentOverlayContext!, message);
|
||||
}
|
||||
|
||||
void _downloadAttachmentForWebSuccessAction(DownloadAttachmentForWebSuccess success) {
|
||||
log('SingleEmailController::_downloadAttachmentForWebSuccessAction():');
|
||||
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
|
||||
mailboxDashBoardController.deleteDownloadTask(success.taskId);
|
||||
|
||||
if (!success.previewerSupported) {
|
||||
_downloadManager.createAnchorElementDownloadFileWeb(
|
||||
success.bytes,
|
||||
success.attachment.generateFileName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (success.attachment.isImage) {
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
Navigator.of(currentContext!).push(GetDialogRoute(
|
||||
pageBuilder: (context, _, __) => PointerInterceptor(child: TwakeImagePreviewer(
|
||||
bytes: success.bytes,
|
||||
zoomable: true,
|
||||
previewerOptions: const PreviewerOptions(
|
||||
previewerState: PreviewerState.success,
|
||||
),
|
||||
topBarOptions: TopBarOptions(
|
||||
title: success.attachment.generateFileName(),
|
||||
onClose: () => Navigator.maybePop(context),
|
||||
onDownload: currentContext == null
|
||||
? null
|
||||
: () => handleDownloadAttachmentAction(success.attachment),
|
||||
),
|
||||
)),
|
||||
barrierDismissible: false,
|
||||
));
|
||||
} else if (success.attachment.isText || success.attachment.isJson) {
|
||||
_updateAttachmentsViewState(success.attachment.blobId, Right(success));
|
||||
Navigator.of(currentContext!).push(GetDialogRoute(
|
||||
pageBuilder: (context, _, __) => PointerInterceptor(child: TwakePlainTextPreviewer(
|
||||
supportedCharset: SupportedCharset.utf8,
|
||||
bytes: success.bytes,
|
||||
previewerOptions: PreviewerOptions(
|
||||
previewerState: PreviewerState.success,
|
||||
width: currentContext == null ? 200 : currentContext!.width * 0.8,
|
||||
),
|
||||
topBarOptions: TopBarOptions(
|
||||
title: success.attachment.generateFileName(),
|
||||
onClose: () => Navigator.maybePop(context),
|
||||
onDownload: currentContext == null
|
||||
? null
|
||||
: () => handleDownloadAttachmentAction(success.attachment),
|
||||
),
|
||||
)),
|
||||
barrierDismissible: false,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _downloadPDFFile(Uint8List bytes, String fileName) {
|
||||
_downloadManager.createAnchorElementDownloadFileWeb(bytes, fileName);
|
||||
}
|
||||
@@ -1236,28 +929,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
await _printUtils.printPDFFile(bytes, fileName);
|
||||
}
|
||||
|
||||
void _downloadAttachmentForWebFailureAction(DownloadAttachmentForWebFailure failure) {
|
||||
log('SingleEmailController::_downloadAttachmentForWebFailureAction(): $failure');
|
||||
if (failure.taskId != null) {
|
||||
mailboxDashBoardController.deleteDownloadTask(failure.taskId!);
|
||||
}
|
||||
|
||||
if (failure.attachment != null) {
|
||||
_updateAttachmentsViewState(failure.attachment?.blobId, Left(failure));
|
||||
}
|
||||
|
||||
if (currentOverlayContext == null || currentContext == null) return;
|
||||
|
||||
String message = AppLocalizations.of(currentContext!).attachment_download_failed;
|
||||
if (failure.attachment is EMLAttachment) {
|
||||
message = AppLocalizations.of(currentContext!).downloadMessageAsEMLFailed;
|
||||
} else if (failure.cancelToken?.isCancelled == true) {
|
||||
message = AppLocalizations.of(currentContext!).downloadAttachmentHasBeenCancelled;
|
||||
}
|
||||
|
||||
appToast.showToastErrorMessage(currentOverlayContext!, message);
|
||||
}
|
||||
|
||||
void _updateAttachmentsViewState(
|
||||
Id? attachmentBlobId,
|
||||
Either<Failure, Success> viewState) {
|
||||
@@ -1444,7 +1115,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
_printEmail(presentationEmail);
|
||||
break;
|
||||
case EmailActionType.downloadMessageAsEML:
|
||||
_downloadMessageAsEML(presentationEmail);
|
||||
mailboxDashBoardController.downloadMessageAsEML(presentationEmail);
|
||||
break;
|
||||
case EmailActionType.editAsNewEmail:
|
||||
_editAsNewEmail(presentationEmail);
|
||||
@@ -1981,17 +1652,6 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
toastManager.showMessageFailure(failure);
|
||||
}
|
||||
|
||||
void _downloadMessageAsEML(PresentationEmail presentationEmail) {
|
||||
if (accountId == null || session == null) return;
|
||||
|
||||
consumeState(emailActionReactor.downloadMessageAsEML(
|
||||
session!,
|
||||
accountId!,
|
||||
presentationEmail,
|
||||
downloadProgressStateController: _downloadProgressStateController,
|
||||
));
|
||||
}
|
||||
|
||||
void _editAsNewEmail(PresentationEmail presentationEmail) {
|
||||
if (accountId == null || session == null) return;
|
||||
|
||||
@@ -2030,7 +1690,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
{bool previewerSupported = false}
|
||||
) {
|
||||
if (PlatformInfo.isWeb) {
|
||||
downloadAttachmentForWeb(attachment, previewerSupported: previewerSupported);
|
||||
mailboxDashBoardController.downloadAttachmentForWeb(
|
||||
attachment: attachment,
|
||||
previewerSupported: previewerSupported,
|
||||
);
|
||||
} else if (PlatformInfo.isMobile) {
|
||||
exportAttachment(attachment);
|
||||
} else {
|
||||
@@ -2040,7 +1703,10 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
|
||||
|
||||
void handleDownloadAllAttachmentsAction(String outputFileName) {
|
||||
if (PlatformInfo.isWeb) {
|
||||
downloadAllAttachmentsForWeb(outputFileName);
|
||||
mailboxDashBoardController.downloadAllAttachmentsForWeb(
|
||||
outputFileName: outputFileName,
|
||||
currentEmail: currentEmail,
|
||||
);
|
||||
} else if (PlatformInfo.isMobile) {
|
||||
exportAllAttachments(outputFileName);
|
||||
} else {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:core/data/network/config/dynamic_url_interceptors.dart';
|
||||
import 'package:core/domain/extensions/datetime_extension.dart';
|
||||
import 'package:core/presentation/extensions/color_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
@@ -11,10 +10,8 @@ import 'package:core/presentation/utils/html_transformer/transform_configuration
|
||||
import 'package:core/presentation/utils/responsive_utils.dart';
|
||||
import 'package:core/presentation/utils/theme_utils.dart';
|
||||
import 'package:core/presentation/views/bottom_popup/confirmation_dialog_action_sheet_builder.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -23,7 +20,6 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/download/download_task_id.dart';
|
||||
import 'package:model/email/email_action_type.dart';
|
||||
import 'package:model/email/mark_star_action.dart';
|
||||
import 'package:model/email/presentation_email.dart';
|
||||
@@ -32,21 +28,17 @@ import 'package:model/extensions/email_address_extension.dart';
|
||||
import 'package:model/extensions/list_email_address_extension.dart';
|
||||
import 'package:model/extensions/presentation_email_extension.dart';
|
||||
import 'package:model/extensions/presentation_mailbox_extension.dart';
|
||||
import 'package:model/extensions/session_extension.dart';
|
||||
import 'package:model/mailbox/presentation_mailbox.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/message_dialog_action_manager.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/context_menu/context_menu_item_action.dart';
|
||||
import 'package:tmail_ui_user/features/base/widget/popup_menu/popup_menu_item_action_widget.dart';
|
||||
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/email_print.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/mark_read_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_action.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/model/move_to_mailbox_request.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/download_attachment_for_web_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/print_email_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/download_attachment_for_web_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_email_read_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/mark_as_star_email_interactor.dart';
|
||||
@@ -70,7 +62,6 @@ import 'package:tmail_ui_user/main/routes/navigation_router.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_utils.dart';
|
||||
import 'package:tmail_ui_user/main/utils/app_utils.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
typedef OpenBottomSheetContextMenuAction = Future<void> Function({
|
||||
required BuildContext context,
|
||||
@@ -93,7 +84,6 @@ class EmailActionReactor {
|
||||
this._createNewEmailRuleFilterInteractor,
|
||||
this._printEmailInteractor,
|
||||
this._getEmailContentInteractor,
|
||||
this._downloadAttachmentForWebInteractor,
|
||||
);
|
||||
|
||||
final MarkAsEmailReadInteractor _markAsEmailReadInteractor;
|
||||
@@ -101,7 +91,6 @@ class EmailActionReactor {
|
||||
final CreateNewEmailRuleFilterInteractor? _createNewEmailRuleFilterInteractor;
|
||||
final PrintEmailInteractor _printEmailInteractor;
|
||||
final GetEmailContentInteractor _getEmailContentInteractor;
|
||||
final DownloadAttachmentForWebInteractor _downloadAttachmentForWebInteractor;
|
||||
|
||||
static final _isEmailAddressDialogOpened = false.obs;
|
||||
static bool get isDialogOpened => _isEmailAddressDialogOpened.value;
|
||||
@@ -429,45 +418,6 @@ class EmailActionReactor {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Stream<Either<Failure, Success>> downloadMessageAsEML(
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
PresentationEmail presentationEmail, {
|
||||
required StreamController<Either<Failure, Success>> downloadProgressStateController,
|
||||
}) async* {
|
||||
final emlAttachment = presentationEmail.createEMLAttachment();
|
||||
if (emlAttachment.blobId == null) {
|
||||
yield* Stream.value(Left(DownloadAttachmentForWebFailure(
|
||||
exception: NotFoundEmailBlobIdException(),
|
||||
)));
|
||||
return;
|
||||
}
|
||||
|
||||
final generateTaskId = DownloadTaskId(const Uuid().v4());
|
||||
try {
|
||||
final baseDownloadUrl = session.getDownloadUrl(
|
||||
jmapUrl: getBinding<DynamicUrlInterceptors>()?.jmapUrl,
|
||||
);
|
||||
final cancelToken = CancelToken();
|
||||
yield* _downloadAttachmentForWebInteractor.execute(
|
||||
generateTaskId,
|
||||
emlAttachment,
|
||||
accountId,
|
||||
baseDownloadUrl,
|
||||
downloadProgressStateController,
|
||||
cancelToken: cancelToken,
|
||||
previewerSupported: false,
|
||||
);
|
||||
} catch (e) {
|
||||
logError('SingleEmailController::downloadAttachmentForWeb(): $e');
|
||||
yield* Stream.value(Left(DownloadAttachmentForWebFailure(
|
||||
attachment: emlAttachment,
|
||||
taskId: generateTaskId,
|
||||
exception: e,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
void editAsNewEmail(
|
||||
PresentationEmail presentationEmail, {
|
||||
|
||||
@@ -91,7 +91,7 @@ class _PDFViewerState extends State<PDFViewer> {
|
||||
widget.attachment,
|
||||
widget.accountId,
|
||||
widget.downloadUrl,
|
||||
_downloadAttachmentStreamController,
|
||||
onReceiveController: _downloadAttachmentStreamController,
|
||||
cancelToken: _downloadAttachmentCancelToken
|
||||
).listen((viewState) {
|
||||
viewState.fold(
|
||||
|
||||
Reference in New Issue
Block a user