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
@@ -94,7 +94,6 @@ class ComposerBindings extends BaseBindings {
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
Get.find<DioClient>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>(), Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
@@ -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);
@@ -97,7 +97,6 @@ class EmailBindings extends BaseBindings {
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
Get.find<DioClient>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>(), Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => EmailHiveCacheDataSourceImpl(
@@ -1,5 +1,4 @@
import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:core/data/network/dio_client.dart';
import 'package:core/utils/config/app_config_loader.dart';
import 'package:core/utils/file_utils.dart';
import 'package:get/get.dart';
@@ -207,7 +206,6 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
Get.find<DioClient>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => SearchDataSourceImpl(
Get.find<RecentSearchCacheClient>(),
@@ -1,5 +1,4 @@
import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:core/data/network/dio_client.dart';
import 'package:core/utils/file_utils.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
@@ -57,7 +56,6 @@ class SendEmailInteractorBindings extends InteractorsBindings {
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
Get.find<DioClient>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(
Get.find<StateCacheClient>(),
@@ -1,5 +1,4 @@
import 'package:core/data/model/source_type/data_source_type.dart';
import 'package:core/data/network/dio_client.dart';
import 'package:core/utils/file_utils.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/base/interactors_bindings.dart';
@@ -98,7 +97,6 @@ class FcmInteractorBindings extends InteractorsBindings {
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
Get.find<DioClient>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(
Get.find<StateCacheClient>(),
@@ -9,7 +9,6 @@ import 'package:core/utils/platform_info.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tmail_ui_user/features/email/data/local/html_analyzer.dart';
import 'package:tmail_ui_user/features/sending_queue/presentation/utils/sending_queue_isolate_manager.dart';
import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
import 'package:uuid/uuid.dart';
@@ -21,7 +20,6 @@ class CoreBindings extends Bindings {
await _bindingSharePreference();
_bindingAppImagePaths();
_bindingResponsiveManager();
_bindingTransformer();
_bindingToast();
_bindingDeviceManager();
_bindingReceivingSharingStream();
@@ -41,10 +39,6 @@ class CoreBindings extends Bindings {
await Get.putAsync(() async => await SharedPreferences.getInstance(), permanent: true);
}
void _bindingTransformer() {
Get.put(HtmlAnalyzer());
}
void _bindingToast() {
Get.put(AppToast());
}
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:connectivity_plus/connectivity_plus.dart';
@@ -8,6 +9,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter_appauth/flutter_appauth.dart';
import 'package:get/get.dart';
import 'package:jmap_dart_client/http/http_client.dart';
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/network/mdn_api.dart';
import 'package:tmail_ui_user/features/login/data/local/account_cache_manager.dart';
@@ -36,6 +38,7 @@ class NetworkBindings extends Bindings {
_bindingConnection();
_bindingDio();
_bindingApi();
_bindingTransformer();
_bindingException();
}
@@ -104,4 +107,9 @@ class NetworkBindings extends Bindings {
void _bindingException() {
Get.put(RemoteExceptionThrower());
}
void _bindingTransformer() {
Get.put(const HtmlEscape());
Get.put(HtmlAnalyzer(Get.find<DioClient>(), Get.find<HtmlEscape>()));
}
}