TF-130 Checking maxSizeAttachmentsPerEmail when uploading attachments
This commit is contained in:
@@ -517,7 +517,38 @@ class ComposerController extends BaseController {
|
||||
|
||||
void _pickFileSuccess(Success success) {
|
||||
if (success is LocalFilePickerSuccess) {
|
||||
_uploadAttachmentsAction(success.pickedFiles);
|
||||
if (_validateAttachmentsSize(success.pickedFiles)) {
|
||||
_uploadAttachmentsAction(success.pickedFiles);
|
||||
} else {
|
||||
if (currentContext != null) {
|
||||
_appToast.showErrorToast(AppLocalizations.of(currentContext!).the_total_size_of_attachments_in_an_email_exceeds_the_limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _validateAttachmentsSize(List<FileInfo> listFiles) {
|
||||
num currentTotalSize = 0;
|
||||
if (attachments.isNotEmpty) {
|
||||
final currentListSize = attachments
|
||||
.map((attachment) => attachment.size?.value ?? 0)
|
||||
.toList();
|
||||
currentTotalSize = currentListSize.reduce((sum, size) => sum + size);
|
||||
log('ComposerController::checkingAttachmentsLimit(): currentTotalSize: $currentTotalSize');
|
||||
}
|
||||
|
||||
final uploadedListSize = listFiles.map((file) => file.fileSize).toList();
|
||||
final uploadedTotalSize = uploadedListSize.reduce((sum, size) => sum + size);
|
||||
log('ComposerController::checkingAttachmentsLimit(): uploadedTotalSize: $uploadedTotalSize');
|
||||
|
||||
final totalSizeReadyToUpload = currentTotalSize + uploadedTotalSize;
|
||||
log('ComposerController::checkingAttachmentsLimit(): totalSizeReadyToUpload: $totalSizeReadyToUpload');
|
||||
|
||||
final maxSizeAttachmentsPerEmail = mailboxDashBoardController.maxSizeAttachmentsPerEmail?.value;
|
||||
if (maxSizeAttachmentsPerEmail != null) {
|
||||
return totalSizeReadyToUpload <= maxSizeAttachmentsPerEmail;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/capability/mail_capability.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/session/session.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/email/email.dart';
|
||||
import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart';
|
||||
import 'package:model/model.dart';
|
||||
@@ -269,6 +272,20 @@ class MailboxDashBoardController extends ReloadableController {
|
||||
accountId.value = sessionCurrent?.accounts.keys.first;
|
||||
}
|
||||
|
||||
UnsignedInt? get maxSizeAttachmentsPerEmail {
|
||||
if (sessionCurrent != null && accountId.value != null) {
|
||||
final mailCapability = sessionCurrent
|
||||
?.accounts[accountId.value]
|
||||
?.accountCapabilities[CapabilityIdentifier.jmapMail];
|
||||
if (mailCapability is MailCapability) {
|
||||
final maxSizeAttachmentsPerEmail = mailCapability.maxSizeAttachmentsPerEmail;
|
||||
log('MailboxDashBoardController::maxSizeAttachmentsPerEmail(): $maxSizeAttachmentsPerEmail');
|
||||
return maxSizeAttachmentsPerEmail;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void composeEmailAction() {
|
||||
if (kIsWeb) {
|
||||
if (dashBoardAction != DashBoardAction.compose) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"@@last_modified": "2022-03-29T11:38:05.063764",
|
||||
"@@last_modified": "2022-03-29T13:00:02.017403",
|
||||
"initializing_data": "Initializing data...",
|
||||
"@initializing_data": {
|
||||
"type": "text",
|
||||
@@ -893,5 +893,11 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"the_total_size_of_attachments_in_an_email_exceeds_the_limit": "The total size of attachments in an email exceeds the limit.",
|
||||
"@the_total_size_of_attachments_in_an_email_exceeds_the_limit": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
@@ -949,4 +949,11 @@ class AppLocalizations {
|
||||
'Fix email addresses',
|
||||
name: 'fix_email_addresses');
|
||||
}
|
||||
|
||||
String get the_total_size_of_attachments_in_an_email_exceeds_the_limit {
|
||||
return Intl.message(
|
||||
'The total size of attachments in an email exceeds the limit.',
|
||||
name: 'the_total_size_of_attachments_in_an_email_exceeds_the_limit'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user