Skip to content

Commit

Permalink
Merge pull request #11889 from nextcloud/fix/11874/hide-upload-federa…
Browse files Browse the repository at this point in the history
…tion

fix(chat): disable drag&drop and Ctrl+V if files upload is not allowed
  • Loading branch information
nickvergessen authored Mar 21, 2024
2 parents c87c9f9 + 30aeeee commit a87d915
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
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

0 comments on commit a87d915

Please sign in to comment.