Skip to content

Commit

Permalink
Merge pull request #11013 from nextcloud/backport/10986/stable28
Browse files Browse the repository at this point in the history
[stable28] fix(uploads): allow to send empty uploads as normal messages
  • Loading branch information
ShGKme authored Nov 27, 2023
2 parents cb7a98a + 68db473 commit 328edc8
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 @@ -400,7 +400,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 @@ -411,7 +412,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 @@ -453,14 +455,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 @@ -482,9 +484,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 328edc8

Please sign in to comment.