Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): resolve a mention to the first visible word of a name

Yudhi Armyndharis89cde6c820f8
diff --git a/dashboard/src/utils/chatMessages.test.ts b/dashboard/src/utils/chatMessages.test.ts
index 7c97ca15c..aaf9401e2 100644
--- a/dashboard/src/utils/chatMessages.test.ts
+++ b/dashboard/src/utils/chatMessages.test.ts
@@ -627,3 +627,10 @@ test('a span delimiter already in a raw body is dropped, so it can never parse a
const names = buildMentionNameMap([msg({ author: '[email protected]', chatName: 'Ann' })]);
assert.equal(resolveMentions(`${MENTION_OPEN} *hi* @6281112345`, names), ` *hi* ${wrap('@Ann')}`);
});
+
+test('a push name whose first word is invisible renders its first visible word, not a bare @', () => {
+ for (const blank of ['\u3164', '\u200B', '\u2800']) {
+ const names = buildMentionNameMap([msg({ author: '[email protected]', chatName: `${blank} Bob Smith` })]);
+ assert.equal(resolveMentions('@6281112345', names), wrap('@Bob'));
+ }
+});
diff --git a/dashboard/src/utils/chatMessages.ts b/dashboard/src/utils/chatMessages.ts
index b194c53cf..d2b862ecb 100644
--- a/dashboard/src/utils/chatMessages.ts
+++ b/dashboard/src/utils/chatMessages.ts
@@ -193,7 +193,12 @@ export function resolveMentions(raw: string, names: Map<string, string>): string
: part.replace(MENTION_TOKEN, (full: string, prefix: string, digits: string) => {
// `^` only counts at the start of the whole text, not right after a closing backtick.
if (i > 0 && prefix === '') return full;
- const first = names.get(digits)?.split(' ')[0];
+ // The first word that renders as something: a name like "\u3164 Bob" is not blank as a
+ // whole, but its first word alone would show as a bare "@".
+ const first = names
+ .get(digits)
+ ?.split(' ')
+ .find(word => !blankMentionName(word));
return first ? `${prefix}${MENTION_OPEN}@${first}${MENTION_CLOSE}` : full;
}),
)