From 3aa4a618841fc646ad6d952ab22f05e003ba2889 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Wed, 28 Feb 2024 18:18:12 +0100 Subject: [PATCH] fix(mentions): parse groups and federated user mentions Signed-off-by: Maksim Sukharev --- src/utils/textParse.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/utils/textParse.js b/src/utils/textParse.js index f13ef02155f8..bbebf2b8c235 100644 --- a/src/utils/textParse.js +++ b/src/utils/textParse.js @@ -21,6 +21,8 @@ * */ +import { getBaseUrl } from '@nextcloud/router' + /** * Parse message text to return proper formatting for mentions * @@ -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) }