diff --git a/lib/features/composer/presentation/composer_controller.dart b/lib/features/composer/presentation/composer_controller.dart
index 2e16fac8e..062b2f605 100644
--- a/lib/features/composer/presentation/composer_controller.dart
+++ b/lib/features/composer/presentation/composer_controller.dart
@@ -1101,7 +1101,7 @@ class ComposerController extends BaseController {
}
void _pickFileSuccess(LocalFilePickerSuccess success) {
- if (uploadController.hasEnoughMaxAttachmentSize(listFiles: success.pickedFiles)) {
+ if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo(success.pickedFiles))) {
_uploadAttachmentsAction(success.pickedFiles);
} else {
if (currentContext != null) {
@@ -1347,7 +1347,7 @@ class ComposerController extends BaseController {
}
if (listFileAttachmentSharedMediaFile.isNotEmpty) {
final listFile = covertListSharedMediaFileToFileInfo(listSharedMediaFile);
- if (uploadController.hasEnoughMaxAttachmentSize(listFiles: listFile)) {
+ if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo(listFile))) {
_uploadAttachmentsAction(listFile);
} else {
if (currentContext != null) {
@@ -1784,7 +1784,7 @@ class ComposerController extends BaseController {
}
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 accountId = mailboxDashBoardController.accountId.value;
if (session != null && accountId != null) {
@@ -1950,10 +1950,15 @@ class ComposerController extends BaseController {
}
if (fileUpload.type?.startsWith(MediaTypeExtension.imageType) == true) {
- _addInlineImageFromDragAndDrop(
- base64Data: fileUpload.base64!,
- name: fileUpload.name,
- );
+ final fileInfo = await fileUpload.toFileInfo();
+ if (fileInfo != null) {
+ _uploadInlineAttachmentsAction(fileInfo);
+ } else if (context.mounted) {
+ _appToast.showToastErrorMessage(
+ context,
+ AppLocalizations.of(context).can_not_upload_this_file_as_attachments
+ );
+ }
} else {
final fileInfo = await fileUpload.toFileInfo();
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({
required BuildContext context,
required web_html_editor.UploadError uploadError,
@@ -1986,7 +1986,7 @@ class ComposerController extends BaseController {
}
void _addAttachmentFromDragAndDrop({required FileInfo fileInfo}) {
- if (uploadController.hasEnoughMaxAttachmentSize(listFiles: [fileInfo])) {
+ if (uploadController.hasEnoughMaxAttachmentSize(fileInfoTotalSize: uploadController.getTotalSizeFromListFileInfo([fileInfo]))) {
_uploadAttachmentsAction([fileInfo]);
} else {
if (currentContext != null) {
@@ -2095,7 +2095,20 @@ class ComposerController extends BaseController {
void addAttachmentFromDropZone(Attachment 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 {
diff --git a/lib/features/composer/presentation/controller/rich_text_web_controller.dart b/lib/features/composer/presentation/controller/rich_text_web_controller.dart
index 70eec65f7..39b296478 100644
--- a/lib/features/composer/presentation/controller/rich_text_web_controller.dart
+++ b/lib/features/composer/presentation/controller/rich_text_web_controller.dart
@@ -202,12 +202,6 @@ class RichTextWebController extends BaseRichTextController {
}
}
- void insertInlineImage({required String base64Data, String? name}) async {
- log('RichTextWebController::insertInlineImage():name: $name');
- final base64Uri = '
';
- editorController.insertHtml(base64Uri);
- }
-
void applyNewFontStyle(FontNameType? newFont) {
final fontSelected = newFont ?? FontNameType.sansSerif;
selectedFontName.value = fontSelected;
diff --git a/lib/features/upload/presentation/controller/upload_controller.dart b/lib/features/upload/presentation/controller/upload_controller.dart
index c1635f595..282cb6fbb 100644
--- a/lib/features/upload/presentation/controller/upload_controller.dart
+++ b/lib/features/upload/presentation/controller/upload_controller.dart
@@ -274,17 +274,12 @@ class UploadController extends BaseController {
}
}
- bool hasEnoughMaxAttachmentSize({List? listFiles}) {
+ bool hasEnoughMaxAttachmentSize({num? fileInfoTotalSize}) {
final currentTotalAttachmentsSize = attachmentsUploaded.totalSize();
final totalInlineAttachmentsSize = inlineAttachmentsUploaded.totalSize();
log('UploadController::_validateAttachmentsSize(): $currentTotalAttachmentsSize');
log('UploadController::_validateAttachmentsSize(): totalInlineAttachmentsSize: $totalInlineAttachmentsSize');
- num uploadedTotalSize = 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');
- }
+ num uploadedTotalSize = fileInfoTotalSize ?? 0;
final totalSizeReadyToUpload = currentTotalAttachmentsSize +
totalInlineAttachmentsSize +
@@ -299,6 +294,13 @@ class UploadController extends BaseController {
}
}
+ num getTotalSizeFromListFileInfo(List 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 {
return listUploadAttachments
.every((uploadFile) => uploadFile.uploadStatus.completed);