From f7d783314e8415b3038e483bec566c81783b0826 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 5 Sep 2024 10:52:48 +0200 Subject: [PATCH] Handle `maxMediaAttachments` being undefined during file cutoff --- src/components/compose.jsx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index 3d034599..92ef81d4 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -639,16 +639,19 @@ function Compose({ e.preventDefault(); e.stopPropagation(); // Auto-cut-off files to avoid exceeding maxMediaAttachments - const max = maxMediaAttachments - mediaAttachments.length; - const allowedFiles = files.slice(0, max); - if (allowedFiles.length <= 0) { - alert( - plural(maxMediaAttachments, { - one: 'You can only attach up to 1 file.', - other: 'You can only attach up to # files.', - }), - ); - return; + let allowedFiles = files; + if(maxMediaAttachments !== undefined) { + const max = maxMediaAttachments - mediaAttachments.length; + allowedFiles = allowedFiles.slice(0, max); + if(allowedFiles.length <= 0) { + alert( + plural(maxMediaAttachments, { + one: 'You can only attach up to 1 file.', + other: 'You can only attach up to # files.', + }), + ); + return; + } } const mediaFiles = allowedFiles.map((file) => ({ file,