Skip to content

Commit

Permalink
fixup! fix: move more computed props to composable and rename this la…
Browse files Browse the repository at this point in the history
…tter.
  • Loading branch information
DorraJaouad committed Apr 29, 2024
1 parent 16ddc88 commit e1e98e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,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'
Expand All @@ -313,7 +313,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',
Expand Down Expand Up @@ -484,11 +483,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,
Expand All @@ -499,6 +500,8 @@ export default {
isMyMsg,
isFileShare,
isFileShareWithoutCaption,
isConversationReadOnly,
isDeleteable,
}
},

Expand Down Expand Up @@ -528,21 +531,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
Expand All @@ -565,10 +553,6 @@ export default {
return this.$store.getters.isActorGuest()
},

isConversationReadOnly() {
return this.conversation.readOnly === CONVERSATION.STATE.READ_ONLY
},

isDeletedMessage() {
return this.messageType === 'comment_deleted'
},
Expand Down
7 changes: 6 additions & 1 deletion src/composables/useConversationInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import { computed, ref } from 'vue'

import { ATTENDEE, CONVERSATION } from '../constants.js'
import { ATTENDEE, CONVERSATION, PARTICIPANT } from '../constants.js'

/**
* Reusable properties for Conversation... items
Expand Down Expand Up @@ -139,10 +139,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,
}
}
22 changes: 15 additions & 7 deletions src/composables/useMessageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,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
Expand All @@ -44,21 +46,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)) {
Expand All @@ -72,8 +69,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,
Expand Down

0 comments on commit e1e98e2

Please sign in to comment.