fix: remove unnecessary tags from reaction events
This commit is contained in:
@@ -9,7 +9,7 @@ import { useNostr } from '@/providers/NostrProvider'
|
|||||||
import client from '@/services/client.service'
|
import client from '@/services/client.service'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Heart, MessageCircle, Repeat, ThumbsUp } from 'lucide-react'
|
import { Heart, MessageCircle, Repeat, ThumbsUp } from 'lucide-react'
|
||||||
import { Event, kinds, nip19, validateEvent } from 'nostr-tools'
|
import { Event, kinds, validateEvent } from 'nostr-tools'
|
||||||
import {
|
import {
|
||||||
forwardRef,
|
forwardRef,
|
||||||
useCallback,
|
useCallback,
|
||||||
@@ -205,24 +205,23 @@ function NotificationItem({ notification }: { notification: Event }) {
|
|||||||
|
|
||||||
function ReactionNotification({ notification }: { notification: Event }) {
|
function ReactionNotification({ notification }: { notification: Event }) {
|
||||||
const { push } = useSecondaryPage()
|
const { push } = useSecondaryPage()
|
||||||
const bech32Id = useMemo(() => {
|
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'))
|
const eTag = notification.tags.findLast(tagNameEquals('e'))
|
||||||
const pTag = notification.tags.find(tagNameEquals('p'))
|
return eTag?.[1]
|
||||||
const eventId = eTag?.[1]
|
}, [notification, pubkey])
|
||||||
const author = pTag?.[1]
|
const { event } = useFetchEvent(eventId)
|
||||||
return eventId
|
if (!event || !eventId || ![kinds.ShortTextNote, PICTURE_EVENT_KIND].includes(event.kind)) {
|
||||||
? nip19.neventEncode(author ? { id: eventId, author } : { id: eventId })
|
|
||||||
: undefined
|
|
||||||
}, [notification])
|
|
||||||
const { event } = useFetchEvent(bech32Id)
|
|
||||||
if (!event || !bech32Id || ![kinds.ShortTextNote, PICTURE_EVENT_KIND].includes(event.kind)) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="flex items-center justify-between cursor-pointer py-2"
|
className="flex items-center justify-between cursor-pointer py-2"
|
||||||
onClick={() => push(toNote(bech32Id))}
|
onClick={() => push(toNote(event))}
|
||||||
>
|
>
|
||||||
<div className="flex gap-2 items-center flex-1">
|
<div className="flex gap-2 items-center flex-1">
|
||||||
<UserAvatar userId={notification.pubkey} size="small" />
|
<UserAvatar userId={notification.pubkey} size="small" />
|
||||||
|
|||||||
@@ -15,12 +15,13 @@ import {
|
|||||||
|
|
||||||
// https://github.com/nostr-protocol/nips/blob/master/25.md
|
// https://github.com/nostr-protocol/nips/blob/master/25.md
|
||||||
export function createReactionDraftEvent(event: Event): TDraftEvent {
|
export function createReactionDraftEvent(event: Event): TDraftEvent {
|
||||||
const tags = event.tags.filter((tag) => tag.length >= 2 && ['e', 'p'].includes(tag[0]))
|
const tags: string[][] = []
|
||||||
|
|
||||||
const hint = client.getEventHint(event.id)
|
const hint = client.getEventHint(event.id)
|
||||||
tags.push(['e', event.id, hint, event.pubkey])
|
tags.push(['e', event.id, hint, event.pubkey])
|
||||||
tags.push(['p', event.pubkey])
|
tags.push(['p', event.pubkey])
|
||||||
tags.push(['k', event.kind.toString()])
|
if (event.kind !== kinds.ShortTextNote) {
|
||||||
|
tags.push(['k', event.kind.toString()])
|
||||||
|
}
|
||||||
|
|
||||||
if (isReplaceable(event.kind)) {
|
if (isReplaceable(event.kind)) {
|
||||||
tags.push(hint ? ['a', getEventCoordinate(event), hint] : ['a', getEventCoordinate(event)])
|
tags.push(hint ? ['a', getEventCoordinate(event), hint] : ['a', getEventCoordinate(event)])
|
||||||
|
|||||||
Reference in New Issue
Block a user