-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! fix: move more computed props to composable and rename this la…
…tter.
- Loading branch information
1 parent
d1e2ef0
commit 7864cfb
Showing
3 changed files
with
30 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
/* | ||
* @copyright Copyright (c) 2024 Dorra Jaouad <[email protected]> | ||
* | ||
* @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 <http://www.gnu.org/licenses/>. | ||
/** | ||
* 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,21 +32,16 @@ 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(() => | ||
message.value.actorId === store.getters.getActorId() | ||
&& 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, | ||
|