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:
commit
5e82cf7a9c
3 changed files with 19 additions and 8 deletions
|
|
@ -58,6 +58,7 @@
|
||||||
"file_prefix": "File: ",
|
"file_prefix": "File: ",
|
||||||
"edited": "(edited)",
|
"edited": "(edited)",
|
||||||
"download_progress": "{percentage}% downloaded",
|
"download_progress": "{percentage}% downloaded",
|
||||||
|
"upload_file_too_large": "File is too large to upload!",
|
||||||
"upload_progress": "Uploaded {count}",
|
"upload_progress": "Uploaded {count}",
|
||||||
"upload_progress_with_total": "Uploaded {count} of {total}",
|
"upload_progress_with_total": "Uploaded {count} of {total}",
|
||||||
"user_changed_room_history": "{user} made room history {type}",
|
"user_changed_room_history": "{user} made room history {type}",
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Vue from "vue";
|
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 util from "../plugins/utils";
|
||||||
import MessageOperations from "./messages/MessageOperations.vue";
|
import MessageOperations from "./messages/MessageOperations.vue";
|
||||||
import AvatarOperations from "./messages/AvatarOperations.vue";
|
import AvatarOperations from "./messages/AvatarOperations.vue";
|
||||||
|
|
@ -936,7 +936,6 @@ export default {
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
const file = event.target.files[0];
|
const file = event.target.files[0];
|
||||||
this.currentSendShowSendButton = true;
|
|
||||||
if (file.type.startsWith("image/")) {
|
if (file.type.startsWith("image/")) {
|
||||||
this.currentImageInput = {
|
this.currentImageInput = {
|
||||||
image: e.target.result,
|
image: e.target.result,
|
||||||
|
|
@ -985,7 +984,15 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(this.currentImageInput);
|
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]);
|
reader.readAsDataURL(event.target.files[0]);
|
||||||
}
|
}
|
||||||
|
|
@ -1034,7 +1041,7 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (err instanceof AbortError || err === "Abort") {
|
if (err.name === "AbortError" || err === "Abort") {
|
||||||
this.currentSendError = null;
|
this.currentSendError = null;
|
||||||
} else {
|
} else {
|
||||||
this.currentSendError = err.LocaleString();
|
this.currentSendError = err.LocaleString();
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,12 @@ var _browserCanRecordAudioF = function () {
|
||||||
}
|
}
|
||||||
var _browserCanRecordAudio = _browserCanRecordAudioF();
|
var _browserCanRecordAudio = _browserCanRecordAudioF();
|
||||||
|
|
||||||
class AbortablePromise extends Promise {
|
class UploadPromise extends Promise {
|
||||||
constructor(executor) {
|
constructor(executor) {
|
||||||
const aborter = {
|
const aborter = {
|
||||||
aborted: false,
|
aborted: false,
|
||||||
abortablePromise: undefined,
|
abortablePromise: undefined,
|
||||||
|
matrixClient: undefined,
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalExecutor = function (resolve, reject) {
|
const normalExecutor = function (resolve, reject) {
|
||||||
|
|
@ -42,8 +43,9 @@ class AbortablePromise extends Promise {
|
||||||
super(normalExecutor);
|
super(normalExecutor);
|
||||||
this.abort = () => {
|
this.abort = () => {
|
||||||
aborter.aborted = true;
|
aborter.aborted = true;
|
||||||
if (aborter.abortablePromise) {
|
if (aborter.abortablePromise && aborter.matrixClient) {
|
||||||
aborter.abortablePromise.abort();
|
aborter.matrixClient.cancelUpload(aborter.abortablePromise);
|
||||||
|
aborter.matrixClient = undefined;
|
||||||
aborter.abortablePromise = undefined;
|
aborter.abortablePromise = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -320,7 +322,7 @@ class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendImage(matrixClient, roomId, file, onUploadProgress) {
|
sendImage(matrixClient, roomId, file, onUploadProgress) {
|
||||||
return new AbortablePromise((resolve, reject, aborter) => {
|
return new UploadPromise((resolve, reject, aborter) => {
|
||||||
const abortionController = aborter;
|
const abortionController = aborter;
|
||||||
var reader = new FileReader();
|
var reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
|
|
@ -366,6 +368,7 @@ class Util {
|
||||||
|
|
||||||
if (!matrixClient.isRoomEncrypted(roomId)) {
|
if (!matrixClient.isRoomEncrypted(roomId)) {
|
||||||
// Not encrypted.
|
// Not encrypted.
|
||||||
|
abortionController.matrixClient = matrixClient;
|
||||||
abortionController.abortablePromise = matrixClient.uploadContent(data, opts);
|
abortionController.abortablePromise = matrixClient.uploadContent(data, opts);
|
||||||
abortionController.abortablePromise
|
abortionController.abortablePromise
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue