feat: NIP-10

This commit is contained in:
codytseng
2025-03-12 17:23:01 +08:00
parent 5f7a99c7b5
commit 4ad96eab66
6 changed files with 309 additions and 212 deletions

View File

@@ -2,11 +2,12 @@ import { Button } from '@/components/ui/button'
import { useToast } from '@/hooks/use-toast'
import { createCommentDraftEvent, createShortTextNoteDraftEvent } from '@/lib/draft-event'
import { getRootEventTag } from '@/lib/event.ts'
import { generateEventIdFromETag } from '@/lib/tag.ts'
import { useNostr } from '@/providers/NostrProvider'
import client from '@/services/client.service'
import postContentCache from '@/services/post-content-cache.service'
import { ChevronDown, ImageUp, LoaderCircle } from 'lucide-react'
import { Event, kinds, nip19 } from 'nostr-tools'
import { Event, kinds } from 'nostr-tools'
import { useEffect, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import TextareaWithMentions from '../TextareaWithMentions.tsx'
@@ -70,34 +71,28 @@ export default function NormalPostContent({
try {
const additionalRelayUrls: string[] = []
if (parentEvent && !specifiedRelayUrls) {
const relayList = await client.fetchRelayList(parentEvent.pubkey)
additionalRelayUrls.push(...relayList.read.slice(0, 3))
const rootEventTag = getRootEventTag(parentEvent)
if (rootEventTag) {
const [, rootEventId, rootEventRelay, , rootAuthor] = rootEventTag
const [, , , , rootAuthor] = rootEventTag
if (rootAuthor) {
if (rootAuthor !== parentEvent.pubkey) {
const rootAuthorRelayList = await client.fetchRelayList(rootAuthor)
additionalRelayUrls.push(...rootAuthorRelayList.read.slice(0, 3))
additionalRelayUrls.push(...rootAuthorRelayList.read.slice(0, 4))
}
} else {
try {
const rootEvent = await client.fetchEvent(
nip19.neventEncode(
rootEventRelay
? { id: rootEventId }
: { id: rootEventId, relays: [rootEventRelay] }
)
)
const rootEventId = generateEventIdFromETag(rootEventTag)
if (rootEventId) {
const rootEvent = await client.fetchEvent(rootEventId)
if (rootEvent && rootEvent.pubkey !== parentEvent.pubkey) {
const rootAuthorRelayList = await client.fetchRelayList(rootEvent.pubkey)
additionalRelayUrls.push(...rootAuthorRelayList.read.slice(0, 3))
additionalRelayUrls.push(...rootAuthorRelayList.read.slice(0, 4))
}
} catch {
// ignore
}
}
}
const relayList = await client.fetchRelayList(parentEvent.pubkey)
additionalRelayUrls.push(...relayList.read.slice(0, 4))
}
const draftEvent =
parentEvent && parentEvent.kind !== kinds.ShortTextNote