Move getRelayUrls to getRelaysFromList
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user