diff --git a/src/types/index.ts b/src/types/index.ts index ccd704e721c..d9c38e05be8 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -127,7 +127,7 @@ export type importEmailsParams = Required // Chats -export type Mention = RichObject<'server'|'call-type'|'icon-url'> +export type Mention = RichObject<'server'|'call-type'|'icon-url'> & { 'mention-id'?: string } export type File = RichObject<'size'|'path'|'link'|'mimetype'|'preview-available'> & { 'etag': string, 'permissions': string, diff --git a/src/utils/__tests__/textParse.spec.js b/src/utils/__tests__/textParse.spec.js index 5ff87f5c3c3..3e5b967c3c3 100644 --- a/src/utils/__tests__/textParse.spec.js +++ b/src/utils/__tests__/textParse.spec.js @@ -10,6 +10,39 @@ jest.mock('@nextcloud/router', () => ({ describe('textParse', () => { describe('parseMentions', () => { + it('replaces mentions correctly if mention-id is available', () => { + const input = 'test {mention-call1} test {mention-user1} test {mention-group1} test {mention-federated-user1}' + const output = 'test @"all" test @"alice" test @"group/talk" test @"federated_user/alice@server2.com"' + const parameters = { + 'mention-call1': { + id: 'room-id', + name: 'Room Display Name', + type: 'call', + 'mention-id': 'all', + }, + 'mention-user1': { + id: 'alice', + name: 'Just Alice', + type: 'user', + 'mention-id': 'alice', + }, + 'mention-group1': { + id: 'talk', + name: 'Talk Group', + type: 'user-group', + 'mention-id': 'group/talk', + }, + 'mention-federated-user1': { + id: 'alice', + name: 'Feder Alice', + type: 'user', + server: 'https://server2.com', + 'mention-id': 'federated_user/alice@https://server2.com', + } + } + expect(parseMentions(input, parameters)).toBe(output) + }) + it('replaces {mention-call} correctly', () => { const input = 'test {mention-call1}' const output = 'test @all' diff --git a/src/utils/textParse.ts b/src/utils/textParse.ts index aeac102d6c8..1e7d216777c 100644 --- a/src/utils/textParse.ts +++ b/src/utils/textParse.ts @@ -19,7 +19,10 @@ function parseMentions(text: string, parameters: ChatMessage['messageParameters' const value: Mention = parameters[key] as Mention let mention = '' - if (key.startsWith('mention-call') && value.type === MENTION.TYPE.CALL) { + if (value['mention-id']) { + // It is safer to always wrap id in double quotes. HTTPS protocol is default and therefore omitted. + mention = `@"${value['mention-id'].replace('https://', '')}"` + } else if (key.startsWith('mention-call') && value.type === MENTION.TYPE.CALL) { mention = '@all' } else if (key.startsWith('mention-federated-user') && value.type === MENTION.TYPE.FEDERATED_USER) { mention = `@"federated_user/${value.id}@${value!.server!.replace('https://', '')}"`