import { useNoteStatsById } from '@/hooks/useNoteStatsById' import { useUserTrust } from '@/contexts/user-trust-context' import { cn } from '@/lib/utils' import noteStatsService from '@/services/note-stats.service' import { useRssUrlThreadQueryRelays } from '@/hooks/useRssUrlThreadQueryRelays' import { useNostr } from '@/providers/NostrProvider' import { Bookmark, Highlighter, MessageCircle, ThumbsUp } from 'lucide-react' import type { Event } from 'nostr-tools' import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' /** Compact reply / reaction / bookmark / highlight counts for RSS + Web URL threads. */ export default function RssUrlThreadStatsBar({ event, className }: { event: Event className?: string }) { const { t } = useTranslation() const { pubkey } = useNostr() const { relayUrls: statsRelays, key: statsRelaysKey } = useRssUrlThreadQueryRelays() const { hideUntrustedInteractions, isUserTrusted } = useUserTrust() const noteStats = useNoteStatsById(event.id) const [loading, setLoading] = useState(false) useEffect(() => { setLoading(true) noteStatsService .fetchNoteStats(event, pubkey, statsRelays, { foreground: true }) .finally(() => setLoading(false)) }, [event.id, event.kind, event.created_at, event.sig, pubkey, statsRelaysKey]) const fmt = (n: number) => (n >= 100 ? '99+' : String(n)) const { replyCount, reactionCount, highlightCount, bookmarkCount } = useMemo(() => { const replies = noteStats?.replies ?? [] const likes = noteStats?.likes ?? [] const highlights = noteStats?.highlights ?? [] const trustedReplyCount = hideUntrustedInteractions ? replies.filter((r) => isUserTrusted(r.pubkey)).length : replies.length const trustedReactionCount = hideUntrustedInteractions ? likes.filter((l) => isUserTrusted(l.pubkey)).length : likes.length const trustedHighlightCount = hideUntrustedInteractions ? highlights.filter((h) => isUserTrusted(h.pubkey)).length : highlights.length const bookmarkCountInner = noteStats?.bookmarkPubkeySet?.size ?? 0 return { replyCount: trustedReplyCount, reactionCount: trustedReactionCount, highlightCount: trustedHighlightCount, bookmarkCount: bookmarkCountInner } }, [noteStats, hideUntrustedInteractions, isUserTrusted]) return (