TF-2245 Upload image with cid when drag n drop image
Signed-off-by: dab246 <tdvu@linagora.com> (cherry picked from commit 68f7eff3b22cf743f5846900e17e2a62a8cbc3e9)
This commit is contained in:
@@ -1101,7 +1101,7 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _pickFileSuccess(LocalFilePickerSuccess success) {
|
void _pickFileSuccess(LocalFilePickerSuccess success) {
|
||||||
if (uploadController.hasEnoughMaxAttachmentSize(listFiles: success.pickedFiles)) {
|
if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo(success.pickedFiles))) {
|
||||||
_uploadAttachmentsAction(success.pickedFiles);
|
_uploadAttachmentsAction(success.pickedFiles);
|
||||||
} else {
|
} else {
|
||||||
if (currentContext != null) {
|
if (currentContext != null) {
|
||||||
@@ -1347,7 +1347,7 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
if (listFileAttachmentSharedMediaFile.isNotEmpty) {
|
if (listFileAttachmentSharedMediaFile.isNotEmpty) {
|
||||||
final listFile = covertListSharedMediaFileToFileInfo(listSharedMediaFile);
|
final listFile = covertListSharedMediaFileToFileInfo(listSharedMediaFile);
|
||||||
if (uploadController.hasEnoughMaxAttachmentSize(listFiles: listFile)) {
|
if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo(listFile))) {
|
||||||
_uploadAttachmentsAction(listFile);
|
_uploadAttachmentsAction(listFile);
|
||||||
} else {
|
} else {
|
||||||
if (currentContext != null) {
|
if (currentContext != null) {
|
||||||
@@ -1784,7 +1784,7 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _uploadInlineAttachmentsAction(FileInfo pickedFile, {bool fromFileShared = false}) async {
|
void _uploadInlineAttachmentsAction(FileInfo pickedFile, {bool fromFileShared = false}) async {
|
||||||
if (uploadController.hasEnoughMaxAttachmentSize(listFiles: [pickedFile])) {
|
if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo([pickedFile]))) {
|
||||||
final session = mailboxDashBoardController.sessionCurrent;
|
final session = mailboxDashBoardController.sessionCurrent;
|
||||||
final accountId = mailboxDashBoardController.accountId.value;
|
final accountId = mailboxDashBoardController.accountId.value;
|
||||||
if (session != null && accountId != null) {
|
if (session != null && accountId != null) {
|
||||||
@@ -1950,10 +1950,15 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fileUpload.type?.startsWith(MediaTypeExtension.imageType) == true) {
|
if (fileUpload.type?.startsWith(MediaTypeExtension.imageType) == true) {
|
||||||
_addInlineImageFromDragAndDrop(
|
final fileInfo = await fileUpload.toFileInfo();
|
||||||
base64Data: fileUpload.base64!,
|
if (fileInfo != null) {
|
||||||
name: fileUpload.name,
|
_uploadInlineAttachmentsAction(fileInfo);
|
||||||
);
|
} else if (context.mounted) {
|
||||||
|
_appToast.showToastErrorMessage(
|
||||||
|
context,
|
||||||
|
AppLocalizations.of(context).can_not_upload_this_file_as_attachments
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
final fileInfo = await fileUpload.toFileInfo();
|
final fileInfo = await fileUpload.toFileInfo();
|
||||||
if (fileInfo != null) {
|
if (fileInfo != null) {
|
||||||
@@ -1967,11 +1972,6 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addInlineImageFromDragAndDrop({required String base64Data, String? name}) {
|
|
||||||
log('ComposerController::_addInlineImageFromDragAndDrop:name: $name');
|
|
||||||
richTextWebController.insertInlineImage(base64Data: base64Data, name: name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleImageUploadFailure({
|
void handleImageUploadFailure({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required web_html_editor.UploadError uploadError,
|
required web_html_editor.UploadError uploadError,
|
||||||
@@ -1986,7 +1986,7 @@ class ComposerController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _addAttachmentFromDragAndDrop({required FileInfo fileInfo}) {
|
void _addAttachmentFromDragAndDrop({required FileInfo fileInfo}) {
|
||||||
if (uploadController.hasEnoughMaxAttachmentSize(listFiles: [fileInfo])) {
|
if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo([fileInfo]))) {
|
||||||
_uploadAttachmentsAction([fileInfo]);
|
_uploadAttachmentsAction([fileInfo]);
|
||||||
} else {
|
} else {
|
||||||
if (currentContext != null) {
|
if (currentContext != null) {
|
||||||
@@ -2095,7 +2095,20 @@ class ComposerController extends BaseController {
|
|||||||
|
|
||||||
void addAttachmentFromDropZone(Attachment attachment) {
|
void addAttachmentFromDropZone(Attachment attachment) {
|
||||||
log('ComposerController::addAttachmentFromDropZone: $attachment');
|
log('ComposerController::addAttachmentFromDropZone: $attachment');
|
||||||
uploadController.initializeUploadAttachments([attachment]);
|
if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: attachment.size?.value)) {
|
||||||
|
uploadController.initializeUploadAttachments([attachment]);
|
||||||
|
} else {
|
||||||
|
if (currentContext != null) {
|
||||||
|
showConfirmDialogAction(
|
||||||
|
currentContext!,
|
||||||
|
AppLocalizations.of(currentContext!).message_dialog_upload_attachments_exceeds_maximum_size(
|
||||||
|
filesize(mailboxDashBoardController.maxSizeAttachmentsPerEmail?.value ?? 0, 0)),
|
||||||
|
AppLocalizations.of(currentContext!).got_it,
|
||||||
|
title: AppLocalizations.of(currentContext!).maximum_files_size,
|
||||||
|
hasCancelButton: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleGetAllIdentitiesFailure(GetAllIdentitiesFailure failure) async {
|
void _handleGetAllIdentitiesFailure(GetAllIdentitiesFailure failure) async {
|
||||||
|
|||||||
@@ -202,12 +202,6 @@ class RichTextWebController extends BaseRichTextController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertInlineImage({required String base64Data, String? name}) async {
|
|
||||||
log('RichTextWebController::insertInlineImage():name: $name');
|
|
||||||
final base64Uri = '<img src="$base64Data" data-filename="$name" alt="Inline Image TeamMail" style="max-width: 100%" />';
|
|
||||||
editorController.insertHtml(base64Uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
void applyNewFontStyle(FontNameType? newFont) {
|
void applyNewFontStyle(FontNameType? newFont) {
|
||||||
final fontSelected = newFont ?? FontNameType.sansSerif;
|
final fontSelected = newFont ?? FontNameType.sansSerif;
|
||||||
selectedFontName.value = fontSelected;
|
selectedFontName.value = fontSelected;
|
||||||
|
|||||||
@@ -274,17 +274,12 @@ class UploadController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasEnoughMaxAttachmentSize({List<FileInfo>? listFiles}) {
|
bool hasEnoughMaxAttachmentSize({num? fileInfoTotalSize}) {
|
||||||
final currentTotalAttachmentsSize = attachmentsUploaded.totalSize();
|
final currentTotalAttachmentsSize = attachmentsUploaded.totalSize();
|
||||||
final totalInlineAttachmentsSize = inlineAttachmentsUploaded.totalSize();
|
final totalInlineAttachmentsSize = inlineAttachmentsUploaded.totalSize();
|
||||||
log('UploadController::_validateAttachmentsSize(): $currentTotalAttachmentsSize');
|
log('UploadController::_validateAttachmentsSize(): $currentTotalAttachmentsSize');
|
||||||
log('UploadController::_validateAttachmentsSize(): totalInlineAttachmentsSize: $totalInlineAttachmentsSize');
|
log('UploadController::_validateAttachmentsSize(): totalInlineAttachmentsSize: $totalInlineAttachmentsSize');
|
||||||
num uploadedTotalSize = 0;
|
num uploadedTotalSize = fileInfoTotalSize ?? 0;
|
||||||
if (listFiles != null && listFiles.isNotEmpty) {
|
|
||||||
final uploadedListSize = listFiles.map((file) => file.fileSize).toList();
|
|
||||||
uploadedTotalSize = uploadedListSize.reduce((sum, size) => sum + size);
|
|
||||||
log('UploadController::_validateAttachmentsSize(): uploadedTotalSize: $uploadedTotalSize');
|
|
||||||
}
|
|
||||||
|
|
||||||
final totalSizeReadyToUpload = currentTotalAttachmentsSize +
|
final totalSizeReadyToUpload = currentTotalAttachmentsSize +
|
||||||
totalInlineAttachmentsSize +
|
totalInlineAttachmentsSize +
|
||||||
@@ -299,6 +294,13 @@ class UploadController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
num getTotalSizeFromListFileInfo(List<FileInfo> listFiles) {
|
||||||
|
final uploadedListSize = listFiles.map((file) => file.fileSize).toList();
|
||||||
|
num totalSize = uploadedListSize.reduce((sum, size) => sum + size);
|
||||||
|
log('UploadController::_getTotalSizeFromListFileInfo():totalSize: $totalSize');
|
||||||
|
return totalSize;
|
||||||
|
}
|
||||||
|
|
||||||
bool get allUploadAttachmentsCompleted {
|
bool get allUploadAttachmentsCompleted {
|
||||||
return listUploadAttachments
|
return listUploadAttachments
|
||||||
.every((uploadFile) => uploadFile.uploadStatus.completed);
|
.every((uploadFile) => uploadFile.uploadStatus.completed);
|
||||||
|
|||||||
Reference in New Issue
Block a user