Skip to content

Commit

Permalink
allow to send normal message if no uploads attached
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Nov 24, 2023
1 parent 0fa038f commit 74a827d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default {
},
},
emits: ['sent', 'failure'],
emits: ['sent', 'failure', 'upload'],
expose: ['focusInput'],
Expand Down Expand Up @@ -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)
Expand All @@ -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)
},
Expand Down Expand Up @@ -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()
})
},
Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/NewMessage/NewMessageUploadEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
:token="token"
:container="modalContainerId"
:aria-label="t('spreed', 'Post message')"
@sent="handleUpload"
@upload="handleUpload"
@sent="handleDismiss"
@failure="handleDismiss" />
</div>
</NcModal>
Expand Down
1 change: 1 addition & 0 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const actions = {
if (state.currentUploadId === uploadId) {
commit('setCurrentUploadId', undefined)
}
EventBus.$emit('upload-discard')

commit('discardUpload', { uploadId })
},
Expand Down

0 comments on commit 74a827d

Please sign in to comment.