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
}) {
final domTransformers = (customDomTransformers != null && customDomTransformers.isNotEmpty)
? [...customDomTransformers]
: [...standardDomTransformers];
? customDomTransformers
: standardDomTransformers;
final textTransformers = (customTextTransformers != null && customTextTransformers.isNotEmpty)
? [...customTextTransformers]
: standardTextTransformers;
? customTextTransformers
: standardTextTransformers;
return TransformConfiguration(
domTransformers,
textTransformers
@@ -59,5 +61,13 @@ class TransformConfiguration {
ImageTransformer(),
];
static const List<DomTransformer> domTransformersForDraftEmail = [
RemoveScriptTransformer(),
BlockQuotedTransformer(),
BlockCodeTransformer(),
AddTargetBlankInTagATransformer(),
ImageTransformer(),
];
static const List<TextTransformer> standardTextTransformers = [];
}
@@ -1086,7 +1086,13 @@ class ComposerController extends BaseController {
final accountId = mailboxDashBoardController.sessionCurrent?.accounts.keys.first;
final emailId = arguments.presentationEmail?.id;
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();
screenDisplayMode.value = displayMode;
_autoFocusFieldWhenLauncher();
selectIdentity(identitySelected.value);
Future.delayed(
const Duration(milliseconds: 500),
() => selectIdentity(identitySelected.value)
);
}
void _updateTextForEditor() async {
@@ -1340,19 +1350,16 @@ class ComposerController extends BaseController {
_removeBccEmailAddressFromFormerIdentity(formerIdentity.bcc!);
}
if (!_isMobileApp && newIdentity != formerIdentity) {
if (!_isMobileApp) {
_removeSignature();
}
}
// Add new identity
if (newIdentity.bcc?.isNotEmpty == true) {
await _applyBccEmailAddressFromIdentity(newIdentity.bcc!);
}
if (!_isMobileApp
&& newIdentity != formerIdentity
&& newIdentity.signatureAsString.isNotEmpty == true) {
if (!_isMobileApp && newIdentity.signatureAsString.isNotEmpty == true) {
_applySignature(newIdentity.signatureAsString.asSignatureHtml());
}
@@ -4,7 +4,8 @@ import 'package:model/model.dart';
abstract class HtmlDataSource {
Future<EmailContent> transformEmailContent(
EmailContent emailContent,
Map<String, String> mapUrlDownloadCID
Map<String, String> mapUrlDownloadCID,
{bool draftsEmail = false}
);
Future<EmailContent> addTooltipWhenHoverOnLink(EmailContent emailContent);
@@ -14,11 +14,17 @@ class HtmlDataSourceImpl extends HtmlDataSource {
@override
Future<EmailContent> transformEmailContent(
EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID
EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID,
{bool draftsEmail = false}
) {
return Future.sync(() async {
return await _htmlAnalyzer.transformEmailContent(emailContent, mapUrlDownloadCID, _dioClient);
return await _htmlAnalyzer.transformEmailContent(
emailContent,
mapUrlDownloadCID,
_dioClient,
draftsEmail: draftsEmail
);
}).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: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 {
Future<EmailContent> transformEmailContent(
EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID,
DioClient dioClient
EmailContent emailContent,
Map<String, String>? mapUrlDownloadCID,
DioClient dioClient,
{bool draftsEmail = false}
) async {
switch(emailContent.type) {
case EmailContentType.textHtml:
final htmlTransform = HtmlTransform(
emailContent.content,
dioClient: dioClient,
mapUrlDownloadCID: mapUrlDownloadCID);
final htmlContent = await htmlTransform.transformToHtml();
emailContent.content,
dioClient: dioClient,
mapUrlDownloadCID: mapUrlDownloadCID
);
final htmlContent = await htmlTransform.transformToHtml(
transformConfiguration: draftsEmail
? TransformConfiguration.create(customDomTransformers: TransformConfiguration.domTransformersForDraftEmail)
: null
);
return EmailContent(emailContent.type, htmlContent);
case EmailContentType.textPlain:
final htmlTransform = HtmlTransform(emailContent.content);
@@ -90,7 +90,8 @@ class EmailRepositoryImpl extends EmailRepository {
List<EmailContent> emailContents,
List<Attachment> attachmentInlines,
String? baseUrlDownload,
AccountId accountId
AccountId accountId,
{bool draftsEmail = false}
) async {
final mapUrlDownloadCID = {
for (var attachment in attachmentInlines)
@@ -98,7 +99,11 @@ class EmailRepositoryImpl extends EmailRepository {
};
return await Future.wait(emailContents
.map((emailContent) async {
return await _htmlDataSource.transformEmailContent(emailContent, mapUrlDownloadCID);
return await _htmlDataSource.transformEmailContent(
emailContent,
mapUrlDownloadCID,
draftsEmail: draftsEmail
);
})
.toList());
}
@@ -55,7 +55,8 @@ abstract class EmailRepository {
List<EmailContent> emailContents,
List<Attachment> attachmentInlines,
String? baseUrlDownload,
AccountId accountId
AccountId accountId,
{bool draftsEmail = false}
);
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:flutter/foundation.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
import 'package:model/model.dart';
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/state/get_email_content_state.dart';
@@ -12,25 +15,38 @@ class GetEmailContentInteractor {
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 {
yield Right<Failure, Success>(GetEmailContentLoading());
final email = await emailRepository.getEmailContent(accountId, emailId);
if (email.emailContentList.isNotEmpty) {
final newEmailContents = await emailRepository.transformEmailContent(
email.emailContentList,
email.allAttachments.listAttachmentsDisplayedInContent,
baseDownloadUrl,
accountId);
final newEmailContentsDisplayed = kIsWeb
? await emailRepository.addTooltipWhenHoverOnLink(newEmailContents)
: newEmailContents;
email.emailContentList,
email.allAttachments.listAttachmentsDisplayedInContent,
baseDownloadUrl,
accountId,
draftsEmail: draftsEmail
);
final newEmailContentsDisplayed = BuildUtils.isWeb && !composeEmail
? await emailRepository.addTooltipWhenHoverOnLink(newEmailContents)
: newEmailContents;
yield Right<Failure, Success>(GetEmailContentSuccess(
newEmailContents,
newEmailContentsDisplayed,
email.allAttachments,
email));
newEmailContents,
newEmailContentsDisplayed,
email.allAttachments,
email
));
} else if (email.allAttachments.isNotEmpty) {
yield Right<Failure, Success>(GetEmailContentSuccess([], [], email.allAttachments, email));
} else if (email.headers?.isNotEmpty == true) {