Files
welshman/packages/client/src/messagingRelayLists.ts
T
2026-06-16 09:22:26 -07:00

28 lines
973 B
TypeScript

import {MESSAGING_RELAYS, asDecryptedEvent, readList} from "@welshman/util"
import type {TrustedEvent} from "@welshman/util"
import {RepositoryCollection} from "./repositoryCollection.js"
import type {ClientContext} from "./client.js"
import type {RelayLists} from "./relayLists.js"
/**
* Kind-10050 messaging relay lists (NIP-17), keyed by pubkey. Loaded via the
* outbox model (the author's write relays), so it depends on the relay-list
* collection.
*/
export class MessagingRelayLists extends RepositoryCollection<ReturnType<typeof readList>> {
constructor(
ctx: ClientContext,
readonly relayLists: RelayLists,
) {
super(ctx, {
filters: [{kinds: [MESSAGING_RELAYS]}],
eventToItem: (event: TrustedEvent) => readList(asDecryptedEvent(event)),
getKey: list => list.event.pubkey,
})
}
fetch(pubkey: string, relayHints: string[] = []) {
return this.relayLists.makeOutboxLoader(MESSAGING_RELAYS)(pubkey, relayHints)
}
}