From 74a827d2ef1835d0826b12924b88fbe3254d9d73 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Fri, 24 Nov 2023 12:40:53 +0100 Subject: [PATCH] allow to send normal message if no uploads attached Signed-off-by: Maksim Sukharev --- src/components/NewMessage/NewMessage.vue | 26 +++++++++++++------ .../NewMessage/NewMessageUploadEditor.vue | 3 ++- src/store/fileUploadStore.js | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/NewMessage/NewMessage.vue b/src/components/NewMessage/NewMessage.vue index ebd0006edf6..148db82bee8 100644 --- a/src/components/NewMessage/NewMessage.vue +++ b/src/components/NewMessage/NewMessage.vue @@ -256,7 +256,7 @@ export default { }, }, - emits: ['sent', 'failure'], + emits: ['sent', 'failure', 'upload'], expose: ['focusInput'], @@ -399,7 +399,8 @@ export default { mounted() { EventBus.$on('focus-chat-input', this.focusInput) - EventBus.$on('upload-start', this.handleUploadStart) + EventBus.$on('upload-start', this.handleUploadSideEffects) + EventBus.$on('upload-discard', this.handleUploadSideEffects) EventBus.$on('retry-message', this.handleRetryMessage) this.text = this.$store.getters.currentMessageInput(this.token) @@ -410,7 +411,8 @@ export default { beforeDestroy() { EventBus.$off('focus-chat-input', this.focusInput) - EventBus.$off('upload-start', this.handleUploadStart) + EventBus.$off('upload-start', this.handleUploadSideEffects) + EventBus.$off('upload-discard', this.handleUploadSideEffects) EventBus.$off('retry-message', this.handleRetryMessage) }, @@ -452,14 +454,14 @@ export default { } }, - handleUploadStart() { + handleUploadSideEffects() { if (this.upload) { return } this.$nextTick(() => { - // reset main input in chat view after upload file with caption + // reset or fill main input in chat view from the store this.text = this.$store.getters.currentMessageInput(this.token) - // refocus on upload start as the user might want to type again while the upload is running + // refocus input as the user might want to type further this.focusInput() }) }, @@ -481,9 +483,17 @@ export default { } if (this.upload) { - this.$emit('sent', this.text) + // Clear input content from store this.$store.dispatch('setCurrentMessageInput', { token: this.token, text: '' }) - return + + if (this.$store.getters.getInitialisedUploads(this.$store.getters.currentUploadId).length) { + // If dialog contains files to upload, delegate sending + this.$emit('upload', this.text) + return + } else { + // Dismiss dialog, process as normal message sending otherwise + this.$emit('sent') + } } if (this.hasText) { diff --git a/src/components/NewMessage/NewMessageUploadEditor.vue b/src/components/NewMessage/NewMessageUploadEditor.vue index b5c3acb7577..0f0951547b1 100644 --- a/src/components/NewMessage/NewMessageUploadEditor.vue +++ b/src/components/NewMessage/NewMessageUploadEditor.vue @@ -82,7 +82,8 @@ :token="token" :container="modalContainerId" :aria-label="t('spreed', 'Post message')" - @sent="handleUpload" + @upload="handleUpload" + @sent="handleDismiss" @failure="handleDismiss" /> diff --git a/src/store/fileUploadStore.js b/src/store/fileUploadStore.js index 8090310cd90..449f14e734c 100644 --- a/src/store/fileUploadStore.js +++ b/src/store/fileUploadStore.js @@ -263,6 +263,7 @@ const actions = { if (state.currentUploadId === uploadId) { commit('setCurrentUploadId', undefined) } + EventBus.$emit('upload-discard') commit('discardUpload', { uploadId }) },