Skip to content

Commit

Permalink
fix(mentions): parse groups and federated user mentions
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Feb 28, 2024
1 parent 6678d24 commit 3aa4a61
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/utils/textParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
*/

import { getBaseUrl } from '@nextcloud/router'

/**
* Parse message text to return proper formatting for mentions
*
Expand All @@ -32,11 +34,18 @@ function parseMentions(text, parameters) {
if (Object.keys(parameters).some(key => key.startsWith('mention'))) {
for (const [key, value] of Object.entries(parameters)) {
let mention = ''
if (value?.type === 'call') {

if (key.startsWith('mention-call') && value?.type === 'call') {
mention = '@all'
} else if (value?.type === 'user') {
} else if (key.startsWith('mention-federated-user') && value?.type === 'user') {
const server = value.server ?? getBaseUrl().split('//').pop()
mention = `@"federated_user/${value.id}@${server}"`
} else if (key.startsWith('mention-group') && value?.type === 'user-group') {
mention = `@"group/${value.id}"`
} else if (key.startsWith('mention-user') && value?.type === 'user') {
mention = value.id.includes(' ') ? `@"${value.id}"` : `@${value.id}`
}

if (mention) {
text = text.replace(new RegExp(`{${key}}`, 'g'), mention)
}
Expand Down

0 comments on commit 3aa4a61

Please sign in to comment.