Skip to content

Commit

Permalink
fix: enhance isEditable and isDeleteable prop
Browse files Browse the repository at this point in the history
Signed-off-by: DorraJaouad <[email protected]>
  • Loading branch information
DorraJaouad committed May 4, 2024
1 parent 71d2dd9 commit d7b71e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/composables/__tests__/useMessageInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('message actions', () => {
mockConversationInfo = {
isOneToOneConversation: computed(() => false),
isConversationReadOnly: computed(() => true),
isConversationModifiable: computed(() => true),
isConversationModifiable: computed(() => false),
}
useConversationInfo.mockReturnValue(mockConversationInfo)
// Act
Expand Down Expand Up @@ -226,6 +226,15 @@ describe('message actions', () => {
expect(result.isEditable.value).toBe(false)
})

test('system message is not editable', () => {
// Arrange
messageProps.systemMessage = 'system-message'
// Act
const result = useMessageInfo(messageProps.token, messageProps.id)
// Assert
expect(result.isEditable.value).toBe(false)
})

test('message is not editable when the conversation is not modifiable', () => {
// Arrange
mockConversationInfo = {
Expand Down
17 changes: 6 additions & 11 deletions src/composables/useMessageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function useMessageInfo(tokenRef = ref(null), messageIdRef = ref(null)) {
)

const isEditable = computed(() => {
if (!canEditMessage || !isConversationModifiable.value || isObjectShare.value
if (!canEditMessage || !isConversationModifiable.value || isObjectShare.value || message.value.systemMessage
|| ((!store.getters.isModerator || isOneToOneConversation.value) && !isCurrentUserOwnMessage.value)) {
return false
}
Expand All @@ -70,16 +70,11 @@ export function useMessageInfo(tokenRef = ref(null), messageIdRef = ref(null)) {

const isFileShareWithoutCaption = computed(() => message.value.message === '{file}' && isFileShare.value)

const isDeleteable = computed(() => {
if (!isConversationModifiable.value) {
return false
}

return (canDeleteMessageUnlimited || (moment(message.value.timestamp * 1000).add(6, 'h')) > moment())
&& (message.value.messageType === 'comment' || message.value.messageType === 'voice-message')
&& (isCurrentUserOwnMessage.value || (!isOneToOneConversation.value && store.getters.isModerator))
&& !isConversationReadOnly.value
})
const isDeleteable = computed(() =>
(canDeleteMessageUnlimited || (moment(message.value.timestamp * 1000).add(6, 'h')) > moment())
&& (message.value.messageType === 'comment' || message.value.messageType === 'voice-message')
&& (isCurrentUserOwnMessage.value || (!isOneToOneConversation.value && store.getters.isModerator))
&& isConversationModifiable.value)

return {
isEditable,
Expand Down

0 comments on commit d7b71e9

Please sign in to comment.