TF-764 Fix inline images are not saved and shown successfully in Draft
This commit is contained in:
@@ -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