TF-764 Fix inline images are not saved and shown successfully in Draft
This commit is contained in:
@@ -112,7 +112,7 @@ class DownloadClient {
|
||||
if (fileName.contains('.')) {
|
||||
fileName = fileName.split('.').first;
|
||||
}
|
||||
final base64Uri = '<img src="data:$mimeType;base64,$base64Data" alt="$fileName" id="$cid" style="max-width: 100%" />';
|
||||
final base64Uri = '<img src="data:$mimeType;base64,$base64Data" alt="$fileName" id="cid:$cid" style="max-width: 100%" />';
|
||||
return base64Uri;
|
||||
}
|
||||
}
|
||||
@@ -21,26 +21,22 @@ class ImageTransformer extends DomTransformer {
|
||||
}
|
||||
) async {
|
||||
final compressFileUtils = CompressFileUtils();
|
||||
final imageElements = document.getElementsByTagName('img');
|
||||
|
||||
final imageElements = document.querySelectorAll('img[src^="cid:"]');
|
||||
log('ImageTransformer::process(): imageElements: ${imageElements.length}');
|
||||
await Future.wait(imageElements.map((imageElement) async {
|
||||
imageElement.attributes['style'] = 'display: inline;max-width: 100%;height: auto;';
|
||||
final src = imageElement.attributes['src'];
|
||||
if (src != null
|
||||
&& src.isNotEmpty
|
||||
&& src.startsWith('cid:')
|
||||
&& mapUrlDownloadCID != null
|
||||
) {
|
||||
final cid = src.replaceFirst('cid:', '').trim();
|
||||
final cidUrlDownload = mapUrlDownloadCID[cid];
|
||||
if (cidUrlDownload != null && cidUrlDownload.isNotEmpty && dioClient != null) {
|
||||
final imgBase64Uri = await loadAsyncNetworkImageToBase64(
|
||||
dioClient,
|
||||
compressFileUtils,
|
||||
cidUrlDownload);
|
||||
if (imgBase64Uri.isNotEmpty) {
|
||||
imageElement.attributes['src'] = imgBase64Uri;
|
||||
}
|
||||
log('ImageTransformer::process(): src: $src');
|
||||
final cid = src?.replaceFirst('cid:', '').trim();
|
||||
final urlDownloadCid = mapUrlDownloadCID?[cid];
|
||||
log('ImageTransformer::process(): urlDownloadCid: $urlDownloadCid');
|
||||
if (urlDownloadCid?.isNotEmpty == true && dioClient != null) {
|
||||
final imgBase64Uri = await loadAsyncNetworkImageToBase64(
|
||||
dioClient,
|
||||
compressFileUtils,
|
||||
urlDownloadCid!);
|
||||
if (imgBase64Uri.isNotEmpty) {
|
||||
imageElement.attributes['src'] = imgBase64Uri;
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -890,6 +890,8 @@ class ComposerController extends BaseController {
|
||||
mailboxDashBoardController.consumeState(
|
||||
_saveEmailAsDraftsInteractor.execute(accountId, newEmail));
|
||||
}
|
||||
|
||||
uploadController.clearInlineFileUploaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/presentation/views/dialog/color_picker_dialog_builder.dart';
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
|
||||
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
|
||||
import 'package:html/parser.dart' show parse;
|
||||
|
||||
abstract class BaseRichTextController extends GetxController {
|
||||
|
||||
@@ -33,4 +38,32 @@ abstract class BaseRichTextController extends GetxController {
|
||||
}
|
||||
).show();
|
||||
}
|
||||
|
||||
Future<Tuple2<String, List<Attachment>>> refactorContentHasInlineImage(
|
||||
String emailContent,
|
||||
Map<String, Attachment> mapInlineAttachments
|
||||
) async {
|
||||
final document = parse(emailContent);
|
||||
final listImgTag = document.querySelectorAll('img[src^="data:image/"][id^="cid:"]');
|
||||
final listInlineAttachment = await Future.wait(listImgTag.map((imgTag) async {
|
||||
final idImg = imgTag.attributes['id'];
|
||||
final cid = idImg!.replaceFirst('cid:', '').trim();
|
||||
log('BaseRichTextController::refactorContentHasInlineImage(): $cid');
|
||||
imgTag.attributes['src'] = 'cid:$cid';
|
||||
imgTag.attributes.remove('id');
|
||||
return cid;
|
||||
})).then((listCid) {
|
||||
log('BaseRichTextController::refactorContentHasInlineImage(): $listCid');
|
||||
final listInlineAttachment = listCid
|
||||
.whereNotNull()
|
||||
.map((cid) => mapInlineAttachments[cid])
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
return listInlineAttachment;
|
||||
});
|
||||
final newContent = document.body?.innerHtml ?? emailContent;
|
||||
log('BaseRichTextController::refactorContentHasInlineImage(): $newContent');
|
||||
log('BaseRichTextController::refactorContentHasInlineImage(): listInlineAttachment: $listInlineAttachment');
|
||||
return Tuple2(newContent, listInlineAttachment);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/core.dart';
|
||||
import 'package:custom_pop_up_menu/custom_pop_up_menu.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:enough_html_editor/enough_html_editor.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:html/parser.dart';
|
||||
import 'package:model/model.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/controller/base_rich_text_controller.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/dropdown_menu_font_status.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/header_style_type.dart';
|
||||
@@ -128,34 +124,6 @@ class RichTextMobileTabletController extends BaseRichTextController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Tuple2<String, List<Attachment>>> refactorContentHasInlineImage(
|
||||
String emailContent,
|
||||
Map<String, Attachment> mapInlineAttachments,
|
||||
) async {
|
||||
final document = parse(emailContent);
|
||||
final listImgTag = document.querySelectorAll('img[src^="data:image/"]');
|
||||
final listInlineAttachment =
|
||||
await Future.wait(listImgTag.map((imgTag) async {
|
||||
final cid = imgTag.attributes['id'];
|
||||
log('RichTextMobileTabletController::refactorContentHasInlineImage(): cid: $cid');
|
||||
imgTag.attributes['src'] = 'cid:$cid';
|
||||
imgTag.attributes.remove('id');
|
||||
return cid;
|
||||
})).then((listCid) {
|
||||
log('RichTextMobileTabletController::refactorContentHasInlineImage(): $listCid');
|
||||
final listInlineAttachment = listCid
|
||||
.whereNotNull()
|
||||
.map((cid) => mapInlineAttachments[cid])
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
return listInlineAttachment;
|
||||
});
|
||||
final newContent = document.body?.innerHtml ?? emailContent;
|
||||
log('RichTextMobileTabletController::refactorContentHasInlineImage(): $newContent');
|
||||
log('RichTextMobileTabletController::refactorContentHasInlineImage(): listInlineAttachment: $listInlineAttachment');
|
||||
return Tuple2(newContent, listInlineAttachment);
|
||||
}
|
||||
|
||||
bool isTextStyleTypeSelected(RichTextStyleType richTextStyleType) {
|
||||
return listTextStyleApply.contains(richTextStyleType);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:custom_pop_up_menu/custom_pop_up_menu.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:html/parser.dart' show parse;
|
||||
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:html_editor_enhanced/html_editor.dart';
|
||||
import 'package:model/email/attachment.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/code_view_state.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/dropdown_menu_font_status.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/header_style_type.dart';
|
||||
@@ -164,33 +159,6 @@ class RichTextWebController extends BaseRichTextController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Tuple2<String, List<Attachment>>> refactorContentHasInlineImage(
|
||||
String emailContent,
|
||||
Map<String, Attachment> mapInlineAttachments
|
||||
) async {
|
||||
final document = parse(emailContent);
|
||||
final listImgTag = document.querySelectorAll('img[src^="data:image/"]');
|
||||
final listInlineAttachment = await Future.wait(listImgTag.map((imgTag) async {
|
||||
final cid = imgTag.attributes['id'];
|
||||
log('RichTextWebController::refactorContentHasInlineImage(): cid: $cid');
|
||||
imgTag.attributes['src'] = 'cid:$cid';
|
||||
imgTag.attributes.remove('id');
|
||||
return cid;
|
||||
})).then((listCid) {
|
||||
log('RichTextWebController::refactorContentHasInlineImage(): $listCid');
|
||||
final listInlineAttachment = listCid
|
||||
.whereNotNull()
|
||||
.map((cid) => mapInlineAttachments[cid])
|
||||
.whereNotNull()
|
||||
.toList();
|
||||
return listInlineAttachment;
|
||||
});
|
||||
final newContent = document.body?.innerHtml ?? emailContent;
|
||||
log('RichTextWebController::refactorContentHasInlineImage(): $newContent');
|
||||
log('RichTextWebController::refactorContentHasInlineImage(): listInlineAttachment: $listInlineAttachment');
|
||||
return Tuple2(newContent, listInlineAttachment);
|
||||
}
|
||||
|
||||
void applyNewFontStyle(FontNameType? newFont) {
|
||||
final fontSelected = newFont ?? FontNameType.sansSerif;
|
||||
selectedFontName.value = fontSelected;
|
||||
|
||||
Reference in New Issue
Block a user