TF-2047 Inject binding html analyzer

(cherry picked from commit 3840e511567172a290886998037b17e2b88db9a5)
This commit is contained in:
dab246
2023-07-31 16:52:09 +07:00
committed by Dat Vu
parent f47c3198b6
commit 903b720b2e
9 changed files with 20 additions and 27 deletions
@@ -1,5 +1,4 @@
import 'package:core/core.dart';
import 'package:model/model.dart';
import 'package:model/email/email_content.dart';
import 'package:tmail_ui_user/features/email/data/datasource/html_datasource.dart';
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
@@ -7,10 +6,9 @@ import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class HtmlDataSourceImpl extends HtmlDataSource {
final HtmlAnalyzer _htmlAnalyzer;
final DioClient _dioClient;
final ExceptionThrower _exceptionThrower;
HtmlDataSourceImpl(this._htmlAnalyzer, this._dioClient, this._exceptionThrower);
HtmlDataSourceImpl(this._htmlAnalyzer, this._exceptionThrower);
@override
Future<EmailContent> transformEmailContent(
@@ -22,7 +20,6 @@ class HtmlDataSourceImpl extends HtmlDataSource {
return await _htmlAnalyzer.transformEmailContent(
emailContent,
mapUrlDownloadCID,
_dioClient,
draftsEmail: draftsEmail
);
}).catchError(_exceptionThrower.throwException);
@@ -1,26 +1,31 @@
import 'dart:convert';
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/sanitize_html_transformers.dart';
import 'package:core/presentation/utils/html_transformer/text/sanitize_autolink_html_transformers.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 {
final DioClient _dioClient;
final HtmlEscape _htmlEscape;
HtmlAnalyzer(this._dioClient, this._htmlEscape);
Future<EmailContent> transformEmailContent(
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,
dioClient: _dioClient,
mapUrlDownloadCID: mapUrlDownloadCID
);
@@ -35,10 +40,7 @@ class HtmlAnalyzer {
final htmlTransform = HtmlTransform(emailContent.content);
final message = htmlTransform.transformToTextPlain(
transformConfiguration: TransformConfiguration.create(
customTextTransformers: [
const ConvertUrlStringToHtmlLinksTransformers(),
const SanitizeHtmlTransformers(),
]
customTextTransformers: [SanitizeAutolinkHtmlTransformers(_htmlEscape)]
)
);
return EmailContent(emailContent.type, message);