fix: query highlights using both a-tag and e-tag

- Highlights on replaceable events include BOTH 'a' and 'e' tags
- Query for highlights using article coordinate (#a tag)
- Also query using event ID (#e tag) for comprehensive results
- Combine and deduplicate results from both queries
- Add detailed logging to help diagnose why highlights aren't found
- Suggest checking highlighter.com if no highlights found

Per NIP-84 and applesauce implementation, highlights on kind:30023
articles include both an addressable reference ('a' tag) and an event
reference ('e' tag).
This commit is contained in:
Gigi
2025-10-05 09:19:43 +01:00
parent 343f176f06
commit 2297d8ae96
3 changed files with 32 additions and 7 deletions

2
dist/index.html vendored
View File

@@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Boris - Nostr Bookmarks</title>
<script type="module" crossorigin src="/assets/index-h7fLeUhN.js"></script>
<script type="module" crossorigin src="/assets/index-DAkjOHFm.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-Dljx1pJR.css">
</head>
<body>

View File

@@ -83,7 +83,8 @@ const Bookmarks: React.FC<BookmarksProps> = ({ relayPool, onLogout }) => {
try {
setHighlightsLoading(true)
const fetchedHighlights = await fetchHighlightsForArticle(relayPool, articleCoordinate)
// Pass both the article coordinate and event ID for comprehensive highlight fetching
const fetchedHighlights = await fetchHighlightsForArticle(relayPool, articleCoordinate, article.event.id)
console.log(`📌 Found ${fetchedHighlights.length} highlights for article ${articleCoordinate}`)
setHighlights(fetchedHighlights)
} catch (err) {

View File

@@ -30,13 +30,15 @@ function dedupeHighlights(events: NostrEvent[]): NostrEvent[] {
}
/**
* Fetches highlights for a specific article by its address coordinate
* Fetches highlights for a specific article by its address coordinate and/or event ID
* @param relayPool - The relay pool to query
* @param articleCoordinate - The article's address in format "kind:pubkey:identifier" (e.g., "30023:abc...def:my-article")
* @param eventId - Optional event ID to also query by 'e' tag
*/
export const fetchHighlightsForArticle = async (
relayPool: RelayPool,
articleCoordinate: string
articleCoordinate: string,
eventId?: string
): Promise<Highlight[]> => {
try {
// Use well-known relays for highlights even if user isn't logged in
@@ -49,19 +51,41 @@ export const fetchHighlightsForArticle = async (
]
console.log('🔍 Fetching highlights (kind 9802) for article:', articleCoordinate)
console.log('🔍 Event ID:', eventId || 'none')
console.log('🔍 From relays:', highlightRelays)
console.log('🔍 Filter:', JSON.stringify({ kinds: [9802], '#a': [articleCoordinate] }, null, 2))
// Query for highlights that reference this article via the 'a' tag
const rawEvents = await lastValueFrom(
console.log('🔍 Filter 1 (a-tag):', JSON.stringify({ kinds: [9802], '#a': [articleCoordinate] }, null, 2))
const aTagEvents = await lastValueFrom(
relayPool
.req(highlightRelays, { kinds: [9802], '#a': [articleCoordinate] })
.pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
)
console.log('📊 Raw highlight events fetched:', rawEvents.length)
console.log('📊 Highlights via a-tag:', aTagEvents.length)
// If we have an event ID, also query for highlights that reference via the 'e' tag
let eTagEvents: NostrEvent[] = []
if (eventId) {
console.log('🔍 Filter 2 (e-tag):', JSON.stringify({ kinds: [9802], '#e': [eventId] }, null, 2))
eTagEvents = await lastValueFrom(
relayPool
.req(highlightRelays, { kinds: [9802], '#e': [eventId] })
.pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
)
console.log('📊 Highlights via e-tag:', eTagEvents.length)
}
// Combine results from both queries
const rawEvents = [...aTagEvents, ...eTagEvents]
console.log('📊 Total raw highlight events fetched:', rawEvents.length)
if (rawEvents.length > 0) {
console.log('📄 Sample highlight tags:', JSON.stringify(rawEvents[0].tags, null, 2))
} else {
console.log('❌ No highlights found. Article coordinate:', articleCoordinate)
console.log('❌ Event ID:', eventId || 'none')
console.log('💡 Try checking if there are any highlights on this article at https://highlighter.com')
}
// Deduplicate events by ID