From 9a1aa73cc874b492fac55a763414e3792514ff10 Mon Sep 17 00:00:00 2001 From: adb Date: Thu, 13 May 2021 01:51:13 +0200 Subject: [PATCH] paste images/files as attachment --- src/components/eventContent.vue | 7 +++++++ src/components/fileUpload.vue | 15 +++------------ src/components/newMessage.vue | 10 +++++++++- src/lib/readFileBlob.js | 8 ++++++++ 4 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/lib/readFileBlob.js diff --git a/src/components/eventContent.vue b/src/components/eventContent.vue index 80a6980..4633f6d 100644 --- a/src/components/eventContent.vue +++ b/src/components/eventContent.vue @@ -52,6 +52,10 @@ export default { compact: { type: Boolean, default: false + }, + onUpdate: { + type: Function, + default: ()=>{} } }, methods: { @@ -59,6 +63,9 @@ export default { return url.includes('mxc')?getMediaUrl(url):url; }, parseMessage + }, + updated() { + this.onUpdate(); } } diff --git a/src/components/fileUpload.vue b/src/components/fileUpload.vue index 5c779c8..5c32d3f 100644 --- a/src/components/fileUpload.vue +++ b/src/components/fileUpload.vue @@ -15,6 +15,7 @@ diff --git a/src/components/newMessage.vue b/src/components/newMessage.vue index 7adbd8d..3fb0668 100644 --- a/src/components/newMessage.vue +++ b/src/components/newMessage.vue @@ -2,7 +2,7 @@
- + this.setAttachment({blob, file})); + }, parseMessage, calcUserName }, diff --git a/src/lib/readFileBlob.js b/src/lib/readFileBlob.js new file mode 100644 index 0000000..e5b1bc5 --- /dev/null +++ b/src/lib/readFileBlob.js @@ -0,0 +1,8 @@ +export function readFileBlob(file){ + return new Promise(resolve => { + let reader = new FileReader(); + reader.onerror = console.error; + reader.onload = async event => resolve(await (await fetch(event.target.result)).blob()); + reader.readAsDataURL(file); + }); +} \ No newline at end of file