Skip to content

Commit

Permalink
fix(textParse): use mention id from message parameters if available
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Jan 31, 2025
1 parent be8fd36 commit 85283cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export type importEmailsParams = Required<operations['room-import-emails-as-part
export type importEmailsResponse = ApiResponse<operations['room-import-emails-as-participants']['responses'][200]['content']['application/json']>

// 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,
Expand Down
8 changes: 6 additions & 2 deletions src/utils/textParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
mention = `@"${value['mention-id']}"`
} 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}"`
Expand All @@ -34,11 +37,12 @@ function parseMentions(text: string, parameters: ChatMessage['messageParameters'
&& [MENTION.TYPE.CIRCLE, MENTION.TYPE.TEAM].includes(value.type)) {
mention = `@"team/${value.id}"`
} else if (key.startsWith('mention-guest') && value.type === MENTION.TYPE.GUEST) {
// id and mention-id are both prefixed with "guest/"
mention = `@"${value.id}"`
} else if (key.startsWith('mention-email') && value.type === MENTION.TYPE.EMAIL) {
mention = `@"email/${value.id}"`
} else if (key.startsWith('mention-user') && value.type === MENTION.TYPE.USER) {
mention = value.id.includes(' ') ? `@"${value.id}"` : `@${value.id}`
mention = `@"${value.id}"`
}

if (mention) {
Expand Down

0 comments on commit 85283cd

Please sign in to comment.