Skip to content

Commit 6cff311

Browse files
committed
fix(textParse): use mention id from message parameters if available
Signed-off-by: Maksim Sukharev <[email protected]>
1 parent ab350f3 commit 6cff311

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

src/stores/__tests__/chatExtras.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ describe('chatExtrasStore', () => {
128128
it('should render mentions properly when editing message', () => {
129129
// Arrange
130130
const parameters = {
131-
'mention-call1': { type: 'call', name: 'Conversation101' },
132-
'mention-user1': { type: 'user', name: 'Alice Joel', id: 'alice' },
131+
'mention-call1': { type: 'call', name: 'Conversation101', 'mention-id': 'all' },
132+
'mention-user1': { type: 'user', name: 'Alice Joel', id: 'alice', 'mention-id': 'alice' },
133133
}
134134
// Act
135135
chatExtrasStore.setChatEditInput({
@@ -138,7 +138,7 @@ describe('chatExtrasStore', () => {
138138
parameters
139139
})
140140
// Assert
141-
expect(chatExtrasStore.getChatEditInput('token-1')).toBe('Hello @all and @alice')
141+
expect(chatExtrasStore.getChatEditInput('token-1')).toBe('Hello @"all" and @"alice"')
142142
})
143143

144144
it('should store chat input without escaping special symbols', () => {

src/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export type importEmailsParams = Required<operations['room-import-emails-as-part
127127
export type importEmailsResponse = ApiResponse<operations['room-import-emails-as-participants']['responses'][200]['content']['application/json']>
128128

129129
// Chats
130-
export type Mention = RichObject<'server'|'call-type'|'icon-url'>
130+
export type Mention = RichObject<'server'|'call-type'|'icon-url'> & { 'mention-id'?: string }
131131
export type File = RichObject<'size'|'path'|'link'|'mimetype'|'preview-available'> & {
132132
'etag': string,
133133
'permissions': string,

src/utils/__tests__/textParse.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,39 @@ jest.mock('@nextcloud/router', () => ({
1010

1111
describe('textParse', () => {
1212
describe('parseMentions', () => {
13+
it('replaces mentions correctly if mention-id is available', () => {
14+
const input = 'test {mention-call1} test {mention-user1} test {mention-group1} test {mention-federated-user1}'
15+
const output = 'test @"all" test @"alice" test @"group/talk" test @"federated_user/[email protected]"'
16+
const parameters = {
17+
'mention-call1': {
18+
id: 'room-id',
19+
name: 'Room Display Name',
20+
type: 'call',
21+
'mention-id': 'all',
22+
},
23+
'mention-user1': {
24+
id: 'alice',
25+
name: 'Just Alice',
26+
type: 'user',
27+
'mention-id': 'alice',
28+
},
29+
'mention-group1': {
30+
id: 'talk',
31+
name: 'Talk Group',
32+
type: 'user-group',
33+
'mention-id': 'group/talk',
34+
},
35+
'mention-federated-user1': {
36+
id: 'alice',
37+
name: 'Feder Alice',
38+
type: 'user',
39+
server: 'https://server2.com',
40+
'mention-id': 'federated_user/[email protected]',
41+
}
42+
}
43+
expect(parseMentions(input, parameters)).toBe(output)
44+
})
45+
1346
it('replaces {mention-call} correctly', () => {
1447
const input = 'test {mention-call1}'
1548
const output = 'test @all'

src/utils/textParse.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ function parseMentions(text: string, parameters: ChatMessage['messageParameters'
1919
const value: Mention = parameters[key] as Mention
2020
let mention = ''
2121

22-
if (key.startsWith('mention-call') && value.type === MENTION.TYPE.CALL) {
22+
if (value['mention-id']) {
23+
mention = `@"${value['mention-id']}"`
24+
} else if (key.startsWith('mention-call') && value.type === MENTION.TYPE.CALL) {
2325
mention = '@all'
2426
} else if (key.startsWith('mention-federated-user')
2527
&& [MENTION.TYPE.USER, MENTION.TYPE.FEDERATED_USER].includes(value.type)) {

0 commit comments

Comments
 (0)