From 160ca1067c5ae571ae0f1cd65518c15f7433d3c6 Mon Sep 17 00:00:00 2001 From: 10G Meow <10gmeow@gmail.com> Date: Mon, 7 Aug 2023 08:48:34 +0300 Subject: [PATCH] fix sending actual file when not scaled --- src/components/Chat.vue | 51 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/components/Chat.vue b/src/components/Chat.vue index 57bf4f3..c7bf791 100644 --- a/src/components/Chat.vue +++ b/src/components/Chat.vue @@ -1113,6 +1113,7 @@ export default { fileObj.dimensions = null; fileObj.type = file.type; fileObj.actualSize = file.size; + fileObj.actualFile = file try { fileObj.dimensions = sizeOf(dataUriToBuffer(evt.target.result)); @@ -1218,33 +1219,41 @@ export default { this.$refs.attachment.value = null; if (this.isCurrentFileInputsAnArray) { let inputFiles = this.currentFileInputs.map(entry => { + // other than file type image + if(entry instanceof File) { + return entry; + } else { if (entry.scaled && entry.useScaled) { // Send scaled version of image instead! return entry.scaled; + } else { + // Send actual file image when not scaled! + return entry.actualFile; } - return entry; + } }) - const promises = inputFiles.map(inputFile => util.sendImage(this.$matrix.matrixClient, this.roomId, inputFile, this.onUploadProgress)); - Promise.all(promises).then(() => { - this.currentSendOperation = null; - this.currentFileInputs = null; - this.currentSendProgress = null; - if (withText) { - this.sendMessage(withText); - } - }) - .catch((err) => { - if (err.name === "AbortError" || err === "Abort") { - this.currentSendError = null; - this.currentSendErrorExceededFile = null; - } else { - this.currentSendError = err.LocaleString(); - this.currentSendErrorExceededFile = err.LocaleString(); - } - this.currentSendOperation = null; - this.currentSendProgress = null; - }); + const promises = inputFiles.map(inputFile => util.sendImage(this.$matrix.matrixClient, this.roomId, inputFile, this.onUploadProgress)); + + Promise.all(promises).then(() => { + this.currentSendOperation = null; + this.currentFileInputs = null; + this.currentSendProgress = null; + if (withText) { + this.sendMessage(withText); + } + }) + .catch((err) => { + if (err.name === "AbortError" || err === "Abort") { + this.currentSendError = null; + this.currentSendErrorExceededFile = null; + } else { + this.currentSendError = err.LocaleString(); + this.currentSendErrorExceededFile = err.LocaleString(); + } + this.currentSendOperation = null; + this.currentSendProgress = null; + }); } },