Skip to content

Commit

Permalink
TF-2047 Inject binding html analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 committed Aug 1, 2023
1 parent 188bf7c commit e7a1b5d
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 27 deletions.
1 change: 0 additions & 1 deletion lib/features/composer/presentation/composer_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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';

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(
Expand All @@ -22,7 +20,6 @@ class HtmlDataSourceImpl extends HtmlDataSource {
return await _htmlAnalyzer.transformEmailContent(
emailContent,
mapUrlDownloadCID,
_dioClient,
draftsEmail: draftsEmail
);
}).catchError(_exceptionThrower.throwException);
Expand Down
18 changes: 10 additions & 8 deletions lib/features/email/data/local/html_analyzer.dart
Original file line number Diff line number Diff line change
@@ -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
);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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>(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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>(),
Expand Down
6 changes: 0 additions & 6 deletions lib/main/bindings/core/core_bindings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,7 +20,6 @@ class CoreBindings extends Bindings {
await _bindingSharePreference();
_bindingAppImagePaths();
_bindingResponsiveManager();
_bindingTransformer();
_bindingToast();
_bindingDeviceManager();
_bindingReceivingSharingStream();
Expand All @@ -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());
}
Expand Down
8 changes: 8 additions & 0 deletions lib/main/bindings/network/network_bindings.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:connectivity_plus/connectivity_plus.dart';
Expand All @@ -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';
Expand Down Expand Up @@ -36,6 +38,7 @@ class NetworkBindings extends Bindings {
_bindingConnection();
_bindingDio();
_bindingApi();
_bindingTransformer();
_bindingException();
}

Expand Down Expand Up @@ -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>()));
}
}

0 comments on commit e7a1b5d

Please sign in to comment.