mirror of
https://github.com/dergigi/boris.git
synced 2026-01-16 21:34:21 +01:00
fix: normalize highlight article references to naddr format for proper matching
- Convert coordinate-format eventReferences (30023:pubkey:identifier) to naddr - ReadItems use naddr format for IDs, but highlights store coordinates - Properly match highlights to articles by normalizing both formats - Fixes 'highlighted' filter showing no results - Handles conversion errors gracefully by falling back to original format
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ReadItem } from '../services/readsService'
|
||||
import { ReadingProgressFilterType } from '../components/ReadingProgressFilters'
|
||||
import { Highlight } from '../types/highlights'
|
||||
import { nip19 } from 'nostr-tools'
|
||||
|
||||
/**
|
||||
* Filters ReadItems by reading progress
|
||||
@@ -11,12 +12,34 @@ export function filterByReadingProgress(
|
||||
highlights?: Highlight[]
|
||||
): ReadItem[] {
|
||||
// Build a map of article references to highlight count
|
||||
// Normalize both coordinate and naddr formats for matching
|
||||
const articleHighlightCount = new Map<string, number>()
|
||||
if (highlights) {
|
||||
highlights.forEach(h => {
|
||||
if (h.eventReference) {
|
||||
const count = articleHighlightCount.get(h.eventReference) || 0
|
||||
articleHighlightCount.set(h.eventReference, count + 1)
|
||||
// eventReference could be a hex ID or a coordinate (30023:pubkey:identifier)
|
||||
let normalizedRef = h.eventReference
|
||||
|
||||
// If it's a coordinate, convert to naddr format for matching
|
||||
if (h.eventReference.includes(':')) {
|
||||
const parts = h.eventReference.split(':')
|
||||
if (parts.length === 3) {
|
||||
const [kind, pubkey, identifier] = parts
|
||||
try {
|
||||
normalizedRef = nip19.naddrEncode({
|
||||
kind: parseInt(kind),
|
||||
pubkey,
|
||||
identifier
|
||||
})
|
||||
} catch {
|
||||
// If conversion fails, use the original reference
|
||||
normalizedRef = h.eventReference
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const count = articleHighlightCount.get(normalizedRef) || 0
|
||||
articleHighlightCount.set(normalizedRef, count + 1)
|
||||
}
|
||||
if (h.urlReference) {
|
||||
const count = articleHighlightCount.get(h.urlReference) || 0
|
||||
|
||||
Reference in New Issue
Block a user