fix: correct bookmark event kinds to match NIP-51 standards

- Fix bookmark list kind from 30001 to 10003 (kinds.BookmarkList)
- Fix bookmark sets kind from 30001 to 30003 (kinds.Bookmarksets)
- Update dedupeNip51Events to handle correct NIP-51 event kinds
- Now fetching the correct bookmark events that support hidden tags
This commit is contained in:
Gigi
2025-10-02 20:41:53 +02:00
parent eb282fcbb0
commit a66c051444

View File

@@ -47,18 +47,18 @@ function dedupeNip51Events(events: NostrEvent[]): NostrEvent[] {
for (const e of events) { if (e?.id && !byId.has(e.id)) byId.set(e.id, e) } for (const e of events) { if (e?.id && !byId.has(e.id)) byId.set(e.id, e) }
const unique = Array.from(byId.values()) const unique = Array.from(byId.values())
// Get the latest bookmark list (30001) - default bookmark list without 'd' tag // Get the latest bookmark list (10003) - default bookmark list without 'd' tag
const bookmarkLists = unique const bookmarkLists = unique
.filter(e => e.kind === 30001) .filter(e => e.kind === 10003)
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0)) .sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
const latestBookmarkList = bookmarkLists.find(list => const latestBookmarkList = bookmarkLists.find(list =>
!list.tags?.some((t: string[]) => t[0] === 'd') !list.tags?.some((t: string[]) => t[0] === 'd')
) )
// Group bookmark sets (30003) and named bookmark lists (30001 with 'd' tag) by their 'd' identifier // Group bookmark sets (30003) and named bookmark lists (10003 with 'd' tag) by their 'd' identifier
const byD = new Map<string, NostrEvent>() const byD = new Map<string, NostrEvent>()
for (const e of unique) { for (const e of unique) {
if (e.kind === 30001 || e.kind === 30003) { if (e.kind === 10003 || e.kind === 30003) {
const d = (e.tags || []).find((t: string[]) => t[0] === 'd')?.[1] || '' const d = (e.tags || []).find((t: string[]) => t[0] === 'd')?.[1] || ''
const prev = byD.get(d) const prev = byD.get(d)
if (!prev || (e.created_at || 0) > (prev.created_at || 0)) byD.set(d, e) if (!prev || (e.created_at || 0) > (prev.created_at || 0)) byD.set(d, e)
@@ -135,11 +135,11 @@ export const fetchBookmarks = async (
} }
// Get relay URLs from the pool // Get relay URLs from the pool
const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url) const relayUrls = Array.from(relayPool.relays.values()).map(relay => relay.url)
// Fetch bookmark lists (30001) and bookmark sets (30003) - NIP-51 standards // Fetch bookmark lists (10003) and bookmark sets (30003) - NIP-51 standards
console.log('🔍 Fetching bookmark events from relays:', relayUrls) console.log('🔍 Fetching bookmark events from relays:', relayUrls)
const rawEvents = await lastValueFrom( const rawEvents = await lastValueFrom(
relayPool relayPool
.req(relayUrls, { kinds: [30001, 30003], authors: [activeAccount.pubkey] }) .req(relayUrls, { kinds: [10003, 30003], authors: [activeAccount.pubkey] })
.pipe(completeOnEose(), takeUntil(timer(10000)), toArray()) .pipe(completeOnEose(), takeUntil(timer(10000)), toArray())
) )
const bookmarkListEvents = dedupeNip51Events(rawEvents) const bookmarkListEvents = dedupeNip51Events(rawEvents)