mirror of
https://github.com/dergigi/boris.git
synced 2026-01-03 15:04:24 +01:00
- Update bookmarkService to fetch kind:39701 events - Add processing logic for web bookmark events in bookmarkProcessing - Update bookmark deduplication to handle web bookmarks - Add 'web' type to IndividualBookmark interface - Implement distinct icon (fa-bookmark + fa-globe) for web bookmarks - Update CompactView and CardView to display web bookmark icon - Add web-bookmarks rule documentation
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
export interface NostrEvent {
|
|
id: string
|
|
kind: number
|
|
created_at: number
|
|
tags: string[][]
|
|
content: string
|
|
pubkey: string
|
|
sig: string
|
|
}
|
|
|
|
export function dedupeNip51Events(events: NostrEvent[]): NostrEvent[] {
|
|
const byId = new Map<string, NostrEvent>()
|
|
for (const e of events) {
|
|
if (e?.id && !byId.has(e.id)) byId.set(e.id, e)
|
|
}
|
|
const unique = Array.from(byId.values())
|
|
|
|
// Separate web bookmarks (kind:39701) from list-based bookmarks
|
|
const webBookmarks = unique.filter(e => e.kind === 39701)
|
|
|
|
const bookmarkLists = unique
|
|
.filter(e => e.kind === 10003 || e.kind === 30001)
|
|
.sort((a, b) => (b.created_at || 0) - (a.created_at || 0))
|
|
const latestBookmarkList = bookmarkLists.find(list => !list.tags?.some((t: string[]) => t[0] === 'd'))
|
|
|
|
const byD = new Map<string, NostrEvent>()
|
|
for (const e of unique) {
|
|
if (e.kind === 10003 || e.kind === 30003 || e.kind === 30001) {
|
|
const d = (e.tags || []).find((t: string[]) => t[0] === 'd')?.[1] || ''
|
|
const prev = byD.get(d)
|
|
if (!prev || (e.created_at || 0) > (prev.created_at || 0)) byD.set(d, e)
|
|
}
|
|
}
|
|
|
|
const setsAndNamedLists = Array.from(byD.values())
|
|
const out: NostrEvent[] = []
|
|
if (latestBookmarkList) out.push(latestBookmarkList)
|
|
out.push(...setsAndNamedLists)
|
|
// Add web bookmarks as individual events
|
|
out.push(...webBookmarks)
|
|
return out
|
|
}
|
|
|
|
|