feat: replace trending notes service
This commit is contained in:
@@ -24,9 +24,7 @@ import {
|
||||
matchFilters,
|
||||
Event as NEvent,
|
||||
nip19,
|
||||
Relay,
|
||||
SimplePool,
|
||||
validateEvent,
|
||||
VerifiedEvent
|
||||
} from 'nostr-tools'
|
||||
import { AbstractRelay } from 'nostr-tools/abstract-relay'
|
||||
@@ -799,39 +797,6 @@ class ClientService extends EventTarget {
|
||||
return this.eventDataLoader.load(id)
|
||||
}
|
||||
|
||||
async fetchTrendingNotes() {
|
||||
if (this.trendingNotesCache) {
|
||||
return this.trendingNotesCache
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('https://api.nostr.band/v0/trending/notes')
|
||||
const data = await response.json()
|
||||
const events: NEvent[] = []
|
||||
for (const note of data.notes ?? []) {
|
||||
if (validateEvent(note.event)) {
|
||||
events.push(note.event)
|
||||
this.addEventToCache(note.event)
|
||||
if (note.relays?.length) {
|
||||
note.relays.map((r: string) => {
|
||||
try {
|
||||
const relay = new Relay(r)
|
||||
this.trackEventSeenOn(note.event.id, relay)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
this.trendingNotesCache = events
|
||||
return this.trendingNotesCache
|
||||
} catch (error) {
|
||||
console.error('fetchTrendingNotes error', error)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
addEventToCache(event: NEvent) {
|
||||
this.eventDataLoader.prime(event.id, Promise.resolve(event))
|
||||
if (isReplaceableEvent(event.kind)) {
|
||||
|
||||
Reference in New Issue
Block a user