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;

View file

@ -9,6 +9,9 @@
<v-btn v-if="isEditable" icon @click.stop="edit" class="ma-0 pa-0">
<v-icon>edit</v-icon>
</v-btn>
<v-btn v-if="isDownloadable" icon @click.stop="download" class="ma-0 pa-0">
<v-icon>get_app</v-icon>
</v-btn>
</div>
</template>
@ -36,6 +39,10 @@ export default {
computed: {
isEditable() {
return !this.incoming && this.event.getContent().msgtype == "m.text";
},
isDownloadable() {
const msgtype = this.event.getContent().msgtype;
return ['m.video','m.audio','m.image','m.file'].includes(msgtype);
}
},
@ -51,6 +58,10 @@ export default {
edit() {
this.$emit("close");
this.$emit("edit", {event:this.event});
},
download() {
this.$emit("close");
this.$emit("download", {event:this.event});
}
}
};