diff --git a/src/components/room/MessageMentions.tsx b/src/components/room/MessageMentions.tsx index 324e6ef..51d2b5f 100644 --- a/src/components/room/MessageMentions.tsx +++ b/src/components/room/MessageMentions.tsx @@ -127,8 +127,40 @@ function renderNode( } if (node.type === 'mention') { const displayName = resolveName(node.mentionType, node.id, node.label); + const baseClass = mentionStyles[node.mentionType] ?? mentionStyles.user; + + if (node.mentionType === 'ai') { + return ( + + ); + } + return ( - + @{displayName} ); diff --git a/src/components/room/RoomChatPanel.tsx b/src/components/room/RoomChatPanel.tsx index e239cfb..2d07658 100644 --- a/src/components/room/RoomChatPanel.tsx +++ b/src/components/room/RoomChatPanel.tsx @@ -230,6 +230,35 @@ const ChatInputArea = memo(function ChatInputArea({ } }; + // Listen for mention-click events from message content (e.g. 🤖 AI button) + useEffect(() => { + const onMentionClick = (e: Event) => { + const { type, id, label } = (e as CustomEvent<{ type: string; id: string; label: string }>).detail; + if (!textareaRef.current) return; + const textarea = textareaRef.current; + const cursorPos = textarea.selectionStart; + const textBefore = textarea.value.substring(0, cursorPos); + + if (type === 'ai') { + // Insert @ai:mention at cursor position + const html = buildMentionHtml('ai', id, label); + const spacer = ' '; + const newValue = textBefore + html + spacer + textarea.value.substring(cursorPos); + const newCursorPos = cursorPos + html.length + spacer.length; + onDraftChange(newValue); + setTimeout(() => { + if (textareaRef.current) { + textareaRef.current.value = newValue; + textareaRef.current.setSelectionRange(newCursorPos, newCursorPos); + textareaRef.current.focus(); + } + }, 0); + } + }; + document.addEventListener('mention-click', onMentionClick); + return () => document.removeEventListener('mention-click', onMentionClick); + }, []); + return (
{replyingTo && (