Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(uploads): allow to send empty uploads as normal messages #11013

Merged
merged 1 commit into from Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/components/NewMessage/NewMessage.vue
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
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
Expand Up @@ -263,6 +263,7 @@ const actions = {
if (state.currentUploadId === uploadId) {
commit('setCurrentUploadId', undefined)
}
EventBus.$emit('upload-discard')

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