From 289b7a84076af78a08584c8f7d45ae98399624a2 Mon Sep 17 00:00:00 2001 From: Marco Ambrosini Date: Wed, 16 Jun 2021 18:38:59 +0100 Subject: [PATCH] Display voice message preview before uploading Signed-off-by: Marco Ambrosini --- .../Message/MessagePart/AudioPlayer.vue | 19 +++- .../AudioRecorder/AudioRecorder.vue | 6 +- .../NewMessageForm/NewMessageForm.vue | 2 +- src/components/UploadEditor.vue | 96 ++++++++++++------- src/store/fileUploadStore.js | 4 +- 5 files changed, 82 insertions(+), 45 deletions(-) diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/AudioPlayer.vue b/src/components/MessagesList/MessagesGroup/Message/MessagePart/AudioPlayer.vue index 61f4fc37d41..a5f38038cab 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/AudioPlayer.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/AudioPlayer.vue @@ -43,17 +43,25 @@ export default { type: String, required: true, }, + link: { type: String, - required: true, + default: '', }, /** - * File path relative to the user's home storage, - * or link share root, includes the file name. + * Link share root, includes the file name. */ path: { type: String, - required: true, + default: '', + }, + /** + * File path relative to the user's home storage, used for previewing + * the audio before upload + */ + localUrl: { + type: String, + default: '', }, }, @@ -66,6 +74,9 @@ export default { }, fileURL() { + if (this.localUrl) { + return this.localUrl + } const userId = this.$store.getters.getUserId() if (userId === null) { // guest mode, use public link download URL diff --git a/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue b/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue index 74b31da29fd..75db4111443 100644 --- a/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue +++ b/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue @@ -102,8 +102,6 @@ export default { chunks: [], // The final audio file blob blob: null, - // The blob url - URL: '', // Switched to true if the recording is aborted aborted: false, // recordTimer @@ -237,14 +235,14 @@ export default { generateFile() { this.audioStream.getTracks().forEach(track => track.stop()) if (!this.aborted) { - this.blob = new Blob(this.chunks, { 'type': 'audio/mpeg-3' }) + this.blob = new Blob(this.chunks, { type: 'audio/mpeg-3' }) // Generate file name const fileName = this.generateFileName() // Convert blob to file const audioFile = new File([this.blob], fileName) + audioFile.localURL = window.URL.createObjectURL(this.blob) this.$emit('audioFile', audioFile) this.$emit('recording', false) - this.URL = window.URL.createObjectURL(this.blob) } this.resetComponentData() }, diff --git a/src/components/NewMessageForm/NewMessageForm.vue b/src/components/NewMessageForm/NewMessageForm.vue index a21b2cebcaf..d1fd2064b72 100644 --- a/src/components/NewMessageForm/NewMessageForm.vue +++ b/src/components/NewMessageForm/NewMessageForm.vue @@ -170,7 +170,7 @@ export default { }, }, - data: function() { + data() { return { text: '', parsedText: '', diff --git a/src/components/UploadEditor.vue b/src/components/UploadEditor.vue index 77e3487c81e..acb58e7e0ad 100644 --- a/src/components/UploadEditor.vue +++ b/src/components/UploadEditor.vue @@ -24,38 +24,45 @@ class="upload-editor" container="#content-vue" @close="handleDismiss"> - - - - -
- -
-
+ +