Handle maxMediaAttachments being undefined during file cutoff

This commit is contained in:
Stefano Pigozzi 2024-09-05 10:52:48 +02:00
parent c277cbca8f
commit f7d783314e
No known key found for this signature in database
GPG key ID: 5ADA3868646C3FC0

View file

@ -639,8 +639,10 @@ function Compose({
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
// Auto-cut-off files to avoid exceeding maxMediaAttachments // Auto-cut-off files to avoid exceeding maxMediaAttachments
let allowedFiles = files;
if(maxMediaAttachments !== undefined) {
const max = maxMediaAttachments - mediaAttachments.length; const max = maxMediaAttachments - mediaAttachments.length;
const allowedFiles = files.slice(0, max); allowedFiles = allowedFiles.slice(0, max);
if(allowedFiles.length <= 0) { if(allowedFiles.length <= 0) {
alert( alert(
plural(maxMediaAttachments, { plural(maxMediaAttachments, {
@ -650,6 +652,7 @@ function Compose({
); );
return; return;
} }
}
const mediaFiles = allowedFiles.map((file) => ({ const mediaFiles = allowedFiles.map((file) => ({
file, file,
type: file.type, type: file.type,