From 7864cfba9acf30af39fe246730df17f44b3500b1 Mon Sep 17 00:00:00 2001 From: DorraJaouad Date: Tue, 30 Apr 2024 10:07:56 +0200 Subject: [PATCH] fixup! fix: move more computed props to composable and rename this latter. --- .../MessageButtonsBar/MessageButtonsBar.vue | 28 +++---------- src/composables/useConversationInfo.js | 7 +++- src/composables/useMessageInfo.js | 42 ++++++++----------- 3 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue index 6325963a740..e05dd1abe8d 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue +++ b/src/components/MessagesList/MessagesGroup/Message/MessageButtonsBar/MessageButtonsBar.vue @@ -287,7 +287,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js' import NcEmojiPicker from '@nextcloud/vue/dist/Components/NcEmojiPicker.js' import { useMessageInfo } from '../../../../../composables/useMessageInfo.js' -import { PARTICIPANT, CONVERSATION, ATTENDEE } from '../../../../../constants.js' +import { CONVERSATION, ATTENDEE } from '../../../../../constants.js' import { getMessageReminder, removeMessageReminder, setMessageReminder } from '../../../../../services/remindersService.js' import { useIntegrationsStore } from '../../../../../stores/integrations.js' import { useReactionsStore } from '../../../../../stores/reactions.js' @@ -297,7 +297,6 @@ import { parseMentions } from '../../../../../utils/textParse.ts' const EmojiIndex = new EmojiIndexFactory(data) const supportReminders = getCapabilities()?.spreed?.features?.includes('remind-me-later') const canEditMessage = getCapabilities()?.spreed?.features?.includes('edit-messages') -const canDeleteMessageUnlimited = getCapabilities()?.spreed?.features?.includes('delete-messages-unlimited') export default { name: 'MessageButtonsBar', @@ -468,11 +467,13 @@ export default { const { messageActions } = useIntegrationsStore() const { isEditable, + isDeleteable, isModifiable, isMyMsg, isFileShare, isFileShareWithoutCaption, - } = useMessageInfo(props.token, props.id) + isConversationReadOnly, + } = useMessageInfo(props.token, props.id) return { messageActions, @@ -483,6 +484,8 @@ export default { isMyMsg, isFileShare, isFileShareWithoutCaption, + isConversationReadOnly, + isDeleteable, } }, @@ -512,21 +515,6 @@ export default { return this.getMessagesListScroller() }, - isDeleteable() { - if (!this.isModifiable) { - return false - } - - return (canDeleteMessageUnlimited || (moment(this.timestamp * 1000).add(6, 'h')) > moment()) - && (this.messageType === 'comment' || this.messageType === 'voice-message') - && !this.isDeleting - && (this.isMyMsg - || (this.conversation.type !== CONVERSATION.TYPE.ONE_TO_ONE - && this.conversation.type !== CONVERSATION.TYPE.ONE_TO_ONE_FORMER - && (this.conversation.participantType === PARTICIPANT.TYPE.OWNER - || this.conversation.participantType === PARTICIPANT.TYPE.MODERATOR))) - }, - isPrivateReplyable() { return this.isReplyable && (this.conversation.type === CONVERSATION.TYPE.PUBLIC @@ -549,10 +537,6 @@ export default { return this.$store.getters.isActorGuest() }, - isConversationReadOnly() { - return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY - }, - isDeletedMessage() { return this.messageType === 'comment_deleted' }, diff --git a/src/composables/useConversationInfo.js b/src/composables/useConversationInfo.js index 64a9aaf3d8c..bdc1fa10ee8 100644 --- a/src/composables/useConversationInfo.js +++ b/src/composables/useConversationInfo.js @@ -5,7 +5,7 @@ import { computed, ref } from 'vue' -import { ATTENDEE, CONVERSATION } from '../constants.js' +import { ATTENDEE, CONVERSATION, PARTICIPANT } from '../constants.js' /** * Reusable properties for Conversation... items @@ -122,10 +122,15 @@ export function useConversationInfo({ return item.value.readOnly === CONVERSATION.STATE.READ_ONLY }) + const isModifiable = computed(() => + !isConversationReadOnly.value + && item.value.participantType !== PARTICIPANT.TYPE.GUEST) + return { counterType, conversationInformation, isOneToOne, isConversationReadOnly, + isModifiable, } } diff --git a/src/composables/useMessageInfo.js b/src/composables/useMessageInfo.js index 0d7c6a179d4..6028f4e03e4 100644 --- a/src/composables/useMessageInfo.js +++ b/src/composables/useMessageInfo.js @@ -1,20 +1,6 @@ -/* - * @copyright Copyright (c) 2024 Dorra Jaouad - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ import { computed } from 'vue' @@ -24,7 +10,9 @@ import moment from '@nextcloud/moment' import { useConversationInfo } from './useConversationInfo.js' import { useStore } from './useStore.js' -import { PARTICIPANT } from '../constants.js' + +const canDeleteMessageUnlimited = getCapabilities()?.spreed?.features?.includes('delete-messages-unlimited') +const canEditMessage = getCapabilities()?.spreed?.features?.includes('edit-messages') /** * Check whether the user can edit the message or not @@ -44,12 +32,9 @@ export function useMessageInfo(token = null, messageId = null) { const { isOneToOne, isConversationReadOnly, + isModifiable, } = useConversationInfo({ item: conversation }) - const isModifiable = computed(() => - !isConversationReadOnly.value - && conversation.value.participantType !== PARTICIPANT.TYPE.GUEST) - const isObjectShare = computed(() => Object.keys(Object(message.value.messageParameters)).some(key => key.startsWith('object'))) const isMyMsg = computed(() => @@ -57,8 +42,6 @@ export function useMessageInfo(token = null, messageId = null) { && message.value.actorType === store.getters.getActorType() ) - const canEditMessage = getCapabilities()?.spreed?.features?.includes('edit-messages') - const isEditable = computed(() => { if (!canEditMessage || !isModifiable.value || isObjectShare.value || ((!store.getters.isModerator || isOneToOne.value) && !isMyMsg.value)) { @@ -72,8 +55,19 @@ export function useMessageInfo(token = null, messageId = null) { const isFileShareWithoutCaption = computed(() => message.value.message === '{file}' && isFileShare.value) + const isDeleteable = computed(() => { + if (!isModifiable.value) { + return false + } + + return (canDeleteMessageUnlimited || (moment(message.value.timestamp * 1000).add(6, 'h')) > moment()) + && (message.value.messageType === 'comment' || message.value.messageType === 'voice-message') + && (isMyMsg.value || (!isOneToOne.value && store.getters.isModerator)) + }) + return { isEditable, + isDeleteable, isMyMsg, isObjectShare, isModifiable,