From 7c0811dd921d37f8835d7539aa35e47d315e0a49 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 3 May 2018 17:02:37 +0100 Subject: [PATCH] size > upload_size as per spec feedback --- src/components/views/rooms/MessageComposer.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.js b/src/components/views/rooms/MessageComposer.js index 8194240319..7d4b4f690f 100644 --- a/src/components/views/rooms/MessageComposer.js +++ b/src/components/views/rooms/MessageComposer.js @@ -65,6 +65,13 @@ export default class MessageComposer extends React.Component { // XXX: fragile as all hell - fixme somehow, perhaps with a dedicated Room.encryption event or something. MatrixClientPeg.get().on("event", this.onEvent); this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate); + + MatrixClientPeg.get().getMediaLimits().then((limits) => { + this._uploadLimits = limits; + }).catch(() => { + // HS can't or won't provide limits, so don't give any. + this._uploadLimits = {}; + }) } componentWillUnmount() { @@ -99,17 +106,12 @@ export default class MessageComposer extends React.Component { onUploadFileSelected(files) { const tfiles = files.target.files; - MatrixClientPeg.get().getMediaLimits().then((limits) => { - this.uploadFiles(tfiles, limits); - }).catch(() => { - // HS can't or won't provide limits, so don't give any. - this.uploadFiles(tfiles, {}); - }); + this.uploadFiles(tfiles); } - isFileUploadAllowed(file, limits) { - if (limits.size != null && file.size > limits.size) { - return _t("File is too big. Maximum file size is %(fileSize)s", {fileSize: filesize(limits.size)}); + isFileUploadAllowed(file) { + if (this._uploadLimits.upload_size != null && file.size > this._uploadLimits.upload_size) { + return _t("File is too big. Maximum file size is %(fileSize)s", {fileSize: filesize(this._uploadLimits.upload_size)}); } return true; } @@ -123,7 +125,7 @@ export default class MessageComposer extends React.Component { const failedFiles = []; for (let i=0; i { files[i].name || _t('Attachment') }