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

fix(chat): disable drag&drop and Ctrl+V if files upload is not allowed #11889

Merged
merged 1 commit into from
Mar 21, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions src/components/ChatView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<script>
import ChevronDoubleDown from 'vue-material-design-icons/ChevronDoubleDown.vue'

import { getCapabilities } from '@nextcloud/capabilities'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'

import GuestWelcomeWindow from './GuestWelcomeWindow.vue'
Expand All @@ -84,10 +86,13 @@ import NewMessage from './NewMessage/NewMessage.vue'
import NewMessageUploadEditor from './NewMessage/NewMessageUploadEditor.vue'
import TransitionWrapper from './TransitionWrapper.vue'

import { CONVERSATION } from '../constants.js'
import { CONVERSATION, PARTICIPANT } from '../constants.js'
import { EventBus } from '../services/EventBus.js'
import { useChatExtrasStore } from '../stores/chatExtras.js'

const attachmentsAllowed = getCapabilities()?.spreed?.config?.attachments?.allowed
const supportFederationV1 = getCapabilities()?.spreed?.features?.includes('federation-v1')

export default {

name: 'ChatView',
Expand Down Expand Up @@ -133,8 +138,15 @@ export default {
return !userName && this.isGuest
},

isEditingMessage() {
return this.chatExtrasStore.getMessageIdToEdit(this.token) !== undefined
canUploadFiles() {
return attachmentsAllowed && this.$store.getters.getUserId()
&& this.$store.getters.getAttachmentFolderFreeSpace() !== 0
&& (this.conversation.permissions & PARTICIPANT.PERMISSIONS.CHAT)
&& (!supportFederationV1 || !this.conversation.remoteServer)
},

isDragAndDropBlocked() {
return this.chatExtrasStore.getMessageIdToEdit(this.token) !== undefined || !this.canUploadFiles
},

dropHintText() {
Expand All @@ -147,8 +159,8 @@ export default {
}
},
isReadOnly() {
if (this.$store.getters.conversation(this.token)) {
return this.$store.getters.conversation(this.token).readOnly === CONVERSATION.STATE.READ_ONLY
if (this.conversation) {
return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY
} else {
return undefined
}
Expand All @@ -158,6 +170,10 @@ export default {
return this.$store.getters.getToken()
},

conversation() {
return this.$store.getters.conversation(this.token)
},

container() {
return this.$store.getters.getMainContainerSelector()
}
Expand All @@ -177,7 +193,7 @@ export default {
methods: {

handleDragOver(event) {
if (event.dataTransfer.types.includes('Files') && !this.isEditingMessage) {
if (event.dataTransfer.types.includes('Files') && !this.isDragAndDropBlocked) {
this.isDraggingOver = true
}
},
Expand All @@ -189,7 +205,7 @@ export default {
},

handleDropFiles(event) {
if (!this.isDraggingOver) {
if (!this.isDraggingOver || this.isDragAndDropBlocked) {
return
}

Expand Down
6 changes: 5 additions & 1 deletion src/components/NewMessage/NewMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ import SendIcon from 'vue-material-design-icons/Send.vue'
import SendVariantOutlineIcon from 'vue-material-design-icons/SendVariantOutline.vue'

import { getCapabilities } from '@nextcloud/capabilities'
import { showError } from '@nextcloud/dialogs'
import { showError, showWarning } from '@nextcloud/dialogs'
import { FilePickerVue } from '@nextcloud/dialogs/filepicker.js'
import { generateUrl } from '@nextcloud/router'

Expand Down Expand Up @@ -843,6 +843,10 @@ export default {
* @param {boolean} isVoiceMessage indicates whether the file is a voice message
*/
async handleFiles(files, rename = false, isVoiceMessage = false) {
if (!this.canUploadFiles) {
showWarning(t('spreed', 'File upload is not available in this conversation'))
return
}
// Create a unique id for the upload operation
const uploadId = this.currentUploadId ?? new Date().getTime()
// Uploads and shares the files
Expand Down
Loading