add inline image to draft composer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:core/core.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
@@ -41,7 +42,6 @@ import 'package:tmail_ui_user/features/composer/presentation/extensions/email_ac
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/image_source.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/inline_image.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/model/screen_display_mode.dart';
|
||||
import 'package:tmail_ui_user/features/composer/presentation/widgets/insert_image_dialog_builder.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/state/get_email_content_state.dart';
|
||||
import 'package:tmail_ui_user/features/email/domain/usecases/get_email_content_interactor.dart';
|
||||
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
|
||||
@@ -139,7 +139,10 @@ class ComposerController extends BaseController {
|
||||
log('ComposerController::_getEmailBodyText():WEB: newContentHtml: $newContentHtml');
|
||||
return newContentHtml;
|
||||
} else {
|
||||
final contentHtml = (await htmlEditorApi?.getText() ?? '').replaceAll('"', '"');
|
||||
String contentHtml = await htmlEditorApi?.getText() ?? '';
|
||||
if(Platform.isAndroid) {
|
||||
contentHtml = contentHtml.replaceAll('"', '"');
|
||||
}
|
||||
log('ComposerController::_getEmailBodyText():MOBILE: $contentHtml');
|
||||
final newContentHtml = contentHtml.removeEditorStartTag();
|
||||
if (changedEmail) {
|
||||
@@ -536,9 +539,7 @@ class ComposerController extends BaseController {
|
||||
final generateBlobId = Id(_uuid.v1());
|
||||
|
||||
var emailBodyText = await _getEmailBodyText(context);
|
||||
final mapContents = await richTextWebController.refactorContentHasInlineImage(
|
||||
emailBodyText,
|
||||
uploadController.mapInlineAttachments);
|
||||
final mapContents = await _getMapContent(emailBodyText);
|
||||
log('ComposerController::_generateEmail(): mapContents: $mapContents');
|
||||
emailBodyText = mapContents.value1;
|
||||
final listInlineAttachment = mapContents.value2;
|
||||
@@ -578,6 +579,18 @@ class ComposerController extends BaseController {
|
||||
);
|
||||
}
|
||||
|
||||
Future<Tuple2<String, List<Attachment>>> _getMapContent(String emailBodyText) async {
|
||||
if (kIsWeb) {
|
||||
return await richTextWebController.refactorContentHasInlineImage(
|
||||
emailBodyText,
|
||||
uploadController.mapInlineAttachments);
|
||||
} else {
|
||||
return await richTextMobileTabletController.refactorContentHasInlineImage(
|
||||
emailBodyText,
|
||||
uploadController.mapInlineAttachments);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> get userAgentPlatform async {
|
||||
String userAgent;
|
||||
try {
|
||||
@@ -1121,21 +1134,12 @@ class ComposerController extends BaseController {
|
||||
}
|
||||
|
||||
void insertImage(BuildContext context, {double? maxWithEditor}) async {
|
||||
if(kIsWeb) {
|
||||
await InsertImageDialogBuilder(
|
||||
context,
|
||||
insertActionCallback: (inlineImage) {
|
||||
log('ComposerController::insertImage(): ${inlineImage.source}|$maxWithEditor');
|
||||
if (BuildUtils.isWeb) {
|
||||
this.maxWithEditor = maxWithEditor;
|
||||
_insertImageOnWeb(inlineImage);
|
||||
}
|
||||
}
|
||||
).show();
|
||||
} else {
|
||||
final inlineImage = await _selectFromFile();
|
||||
if(inlineImage != null) {
|
||||
this.maxWithEditor = maxWithEditor;
|
||||
final inlineImage = await _selectFromFile();
|
||||
if(inlineImage != null) {
|
||||
this.maxWithEditor = maxWithEditor;
|
||||
if(kIsWeb) {
|
||||
_insertImageOnWeb(inlineImage);
|
||||
} else {
|
||||
_insertImageOnMobileAndTablet(inlineImage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:core/core.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/image_source.dart';
|
||||
@@ -97,6 +101,33 @@ 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user