diff --git a/surfsense_backend/app/utils/chat_comments.py b/surfsense_backend/app/utils/chat_comments.py index 256782a5f..5349466f9 100644 --- a/surfsense_backend/app/utils/chat_comments.py +++ b/surfsense_backend/app/utils/chat_comments.py @@ -38,14 +38,16 @@ def parse_mentions(content: str) -> list[UUID]: def render_mentions(content: str, user_names: dict[UUID, str]) -> str: """ - Replace @[uuid] mentions with @DisplayName in content. + Replace @[uuid] mentions with @{DisplayName} in content. + + Uses curly braces as delimiters for unambiguous frontend parsing. Args: content: Comment text with @[uuid] mentions user_names: Dict mapping user UUIDs to display names Returns: - Content with mentions rendered as @DisplayName + Content with mentions rendered as @{DisplayName} """ def replace_mention(match: re.Match) -> str: @@ -53,7 +55,7 @@ def render_mentions(content: str, user_names: dict[UUID, str]) -> str: uuid = UUID(match.group(1)) name = user_names.get(uuid) if name: - return f"@{name}" + return f"@{{{name}}}" # Keep original format if user not found return match.group(0) except ValueError: diff --git a/surfsense_web/components/chat-comments/comment-item/comment-item.tsx b/surfsense_web/components/chat-comments/comment-item/comment-item.tsx index e37e17f6d..643c8b295 100644 --- a/surfsense_web/components/chat-comments/comment-item/comment-item.tsx +++ b/surfsense_web/components/chat-comments/comment-item/comment-item.tsx @@ -68,7 +68,8 @@ function formatTimestamp(dateString: string): string { } function renderMentions(content: string): React.ReactNode { - const mentionPattern = /@(\w+(?:\s+\w+)*)/g; + // Match @{DisplayName} format from backend + const mentionPattern = /@\{([^}]+)\}/g; const parts: React.ReactNode[] = []; let lastIndex = 0; let match: RegExpExecArray | null; @@ -78,9 +79,10 @@ function renderMentions(content: string): React.ReactNode { parts.push(content.slice(lastIndex, match.index)); } + // Display as @DisplayName (without curly braces) parts.push( - {match[0]} + @{match[1]} );