diff --git a/packages/app/src/relaySelections.ts b/packages/app/src/relaySelections.ts index 3fd99af..700b771 100644 --- a/packages/app/src/relaySelections.ts +++ b/packages/app/src/relaySelections.ts @@ -1,3 +1,4 @@ +import {derived} from 'svelte/store' import {uniq, batcher, always} from "@welshman/lib" import { INBOX_RELAYS, @@ -59,11 +60,16 @@ export const { load: makeOutboxLoader(RELAYS), }) -export const getPubkeyRelays = (pubkey: string, mode?: string) => +export const getPubkeyRelays = (pubkey: string, mode?: RelayMode) => mode === RelayMode.Inbox ? getRelaysFromList(inboxRelaySelectionsByPubkey.get().get(pubkey)) : getRelaysFromList(relaySelectionsByPubkey.get().get(pubkey), mode) +export const derivePubkeyRelays = (pubkey: string, mode?: RelayMode) => + mode === RelayMode.Inbox + ? derived(inboxRelaySelectionsByPubkey, $m => getRelaysFromList($m.get(pubkey))) + : derived(relaySelectionsByPubkey, $m => getRelaysFromList($m.get(pubkey), mode)) + export const inboxRelaySelections = deriveEventsMapped(repository, { filters: [{kinds: [INBOX_RELAYS]}], itemToEvent: item => item.event, diff --git a/packages/util/src/List.ts b/packages/util/src/List.ts index 7dfbc98..ecac9d8 100644 --- a/packages/util/src/List.ts +++ b/packages/util/src/List.ts @@ -1,7 +1,7 @@ import {parseJson, uniq, nthEq} from "@welshman/lib" import {Address} from "./Address.js" import {uniqTags, getRelayTags} from "./Tags.js" -import {isRelayUrl, normalizeRelayUrl} from "./Relay.js" +import {isRelayUrl, RelayMode, normalizeRelayUrl} from "./Relay.js" import {Encryptable, DecryptedEvent} from "./Encryptable.js" import type {EncryptableUpdates} from "./Encryptable.js" @@ -89,7 +89,7 @@ export const addToListPrivately = (list: List, ...tags: string[][]) => { }) } -export const getRelaysFromList = (list?: List, mode?: string): string[] => { +export const getRelaysFromList = (list?: List, mode?: RelayMode): string[] => { let tags = getRelayTags(getListTags(list)) if (mode) {