refact: bookmarks

This commit is contained in:
codytseng
2025-04-18 22:53:52 +08:00
parent 7876f26d0c
commit 46d48a6d52
22 changed files with 223 additions and 175 deletions

View File

@@ -746,6 +746,21 @@ class ClientService extends EventTarget {
return event
}
async fetchBookmarkListEvent(pubkey: string): Promise<NEvent | undefined> {
const storedBookmarkListEvent = await indexedDb.getReplaceableEvent(pubkey, kinds.BookmarkList)
if (storedBookmarkListEvent) {
return storedBookmarkListEvent
}
const relayList = await this.fetchRelayList(pubkey)
const events = await this.query(relayList.write.concat(BIG_RELAY_URLS), {
authors: [pubkey],
kinds: [kinds.BookmarkList]
})
return events.sort((a, b) => b.created_at - a.created_at)[0]
}
async fetchFollowings(pubkey: string, storeToIndexedDb = false) {
const followListEvent = await this.fetchFollowListEvent(pubkey, storeToIndexedDb)
return followListEvent ? extractPubkeysFromEventTags(followListEvent.tags) : []