Fix appear save draft dialog when reload editing composer
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -27,6 +27,7 @@ class ComposerDataSourceImpl extends ComposerDataSource {
|
||||
cid,
|
||||
fileInfo.fileExtension,
|
||||
fileInfo.fileName,
|
||||
fileInfo.mimeType,
|
||||
filePath: fileInfo.filePath,
|
||||
maxWidth: maxWidth,
|
||||
compress: compress);
|
||||
|
||||
@@ -113,4 +113,14 @@ class ComposerRepositoryImpl extends ComposerRepository {
|
||||
return Future.value(emailContent);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent}) {
|
||||
try {
|
||||
return _htmlDataSource.removeStyleLazyLoadDisplayInlineImages(emailContent: emailContent);
|
||||
} catch (e) {
|
||||
logError('ComposerRepositoryImpl::removeStyleLazyLoadDisplayInlineImages: Exception: $e');
|
||||
return Future.value(emailContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,6 @@ abstract class ComposerRepository {
|
||||
Future<String?> downloadImageAsBase64(String url, String cid, FileInfo fileInfo, {double? maxWidth, bool? compress});
|
||||
|
||||
Future<String> removeCollapsedExpandedSignatureEffect({required String emailContent});
|
||||
|
||||
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent});
|
||||
}
|
||||
@@ -1112,6 +1112,13 @@ class ComposerController extends BaseController
|
||||
emailContent = await _composerRepository.removeCollapsedExpandedSignatureEffect(
|
||||
emailContent: emailContent,
|
||||
);
|
||||
if (emailIdEditing != null &&
|
||||
savedActionType == EmailActionType.compose &&
|
||||
currentEmailActionType == EmailActionType.reopenComposerBrowser) {
|
||||
emailContent = await _composerRepository.removeStyleLazyLoadDisplayInlineImages(
|
||||
emailContent: emailContent,
|
||||
);
|
||||
}
|
||||
|
||||
final savedEmailDraft = SavedEmailDraft(
|
||||
subject: subjectEmail.value ?? '',
|
||||
|
||||
@@ -282,8 +282,9 @@ class RichTextWebController extends BaseRichTextController {
|
||||
void insertImageAsBase64({required PlatformFile platformFile, int? maxWidth}) {
|
||||
if (platformFile.bytes != null) {
|
||||
final base64Data = base64Encode(platformFile.bytes!);
|
||||
final mimeType = HtmlUtils.validateHtmlImageResourceMimeType('image/${platformFile.extension}');
|
||||
editorController.insertHtml(
|
||||
'<img src="${HtmlUtils.convertBase64ToImageResourceData(base64Data: base64Data, mimeType: 'image/${platformFile.extension}')}" data-filename="${platformFile.name}" alt="Image in my signature" style="max-width: ${maxWidth != null ? '${maxWidth}px' : '100%'};"/>'
|
||||
'<img src="${HtmlUtils.convertBase64ToImageResourceData(base64Data: base64Data, mimeType: mimeType)}" data-filename="${platformFile.name}" alt="Image in my signature" style="max-width: ${maxWidth != null ? '${maxWidth}px' : '100%'};" data-mimetype="$mimeType"/>'
|
||||
);
|
||||
} else {
|
||||
logError("RichTextWebController::insertImageAsBase64: bytes is null");
|
||||
|
||||
@@ -23,4 +23,6 @@ abstract class HtmlDataSource {
|
||||
});
|
||||
|
||||
Future<String> removeCollapsedExpandedSignatureEffect({required String emailContent});
|
||||
|
||||
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent});
|
||||
}
|
||||
@@ -62,4 +62,13 @@ class HtmlDataSourceImpl extends HtmlDataSource {
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent}) {
|
||||
return Future.sync(() async {
|
||||
return await _htmlAnalyzer.removeStyleLazyLoadDisplayInlineImages(
|
||||
emailContent: emailContent,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -237,4 +237,30 @@ class HtmlAnalyzer {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent}) async {
|
||||
try {
|
||||
final document = parse(emailContent);
|
||||
final imgElements = document.querySelectorAll('img[style], img[loading]');
|
||||
await Future.wait(imgElements.map((img) async {
|
||||
String? style = img.attributes['style'];
|
||||
if (style != null) {
|
||||
style = style.replaceAll(RegExp(r'display\s*:\s*inline;?'), '').trim();
|
||||
if (style.isEmpty) {
|
||||
img.attributes.remove('style');
|
||||
} else {
|
||||
img.attributes['style'] = style;
|
||||
}
|
||||
}
|
||||
|
||||
if (img.attributes['loading'] == 'lazy') {
|
||||
img.attributes.remove('loading');
|
||||
}
|
||||
}));
|
||||
return document.body?.innerHtml ?? emailContent;
|
||||
} catch (e) {
|
||||
logError('HtmlAnalyzer::removeStyleLazyLoadDisplayInlineImages:Exception = $e');
|
||||
return emailContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,7 +186,7 @@ class PublicAssetController extends BaseController {
|
||||
newlyPickedPublicAssetIds.add(publicAsset.id!);
|
||||
final imageTag = '<img '
|
||||
'src="${publicAsset.publicURI!}" '
|
||||
'style="max-width: 100%" '
|
||||
'style="max-width: 100%;" '
|
||||
'public-asset-id="${publicAsset.id!.value}">';
|
||||
if (PlatformInfo.isWeb) {
|
||||
Get
|
||||
|
||||
Reference in New Issue
Block a user