mirror of
https://github.com/dergigi/boris.git
synced 2026-01-08 17:34:52 +01:00
fix(highlights): ensure nostrverse fetch merges remote results after local for article/url
This commit is contained in:
@@ -24,7 +24,7 @@ export const fetchHighlightsForArticle = async (
|
||||
}
|
||||
|
||||
const orderedRelays = prioritizeLocalRelays(RELAYS)
|
||||
const { local: localRelays } = partitionRelays(orderedRelays)
|
||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||
|
||||
let aTagEvents: NostrEvent[] = []
|
||||
if (localRelays.length > 0) {
|
||||
@@ -48,21 +48,27 @@ export const fetchHighlightsForArticle = async (
|
||||
}
|
||||
}
|
||||
|
||||
if (aTagEvents.length === 0) {
|
||||
aTagEvents = await lastValueFrom(
|
||||
relayPool
|
||||
.req(orderedRelays, { kinds: [9802], '#a': [articleCoordinate] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
const highlight = processEvent(event)
|
||||
if (highlight && onHighlight) onHighlight(highlight)
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
// Always query remote relays to merge additional highlights
|
||||
if (remoteRelays.length > 0) {
|
||||
try {
|
||||
const aRemote = await lastValueFrom(
|
||||
relayPool
|
||||
.req(remoteRelays, { kinds: [9802], '#a': [articleCoordinate] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
const highlight = processEvent(event)
|
||||
if (highlight && onHighlight) onHighlight(highlight)
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
aTagEvents = aTagEvents.concat(aRemote)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
let eTagEvents: NostrEvent[] = []
|
||||
@@ -88,21 +94,27 @@ export const fetchHighlightsForArticle = async (
|
||||
}
|
||||
}
|
||||
|
||||
if (eTagEvents.length === 0) {
|
||||
eTagEvents = await lastValueFrom(
|
||||
relayPool
|
||||
.req(orderedRelays, { kinds: [9802], '#e': [eventId] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
const highlight = processEvent(event)
|
||||
if (highlight && onHighlight) onHighlight(highlight)
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
// Always query remote for e-tag too
|
||||
if (remoteRelays.length > 0) {
|
||||
try {
|
||||
const eRemote = await lastValueFrom(
|
||||
relayPool
|
||||
.req(remoteRelays, { kinds: [9802], '#e': [eventId] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
const highlight = processEvent(event)
|
||||
if (highlight && onHighlight) onHighlight(highlight)
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
eTagEvents = eTagEvents.concat(eRemote)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ export const fetchHighlightsForUrl = async (
|
||||
try {
|
||||
const seenIds = new Set<string>()
|
||||
const orderedRelaysUrl = prioritizeLocalRelays(RELAYS)
|
||||
const { local: localRelaysUrl } = partitionRelays(orderedRelaysUrl)
|
||||
const { local: localRelaysUrl, remote: remoteRelaysUrl } = partitionRelays(orderedRelaysUrl)
|
||||
let rawEvents: NostrEvent[] = []
|
||||
if (localRelaysUrl.length > 0) {
|
||||
try {
|
||||
@@ -39,21 +39,26 @@ export const fetchHighlightsForUrl = async (
|
||||
rawEvents = []
|
||||
}
|
||||
}
|
||||
if (rawEvents.length === 0) {
|
||||
rawEvents = await lastValueFrom(
|
||||
relayPool
|
||||
.req(orderedRelaysUrl, { kinds: [9802], '#r': [url] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
seenIds.add(event.id)
|
||||
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
if (remoteRelaysUrl.length > 0) {
|
||||
try {
|
||||
const remote = await lastValueFrom(
|
||||
relayPool
|
||||
.req(remoteRelaysUrl, { kinds: [9802], '#r': [url] })
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
tap((event: NostrEvent) => {
|
||||
seenIds.add(event.id)
|
||||
if (onHighlight) onHighlight(eventToHighlight(event))
|
||||
}),
|
||||
completeOnEose(),
|
||||
takeUntil(timer(6000)),
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
rawEvents = rawEvents.concat(remote)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
await rebroadcastEvents(rawEvents, relayPool, settings)
|
||||
const uniqueEvents = dedupeHighlights(rawEvents)
|
||||
|
||||
Reference in New Issue
Block a user