diff --git a/src/__mocks__/capabilities.ts b/src/__mocks__/capabilities.ts index 7a557e314f0..4e188fbfaeb 100644 --- a/src/__mocks__/capabilities.ts +++ b/src/__mocks__/capabilities.ts @@ -83,6 +83,7 @@ export const mockedCapabilities: Capabilities = { 'ban-v1', 'chat-reference-id', 'mention-permissions', + 'edit-messages-note-to-self', ], 'features-local': [ 'favorites', diff --git a/src/composables/__tests__/useMessageInfo.spec.js b/src/composables/__tests__/useMessageInfo.spec.js index c68f573ac03..f0cbb45d7a8 100644 --- a/src/composables/__tests__/useMessageInfo.spec.js +++ b/src/composables/__tests__/useMessageInfo.spec.js @@ -15,7 +15,7 @@ import { useStore } from '../useStore.js' jest.mock('@nextcloud/capabilities', () => ({ getCapabilities: jest.fn(() => ({ spreed: { - features: ['edit-messages'], + features: ['edit-messages', 'edit-messages-note-to-self'], 'features-local': [], }, })) @@ -170,6 +170,17 @@ describe('message actions', () => { expect(result.isEditable.value).toBe(true) }) + test('can edit own message in note to self', () => { + // Arrange + message.value.timestamp = new Date('2024-04-28 7:20:00').getTime() / 1000 + conversationProps.type = CONVERSATION.TYPE.NOTE_TO_SELF + // Act + const result = useMessageInfo(message) + // Assert + expect(result.isCurrentUserOwnMessage.value).toBe(true) + expect(result.isEditable.value).toBe(true) + }) + test('moderator can edit other people messages', () => { // Arrange message.value.actorId = 'another-user' diff --git a/src/composables/useMessageInfo.js b/src/composables/useMessageInfo.js index 9242c91970e..442e567c7ed 100644 --- a/src/composables/useMessageInfo.js +++ b/src/composables/useMessageInfo.js @@ -10,7 +10,7 @@ import moment from '@nextcloud/moment' import { useConversationInfo } from './useConversationInfo.js' import { useStore } from './useStore.js' -import { ATTENDEE } from '../constants.js' +import { ATTENDEE, CONVERSATION } from '../constants.js' import { hasTalkFeature } from '../services/CapabilitiesManager.ts' import { useGuestNameStore } from '../stores/guestName.js' @@ -59,6 +59,10 @@ export function useMessageInfo(message = ref({})) { return false } + if (hasTalkFeature(message.value.token, 'edit-messages-note-to-self') && conversation.value.type === CONVERSATION.TYPE.NOTE_TO_SELF) { + return true + } + return (moment(message.value.timestamp * 1000).add(1, 'd')) > moment() })