Download option for attachments

Issue #11
This commit is contained in:
N-Pex 2021-01-12 09:25:39 +01:00
parent cafe465d3a
commit 50ae081ea8
2 changed files with 27 additions and 0 deletions

View file

@ -16,6 +16,7 @@
v-on:addreaction="addReaction"
v-on:addreply="addReply(selectedEvent)"
v-on:edit="edit(selectedEvent)"
v-on:download="download(selectedEvent)"
:event="selectedEvent"
:incoming="selectedEvent.getSender() != $matrix.currentUserId"
/>
@ -730,6 +731,21 @@ export default {
this.$refs.messageInput.focus();
},
download(event) {
util
.getAttachment(this.$matrix.matrixClient, event)
.then((url) => {
const link = document.createElement("a");
link.href = url;
link.download = event.getContent().body || "Download";
link.click();
URL.revokeObjectURL(url);
})
.catch((err) => {
console.log("Failed to fetch attachment: ", err);
});
},
cancelEditReply() {
this.currentInput = "";
this.editedEvent = null;