TF-1371 Update position of Identity in edit email

(cherry picked from commit f0c6a5716cd55c963606550b09d4f5ec4b2140a5)
This commit is contained in:
dab246
2023-03-15 11:27:21 +07:00
committed by Dat Vu
parent a31f331e09
commit ee91963e53
8 changed files with 100 additions and 42 deletions
@@ -39,11 +39,13 @@ class TransformConfiguration {
List<TextTransformer>? customTextTransformers List<TextTransformer>? customTextTransformers
}) { }) {
final domTransformers = (customDomTransformers != null && customDomTransformers.isNotEmpty) final domTransformers = (customDomTransformers != null && customDomTransformers.isNotEmpty)
? [...customDomTransformers] ? customDomTransformers
: [...standardDomTransformers]; : standardDomTransformers;
final textTransformers = (customTextTransformers != null && customTextTransformers.isNotEmpty) final textTransformers = (customTextTransformers != null && customTextTransformers.isNotEmpty)
? [...customTextTransformers] ? customTextTransformers
: standardTextTransformers; : standardTextTransformers;
return TransformConfiguration( return TransformConfiguration(
domTransformers, domTransformers,
textTransformers textTransformers
@@ -59,5 +61,13 @@ class TransformConfiguration {
ImageTransformer(), ImageTransformer(),
]; ];
static const List<DomTransformer> domTransformersForDraftEmail = [
RemoveScriptTransformer(),
BlockQuotedTransformer(),
BlockCodeTransformer(),
AddTargetBlankInTagATransformer(),
ImageTransformer(),
];
static const List<TextTransformer> standardTextTransformers = []; static const List<TextTransformer> standardTextTransformers = [];
} }
@@ -1086,7 +1086,13 @@ class ComposerController extends BaseController {
final accountId = mailboxDashBoardController.sessionCurrent?.accounts.keys.first; final accountId = mailboxDashBoardController.sessionCurrent?.accounts.keys.first;
final emailId = arguments.presentationEmail?.id; final emailId = arguments.presentationEmail?.id;
if (emailId != null && baseDownloadUrl != null && accountId != null) { if (emailId != null && baseDownloadUrl != null && accountId != null) {
consumeState(_getEmailContentInteractor.execute(accountId, emailId, baseDownloadUrl)); consumeState(_getEmailContentInteractor.execute(
accountId,
emailId,
baseDownloadUrl,
composeEmail: true,
draftsEmail: arguments.presentationEmail?.isDraft ?? false
));
} }
} }
} }
@@ -1133,7 +1139,11 @@ class ComposerController extends BaseController {
_updateTextForEditor(); _updateTextForEditor();
screenDisplayMode.value = displayMode; screenDisplayMode.value = displayMode;
_autoFocusFieldWhenLauncher(); _autoFocusFieldWhenLauncher();
selectIdentity(identitySelected.value);
Future.delayed(
const Duration(milliseconds: 500),
() => selectIdentity(identitySelected.value)
);
} }
void _updateTextForEditor() async { void _updateTextForEditor() async {
@@ -1340,19 +1350,16 @@ class ComposerController extends BaseController {
_removeBccEmailAddressFromFormerIdentity(formerIdentity.bcc!); _removeBccEmailAddressFromFormerIdentity(formerIdentity.bcc!);
} }
if (!_isMobileApp && newIdentity != formerIdentity) { if (!_isMobileApp) {
_removeSignature(); _removeSignature();
} }
} }
// Add new identity // Add new identity
if (newIdentity.bcc?.isNotEmpty == true) { if (newIdentity.bcc?.isNotEmpty == true) {
await _applyBccEmailAddressFromIdentity(newIdentity.bcc!); await _applyBccEmailAddressFromIdentity(newIdentity.bcc!);
} }
if (!_isMobileApp if (!_isMobileApp && newIdentity.signatureAsString.isNotEmpty == true) {
&& newIdentity != formerIdentity
&& newIdentity.signatureAsString.isNotEmpty == true) {
_applySignature(newIdentity.signatureAsString.asSignatureHtml()); _applySignature(newIdentity.signatureAsString.asSignatureHtml());
} }
@@ -4,7 +4,8 @@ import 'package:model/model.dart';
abstract class HtmlDataSource { abstract class HtmlDataSource {
Future<EmailContent> transformEmailContent( Future<EmailContent> transformEmailContent(
EmailContent emailContent, EmailContent emailContent,
Map<String, String> mapUrlDownloadCID Map<String, String> mapUrlDownloadCID,
{bool draftsEmail = false}
); );
Future<EmailContent> addTooltipWhenHoverOnLink(EmailContent emailContent); Future<EmailContent> addTooltipWhenHoverOnLink(EmailContent emailContent);
@@ -14,11 +14,17 @@ class HtmlDataSourceImpl extends HtmlDataSource {
@override @override
Future<EmailContent> transformEmailContent( Future<EmailContent> transformEmailContent(
EmailContent emailContent, EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID Map<String, String>? mapUrlDownloadCID,
{bool draftsEmail = false}
) { ) {
return Future.sync(() async { return Future.sync(() async {
return await _htmlAnalyzer.transformEmailContent(emailContent, mapUrlDownloadCID, _dioClient); return await _htmlAnalyzer.transformEmailContent(
emailContent,
mapUrlDownloadCID,
_dioClient,
draftsEmail: draftsEmail
);
}).catchError(_exceptionThrower.throwException); }).catchError(_exceptionThrower.throwException);
} }
@@ -1,22 +1,34 @@
import 'package:core/core.dart'; import 'package:core/data/network/dio_client.dart';
import 'package:core/presentation/utils/html_transformer/dom/add_tooltip_link_transformers.dart';
import 'package:core/presentation/utils/html_transformer/html_transform.dart';
import 'package:core/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart'; import 'package:core/presentation/utils/html_transformer/text/convert_url_string_to_html_links_transformers.dart';
import 'package:model/model.dart'; import 'package:core/presentation/utils/html_transformer/transform_configuration.dart';
import 'package:model/email/email_content.dart';
import 'package:model/email/email_content_type.dart';
class HtmlAnalyzer { class HtmlAnalyzer {
Future<EmailContent> transformEmailContent( Future<EmailContent> transformEmailContent(
EmailContent emailContent, EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID, Map<String, String>? mapUrlDownloadCID,
DioClient dioClient DioClient dioClient,
{bool draftsEmail = false}
) async { ) async {
switch(emailContent.type) { switch(emailContent.type) {
case EmailContentType.textHtml: case EmailContentType.textHtml:
final htmlTransform = HtmlTransform( final htmlTransform = HtmlTransform(
emailContent.content, emailContent.content,
dioClient: dioClient, dioClient: dioClient,
mapUrlDownloadCID: mapUrlDownloadCID); mapUrlDownloadCID: mapUrlDownloadCID
final htmlContent = await htmlTransform.transformToHtml(); );
final htmlContent = await htmlTransform.transformToHtml(
transformConfiguration: draftsEmail
? TransformConfiguration.create(customDomTransformers: TransformConfiguration.domTransformersForDraftEmail)
: null
);
return EmailContent(emailContent.type, htmlContent); return EmailContent(emailContent.type, htmlContent);
case EmailContentType.textPlain: case EmailContentType.textPlain:
final htmlTransform = HtmlTransform(emailContent.content); final htmlTransform = HtmlTransform(emailContent.content);
@@ -90,7 +90,8 @@ class EmailRepositoryImpl extends EmailRepository {
List<EmailContent> emailContents, List<EmailContent> emailContents,
List<Attachment> attachmentInlines, List<Attachment> attachmentInlines,
String? baseUrlDownload, String? baseUrlDownload,
AccountId accountId AccountId accountId,
{bool draftsEmail = false}
) async { ) async {
final mapUrlDownloadCID = { final mapUrlDownloadCID = {
for (var attachment in attachmentInlines) for (var attachment in attachmentInlines)
@@ -98,7 +99,11 @@ class EmailRepositoryImpl extends EmailRepository {
}; };
return await Future.wait(emailContents return await Future.wait(emailContents
.map((emailContent) async { .map((emailContent) async {
return await _htmlDataSource.transformEmailContent(emailContent, mapUrlDownloadCID); return await _htmlDataSource.transformEmailContent(
emailContent,
mapUrlDownloadCID,
draftsEmail: draftsEmail
);
}) })
.toList()); .toList());
} }
@@ -55,7 +55,8 @@ abstract class EmailRepository {
List<EmailContent> emailContents, List<EmailContent> emailContents,
List<Attachment> attachmentInlines, List<Attachment> attachmentInlines,
String? baseUrlDownload, String? baseUrlDownload,
AccountId accountId AccountId accountId,
{bool draftsEmail = false}
); );
Future<List<EmailContent>> addTooltipWhenHoverOnLink(List<EmailContent> emailContents); Future<List<EmailContent>> addTooltipWhenHoverOnLink(List<EmailContent> emailContents);
@@ -1,9 +1,12 @@
import 'package:core/core.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/build_utils.dart';
import 'package:dartz/dartz.dart'; import 'package:dartz/dartz.dart';
import 'package:flutter/foundation.dart';
import 'package:jmap_dart_client/jmap/account_id.dart'; import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart'; import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/model.dart'; import 'package:model/extensions/email_extension.dart';
import 'package:model/extensions/list_attachment_extension.dart';
import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart'; import 'package:tmail_ui_user/features/email/domain/repository/email_repository.dart';
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
@@ -12,25 +15,38 @@ class GetEmailContentInteractor {
GetEmailContentInteractor(this.emailRepository); GetEmailContentInteractor(this.emailRepository);
Stream<Either<Failure, Success>> execute(AccountId accountId, EmailId emailId, String? baseDownloadUrl) async* { Stream<Either<Failure, Success>> execute(
AccountId accountId,
EmailId emailId,
String? baseDownloadUrl,
{
bool composeEmail = false,
bool draftsEmail = false
}
) async* {
try { try {
yield Right<Failure, Success>(GetEmailContentLoading()); yield Right<Failure, Success>(GetEmailContentLoading());
final email = await emailRepository.getEmailContent(accountId, emailId); final email = await emailRepository.getEmailContent(accountId, emailId);
if (email.emailContentList.isNotEmpty) { if (email.emailContentList.isNotEmpty) {
final newEmailContents = await emailRepository.transformEmailContent( final newEmailContents = await emailRepository.transformEmailContent(
email.emailContentList, email.emailContentList,
email.allAttachments.listAttachmentsDisplayedInContent, email.allAttachments.listAttachmentsDisplayedInContent,
baseDownloadUrl, baseDownloadUrl,
accountId); accountId,
final newEmailContentsDisplayed = kIsWeb draftsEmail: draftsEmail
? await emailRepository.addTooltipWhenHoverOnLink(newEmailContents) );
: newEmailContents;
final newEmailContentsDisplayed = BuildUtils.isWeb && !composeEmail
? await emailRepository.addTooltipWhenHoverOnLink(newEmailContents)
: newEmailContents;
yield Right<Failure, Success>(GetEmailContentSuccess( yield Right<Failure, Success>(GetEmailContentSuccess(
newEmailContents, newEmailContents,
newEmailContentsDisplayed, newEmailContentsDisplayed,
email.allAttachments, email.allAttachments,
email)); email
));
} else if (email.allAttachments.isNotEmpty) { } else if (email.allAttachments.isNotEmpty) {
yield Right<Failure, Success>(GetEmailContentSuccess([], [], email.allAttachments, email)); yield Right<Failure, Success>(GetEmailContentSuccess([], [], email.allAttachments, email));
} else if (email.headers?.isNotEmpty == true) { } else if (email.headers?.isNotEmpty == true) {