Skip to content

Commit

Permalink
feat(NoteToSelf): allow to edit old messages on frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy authored and backportbot[bot] committed Aug 22, 2024
1 parent e2de6d7 commit df7b9df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/__mocks__/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const mockedCapabilities: Capabilities = {
'ban-v1',
'chat-reference-id',
'mention-permissions',
'edit-messages-note-to-self',
],
'features-local': [
'favorites',
Expand Down
13 changes: 12 additions & 1 deletion src/composables/__tests__/useMessageInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': [],
},
}))
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion src/composables/useMessageInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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()
})

Expand Down

0 comments on commit df7b9df

Please sign in to comment.