import Image from '@/components/Image' import { useFetchEvent } from '@/hooks' import { toNote } from '@/lib/link' import { tagNameEquals } from '@/lib/tag' import { cn } from '@/lib/utils' import { useSecondaryPage } from '@/PageManager' import { useNostr } from '@/providers/NostrProvider' import { Heart } from 'lucide-react' import { Event } from 'nostr-tools' import { useMemo } from 'react' import ContentPreview from '../../ContentPreview' import { FormattedTimestamp } from '../../FormattedTimestamp' import UserAvatar from '../../UserAvatar' export function ReactionNotification({ notification, isNew = false }: { notification: Event isNew?: boolean }) { const { push } = useSecondaryPage() const { pubkey } = useNostr() const eventId = useMemo(() => { const targetPubkey = notification.tags.findLast(tagNameEquals('p'))?.[1] if (targetPubkey !== pubkey) return undefined const eTag = notification.tags.findLast(tagNameEquals('e')) return eTag?.[1] }, [notification, pubkey]) const { event } = useFetchEvent(eventId) const reaction = useMemo(() => { if (!notification.content || notification.content === '+') { return } const emojiName = /^:([^:]+):$/.exec(notification.content)?.[1] if (emojiName) { const emojiTag = notification.tags.find((tag) => tag[0] === 'emoji' && tag[1] === emojiName) const emojiUrl = emojiTag?.[2] if (emojiUrl) { return ( {emojiName}} /> ) } } return notification.content }, [notification]) if (!event || !eventId) { return null } return (
push(toNote(event))} >
{reaction}
) }