Browse Source

Merge pull request #11889 from nextcloud/fix/11874/hide-upload-federation

fix(chat): disable drag&drop and Ctrl+V if files upload is not allowed
pull/11892/head
Joas Schilling 2 years ago
committed by GitHub
parent
commit
a87d9157c3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 30
      src/components/ChatView.vue
  2. 6
      src/components/NewMessage/NewMessage.vue

30
src/components/ChatView.vue

@ -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'
@ -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',
@ -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() {
@ -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
}
@ -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()
}
@ -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
}
},
@ -189,7 +205,7 @@ export default {
},
handleDropFiles(event) {
if (!this.isDraggingOver) {
if (!this.isDraggingOver || this.isDragAndDropBlocked) {
return
}

6
src/components/NewMessage/NewMessage.vue

@ -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'
@ -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

Loading…
Cancel
Save