import { EmbeddedEventParser, EmbeddedMentionParser, EmbeddedUrlParser, EmbeddedHashtagParser, EmbeddedEmojiParser, parseContent } from '@/lib/content-parser' import { EmbeddedMention, EmbeddedHashtag } from '../Embedded' import { SecondaryPageLink } from '@/PageManager' import { toNote } from '@/lib/link' import { truncateUrl } from '@/lib/url' import { getEmojiInfosFromEmojiTags } from '@/lib/tag' import Emoji from '../Emoji' import { useMemo } from 'react' import { Event } from 'nostr-tools' /** * Lightweight inline content renderer for NIRC chat messages. * Reuses the same parseContent pipeline as the full Content component * but renders everything inline to fit the IRC-style monospace layout. */ export default function ChatContent({ content, event }: { content: string; event?: Event }) { const { nodes, emojiInfos } = useMemo(() => { if (!content) return { nodes: [], emojiInfos: [] } const nodes = parseContent(content, [ EmbeddedEventParser, EmbeddedMentionParser, EmbeddedUrlParser, EmbeddedHashtagParser, EmbeddedEmojiParser ]) const emojiInfos = getEmojiInfosFromEmojiTags(event?.tags) return { nodes, emojiInfos } }, [content, event]) if (!nodes || nodes.length === 0) return null return ( {nodes.map((node, i) => { if (node.type === 'text') { return {node.data} } if (node.type === 'mention') { const userId = (node.data as string).split(':')[1] if (!userId) return {node.data as string} return } if (node.type === 'url') { return ( e.stopPropagation()} > {truncateUrl(node.data as string)} ) } if (node.type === 'image' || node.type === 'images') { const url = Array.isArray(node.data) ? node.data[0] : node.data return ( e.stopPropagation()} > [image] ) } if (node.type === 'media') { return ( e.stopPropagation()} > [media] ) } if (node.type === 'event') { const id = (node.data as string).split(':')[1] if (!id) return {node.data as string} return ( e.stopPropagation()} > [note] ) } if (node.type === 'hashtag') { return } if (node.type === 'emoji') { const shortcode = (node.data as string).split(':')[1] const emoji = emojiInfos.find((e) => e.shortcode === shortcode) if (!emoji) return {node.data as string} return } if (node.type === 'youtube' || node.type === 'x-post') { return ( e.stopPropagation()} > {truncateUrl(node.data as string)} ) } if (node.type === 'invoice') { return ( [ln-invoice] ) } return null })} ) }