Merge branch 'file-upload-fixes' into 'dev'

Fix cancel of file uploads again (after upstream changes)

See merge request keanuapp/keanuapp-weblite!183
This commit is contained in:
N Pex 2023-05-11 08:15:48 +00:00
commit 5e82cf7a9c
3 changed files with 19 additions and 8 deletions

View file

@ -58,6 +58,7 @@
"file_prefix": "File: ",
"edited": "(edited)",
"download_progress": "{percentage}% downloaded",
"upload_file_too_large": "File is too large to upload!",
"upload_progress": "Uploaded {count}",
"upload_progress_with_total": "Uploaded {count} of {total}",
"user_changed_room_history": "{user} made room history {type}",

View file

@ -262,7 +262,7 @@
<script>
import Vue from "vue";
import { TimelineWindow, EventTimeline, AbortError } from "matrix-js-sdk";
import { TimelineWindow, EventTimeline } from "matrix-js-sdk";
import util from "../plugins/utils";
import MessageOperations from "./messages/MessageOperations.vue";
import AvatarOperations from "./messages/AvatarOperations.vue";
@ -936,7 +936,6 @@ export default {
var reader = new FileReader();
reader.onload = (e) => {
const file = event.target.files[0];
this.currentSendShowSendButton = true;
if (file.type.startsWith("image/")) {
this.currentImageInput = {
image: e.target.result,
@ -985,7 +984,15 @@ export default {
}
}
console.log(this.currentImageInput);
this.currentImageInputPath = file;
this.$matrix.matrixClient.getMediaConfig().then((config) => {
this.currentImageInputPath = file;
if (config["m.upload.size"] && file.size > config["m.upload.size"]) {
this.currentSendError = this.$t("message.upload_file_too_large");
this.currentSendShowSendButton = false;
} else {
this.currentSendShowSendButton = true;
}
});
};
reader.readAsDataURL(event.target.files[0]);
}
@ -1034,7 +1041,7 @@ export default {
}
})
.catch((err) => {
if (err instanceof AbortError || err === "Abort") {
if (err.name === "AbortError" || err === "Abort") {
this.currentSendError = null;
} else {
this.currentSendError = err.LocaleString();

View file

@ -28,11 +28,12 @@ var _browserCanRecordAudioF = function () {
}
var _browserCanRecordAudio = _browserCanRecordAudioF();
class AbortablePromise extends Promise {
class UploadPromise extends Promise {
constructor(executor) {
const aborter = {
aborted: false,
abortablePromise: undefined,
matrixClient: undefined,
}
const normalExecutor = function (resolve, reject) {
@ -42,8 +43,9 @@ class AbortablePromise extends Promise {
super(normalExecutor);
this.abort = () => {
aborter.aborted = true;
if (aborter.abortablePromise) {
aborter.abortablePromise.abort();
if (aborter.abortablePromise && aborter.matrixClient) {
aborter.matrixClient.cancelUpload(aborter.abortablePromise);
aborter.matrixClient = undefined;
aborter.abortablePromise = undefined;
}
};
@ -320,7 +322,7 @@ class Util {
}
sendImage(matrixClient, roomId, file, onUploadProgress) {
return new AbortablePromise((resolve, reject, aborter) => {
return new UploadPromise((resolve, reject, aborter) => {
const abortionController = aborter;
var reader = new FileReader();
reader.onload = (e) => {
@ -366,6 +368,7 @@ class Util {
if (!matrixClient.isRoomEncrypted(roomId)) {
// Not encrypted.
abortionController.matrixClient = matrixClient;
abortionController.abortablePromise = matrixClient.uploadContent(data, opts);
abortionController.abortablePromise
.then((response) => {