TF-1961 Transform html email content in composer
(cherry picked from commit f5470c130744242195b265a0ea4aad044ad8e740)
This commit is contained in:
@@ -3,4 +3,6 @@ class CannotDeleteOldEmailException implements Exception {}
|
||||
|
||||
class NotFoundEmailException implements Exception {}
|
||||
|
||||
class NotFoundEmailContentException implements Exception {}
|
||||
class NotFoundEmailContentException implements Exception {}
|
||||
|
||||
class EmptyEmailContentException implements Exception {}
|
||||
@@ -4,6 +4,7 @@ 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:jmap_dart_client/jmap/account_id.dart';
|
||||
@@ -69,14 +70,10 @@ abstract class EmailRepository {
|
||||
|
||||
Future<List<EmailContent>> transformEmailContent(
|
||||
List<EmailContent> emailContents,
|
||||
List<Attachment> attachmentInlines,
|
||||
String? baseUrlDownload,
|
||||
AccountId accountId,
|
||||
{bool draftsEmail = false}
|
||||
Map<String, String> mapCidImageDownloadUrl,
|
||||
TransformConfiguration transformConfiguration
|
||||
);
|
||||
|
||||
Future<List<EmailContent>> addTooltipWhenHoverOnLink(List<EmailContent> emailContents);
|
||||
|
||||
Future<Email> saveEmailAsDrafts(Session session, AccountId accountId, Email email);
|
||||
|
||||
Future<bool> removeEmailDrafts(Session session, AccountId accountId, EmailId emailId);
|
||||
@@ -102,4 +99,9 @@ abstract class EmailRepository {
|
||||
Future<DetailedEmail> getStoredOpenedEmail(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<DetailedEmail> getStoredNewEmail(Session session, AccountId accountId, EmailId emailId);
|
||||
|
||||
Future<String> transformHtmlEmailContent(
|
||||
String htmlContent,
|
||||
TransformConfiguration configuration
|
||||
);
|
||||
}
|
||||
@@ -6,41 +6,38 @@ import 'package:model/email/attachment.dart';
|
||||
class GetEmailContentLoading extends LoadingState {}
|
||||
|
||||
class GetEmailContentSuccess extends UIState {
|
||||
final String emailContent;
|
||||
final String emailContentDisplayed;
|
||||
final String htmlEmailContent;
|
||||
final List<Attachment> attachments;
|
||||
final Email? emailCurrent;
|
||||
|
||||
GetEmailContentSuccess({
|
||||
required this.emailContent,
|
||||
required this.emailContentDisplayed,
|
||||
required this.attachments,
|
||||
required this.emailCurrent
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
emailContent,
|
||||
emailContentDisplayed,
|
||||
attachments,
|
||||
emailCurrent
|
||||
];
|
||||
}
|
||||
|
||||
class GetEmailContentFromCacheSuccess extends UIState {
|
||||
final String emailContent;
|
||||
final List<Attachment> attachments;
|
||||
final Email? emailCurrent;
|
||||
|
||||
GetEmailContentFromCacheSuccess({
|
||||
required this.emailContent,
|
||||
required this.htmlEmailContent,
|
||||
required this.attachments,
|
||||
this.emailCurrent
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
emailContent,
|
||||
htmlEmailContent,
|
||||
attachments,
|
||||
emailCurrent
|
||||
];
|
||||
}
|
||||
|
||||
class GetEmailContentFromCacheSuccess extends UIState {
|
||||
final String htmlEmailContent;
|
||||
final List<Attachment> attachments;
|
||||
final Email? emailCurrent;
|
||||
|
||||
GetEmailContentFromCacheSuccess({
|
||||
required this.htmlEmailContent,
|
||||
required this.attachments,
|
||||
this.emailCurrent
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
htmlEmailContent,
|
||||
attachments,
|
||||
emailCurrent,
|
||||
];
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
|
||||
class TransformHtmlEmailContentLoading extends LoadingState {}
|
||||
|
||||
class TransformHtmlEmailContentSuccess extends UIState {
|
||||
final String htmlContent;
|
||||
|
||||
TransformHtmlEmailContentSuccess(this.htmlContent);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [htmlContent];
|
||||
}
|
||||
|
||||
class TransformHtmlEmailContentFailure extends FeatureFailure {
|
||||
|
||||
TransformHtmlEmailContentFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
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/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
@@ -20,19 +21,16 @@ class GetEmailContentInteractor {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String? baseDownloadUrl,
|
||||
{
|
||||
bool composeEmail = false,
|
||||
bool draftsEmail = false
|
||||
}
|
||||
String baseDownloadUrl,
|
||||
TransformConfiguration transformConfiguration,
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(GetEmailContentLoading());
|
||||
|
||||
if (PlatformInfo.isMobile) {
|
||||
yield* _getStoredOpenedEmail(session, accountId, emailId, baseDownloadUrl, composeEmail: composeEmail, draftsEmail: draftsEmail);
|
||||
yield* _getStoredOpenedEmail(session, accountId, emailId, baseDownloadUrl, transformConfiguration);
|
||||
} else {
|
||||
yield* _getContentEmailFromServer(session, accountId, emailId, baseDownloadUrl, composeEmail: composeEmail, draftsEmail: draftsEmail);
|
||||
yield* _getContentEmailFromServer(session, accountId, emailId, baseDownloadUrl, transformConfiguration);
|
||||
}
|
||||
} catch (e) {
|
||||
log('GetEmailContentInteractor::execute(): exception = $e');
|
||||
@@ -44,38 +42,31 @@ class GetEmailContentInteractor {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String? baseDownloadUrl,
|
||||
{
|
||||
bool composeEmail = false,
|
||||
bool draftsEmail = false
|
||||
}
|
||||
String baseDownloadUrl,
|
||||
TransformConfiguration transformConfiguration,
|
||||
) async* {
|
||||
try {
|
||||
final email = await emailRepository.getEmailContent(session, accountId, emailId);
|
||||
|
||||
if (email.emailContentList.isNotEmpty) {
|
||||
final mapCidImageDownloadUrl = email.attachmentsWithCid.toMapCidImageDownloadUrl(
|
||||
accountId: accountId,
|
||||
downloadUrl: baseDownloadUrl
|
||||
);
|
||||
final newEmailContents = await emailRepository.transformEmailContent(
|
||||
email.emailContentList,
|
||||
email.allAttachments.listAttachmentsDisplayedInContent,
|
||||
baseDownloadUrl,
|
||||
accountId,
|
||||
draftsEmail: draftsEmail
|
||||
mapCidImageDownloadUrl,
|
||||
transformConfiguration
|
||||
);
|
||||
|
||||
final newEmailContentsDisplayed = PlatformInfo.isWeb && !composeEmail
|
||||
? await emailRepository.addTooltipWhenHoverOnLink(newEmailContents)
|
||||
: newEmailContents;
|
||||
|
||||
yield Right<Failure, Success>(GetEmailContentSuccess(
|
||||
emailContent: newEmailContents.asHtmlString,
|
||||
emailContentDisplayed: newEmailContentsDisplayed.asHtmlString,
|
||||
htmlEmailContent: newEmailContents.asHtmlString,
|
||||
attachments: email.allAttachments,
|
||||
emailCurrent: email
|
||||
));
|
||||
} else {
|
||||
yield Right<Failure, Success>(GetEmailContentSuccess(
|
||||
emailContent: '',
|
||||
emailContentDisplayed: '',
|
||||
htmlEmailContent: '',
|
||||
attachments: email.allAttachments,
|
||||
emailCurrent: email
|
||||
));
|
||||
@@ -90,17 +81,14 @@ class GetEmailContentInteractor {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String? baseDownloadUrl,
|
||||
{
|
||||
bool composeEmail = false,
|
||||
bool draftsEmail = false
|
||||
}
|
||||
String baseDownloadUrl,
|
||||
TransformConfiguration transformConfiguration,
|
||||
) async* {
|
||||
try {
|
||||
log('GetEmailContentInteractor::_getStoredOpenedEmail(): CALLED');
|
||||
final detailedEmail = await emailRepository.getStoredOpenedEmail(session, accountId, emailId);
|
||||
yield Right<Failure, Success>(GetEmailContentFromCacheSuccess(
|
||||
emailContent: detailedEmail.htmlEmailContent ?? "",
|
||||
htmlEmailContent: detailedEmail.htmlEmailContent ?? '',
|
||||
attachments: detailedEmail.attachments ?? [],
|
||||
emailCurrent: Email(
|
||||
id: emailId,
|
||||
@@ -115,8 +103,8 @@ class GetEmailContentInteractor {
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadUrl,
|
||||
composeEmail: composeEmail,
|
||||
draftsEmail: draftsEmail);
|
||||
transformConfiguration
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,17 +112,14 @@ class GetEmailContentInteractor {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
EmailId emailId,
|
||||
String? baseDownloadUrl,
|
||||
{
|
||||
bool composeEmail = false,
|
||||
bool draftsEmail = false
|
||||
}
|
||||
String baseDownloadUrl,
|
||||
TransformConfiguration transformConfiguration,
|
||||
) async* {
|
||||
try {
|
||||
log('GetEmailContentInteractor::_getStoredNewEmail():CALLED');
|
||||
final detailedEmail = await emailRepository.getStoredNewEmail(session, accountId, emailId);
|
||||
yield Right<Failure, Success>(GetEmailContentFromCacheSuccess(
|
||||
emailContent: detailedEmail.htmlEmailContent ?? "",
|
||||
htmlEmailContent: detailedEmail.htmlEmailContent ?? '',
|
||||
attachments: detailedEmail.attachments ?? [],
|
||||
emailCurrent: Email(
|
||||
id: emailId,
|
||||
@@ -149,8 +134,8 @@ class GetEmailContentInteractor {
|
||||
accountId,
|
||||
emailId,
|
||||
baseDownloadUrl,
|
||||
composeEmail: composeEmail,
|
||||
draftsEmail: draftsEmail);
|
||||
transformConfiguration
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
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/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/extensions/utc_date_extension.dart';
|
||||
@@ -23,7 +25,7 @@ class GetListDetailedEmailByIdInteractor {
|
||||
Session session,
|
||||
AccountId accountId,
|
||||
Set<EmailId> emailIds,
|
||||
String? baseDownloadUrl,
|
||||
String baseDownloadUrl,
|
||||
{Set<Comparator>? sort}
|
||||
) async* {
|
||||
try {
|
||||
@@ -57,17 +59,27 @@ class GetListDetailedEmailByIdInteractor {
|
||||
Future<Tuple2<Email, DetailedEmail>> _parsingEmailToDetailedEmail(
|
||||
AccountId accountId,
|
||||
Email email,
|
||||
String? baseDownloadUrl
|
||||
String baseDownloadUrl
|
||||
) async {
|
||||
String? htmlEmailContent;
|
||||
|
||||
final listEmailContent = email.emailContentList;
|
||||
if (listEmailContent.isNotEmpty) {
|
||||
final mapCidImageDownloadUrl = email.attachmentsWithCid.toMapCidImageDownloadUrl(
|
||||
accountId: accountId,
|
||||
downloadUrl: baseDownloadUrl
|
||||
);
|
||||
TransformConfiguration transformConfiguration = TransformConfiguration.standardConfiguration;
|
||||
if (email.isDraft) {
|
||||
transformConfiguration = TransformConfiguration.forDraftsEmail();
|
||||
} else if (PlatformInfo.isWeb) {
|
||||
transformConfiguration = TransformConfiguration.forPreviewEmailPlatformWeb();
|
||||
}
|
||||
final newEmailContents = await _emailRepository.transformEmailContent(
|
||||
listEmailContent,
|
||||
email.allAttachments.listAttachmentsDisplayedInContent,
|
||||
baseDownloadUrl,
|
||||
accountId);
|
||||
email.emailContentList,
|
||||
mapCidImageDownloadUrl,
|
||||
transformConfiguration
|
||||
);
|
||||
|
||||
htmlEmailContent = newEmailContents.asHtmlString;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
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:tmail_ui_user/features/email/domain/repository/email_repository.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/transform_html_email_content_state.dart';
|
||||
|
||||
class TransformHtmlEmailContentInteractor {
|
||||
final EmailRepository emailRepository;
|
||||
|
||||
TransformHtmlEmailContentInteractor(this.emailRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(
|
||||
String htmlContent,
|
||||
TransformConfiguration configuration
|
||||
) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(TransformHtmlEmailContentLoading());
|
||||
final htmlContentTransformed = await emailRepository.transformHtmlEmailContent(htmlContent, configuration);
|
||||
yield Right<Failure, Success>(TransformHtmlEmailContentSuccess(htmlContentTransformed));
|
||||
} catch (e) {
|
||||
yield Left<Failure, Success>(TransformHtmlEmailContentFailure(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user