Move getRelayUrls to getRelaysFromList

This commit is contained in:
Jon Staab
2025-04-24 17:10:41 -07:00
parent 3d1a6a106e
commit 3636064f25
6 changed files with 46 additions and 48 deletions
+15 -7
View File
@@ -1,4 +1,5 @@
import {
uniq,
intersection,
mergeLeft,
first,
@@ -29,7 +30,12 @@ import {
normalizeRelayUrl,
TrustedEvent,
Filter,
readList,
asDecryptedEvent,
getRelaysFromList,
RelayMode,
} from "@welshman/util"
import {Repository} from "@welshman/relay"
export const INDEXED_KINDS = [PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS]
@@ -38,12 +44,6 @@ export type RelaysAndFilters = {
filters: Filter[]
}
export enum RelayMode {
Read = "read",
Write = "write",
Inbox = "inbox",
}
export type RouterOptions = {
/**
* Retrieves the user's public key.
@@ -114,7 +114,15 @@ export const addMaximalFallbacks = (count: number, limit: number) => limit - cou
// Router class
export const routerContext: RouterOptions = {}
export const routerContext: RouterOptions = {
getPubkeyRelays: (pubkey: string, mode?: RelayMode) => {
return uniq(
Repository.get()
.query([{kinds: [RELAYS], authors: [pubkey]}])
.flatMap(event => getRelaysFromList(readList(asDecryptedEvent(event)), mode))
)
}
}
export class Router {
readonly options: RouterOptions