about summary refs log tree commit diff
path: root/app/javascript/mastodon/actions/compose.js
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-11-07 08:07:03 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-11-07 09:07:03 +0200
commit66684c489c3c0bde752d107b02fc3bd6cbcacf04 (patch)
tree9ea05359ce7c47899520a69f7dd11a5067d1a20a /app/javascript/mastodon/actions/compose.js
parent7cdb8c10e97fe9e22411efef4986e6393247e0ee (diff)
Fix WebUI allowing to upload more items than the limit (#12300)
Until this patch, drag'n'drop and copy-paste allowed to start uploading as
long as the number of *finished* uploads was below the limit.
Diffstat (limited to 'app/javascript/mastodon/actions/compose.js')
-rw-r--r--app/javascript/mastodon/actions/compose.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js
index 8e7906c73..727f02718 100644
--- a/app/javascript/mastodon/actions/compose.js
+++ b/app/javascript/mastodon/actions/compose.js
@@ -205,10 +205,11 @@ export function uploadCompose(files) {
   return function (dispatch, getState) {
     const uploadLimit = 4;
     const media  = getState().getIn(['compose', 'media_attachments']);
+    const pending  = getState().getIn(['compose', 'pending_media_attachments']);
     const progress = new Array(files.length).fill(0);
     let total = Array.from(files).reduce((a, v) => a + v.size, 0);
 
-    if (files.length + media.size > uploadLimit) {
+    if (files.length + media.size + pending > uploadLimit) {
       dispatch(showAlert(undefined, messages.uploadErrorLimit));
       return;
     }
@@ -235,7 +236,7 @@ export function uploadCompose(files) {
             dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
           },
         }).then(({ data }) => dispatch(uploadComposeSuccess(data, f)));
-      }).catch(error => dispatch(uploadComposeFail(error)));
+      }).catch(error => dispatch(uploadComposeFail(error, true)));
     };
   };
 };
@@ -266,10 +267,11 @@ export function changeUploadComposeSuccess(media) {
   };
 };
 
-export function changeUploadComposeFail(error) {
+export function changeUploadComposeFail(error, decrement = false) {
   return {
     type: COMPOSE_UPLOAD_CHANGE_FAIL,
     error: error,
+    decrement: decrement,
     skipLoading: true,
   };
 };