feat: support displaying highlights in replies

This commit is contained in:
codytseng
2025-11-17 21:55:24 +08:00
parent d3f0704eae
commit d2c5c923a3
6 changed files with 112 additions and 50 deletions

View File

@@ -1,5 +1,6 @@
import { getEventKey, getKeyFromTag, getParentTag } from '@/lib/event'
import { Event } from 'nostr-tools'
import { getHighlightSourceTag } from '@/lib/event-metadata'
import { Event, kinds } from 'nostr-tools'
import { createContext, useCallback, useContext, useState } from 'react'
type TReplyContext = {
@@ -30,12 +31,25 @@ export function ReplyProvider({ children }: { children: React.ReactNode }) {
if (newReplyKeySet.has(key)) return
newReplyKeySet.add(key)
const parentTag = getParentTag(reply)
if (parentTag) {
const parentKey = getKeyFromTag(parentTag.tag)
if (parentKey) {
newReplyEventMap.set(parentKey, [...(newReplyEventMap.get(parentKey) || []), reply])
let parentKey: string | undefined
if (reply.kind === kinds.Highlights) {
console.log('reply', reply)
const sourceTag = getHighlightSourceTag(reply)
if (!sourceTag) return
parentKey = getKeyFromTag(sourceTag)
} else {
const parentTag = getParentTag(reply)
if (!parentTag) return
parentKey = getKeyFromTag(parentTag.tag)
}
if (parentKey) {
if (reply.kind === kinds.Highlights) {
console.log('parentKey', parentKey)
}
newReplyEventMap.set(parentKey, [...(newReplyEventMap.get(parentKey) || []), reply])
}
})
if (newReplyEventMap.size === 0) return