Use new relay getters

This commit is contained in:
Jon Staab
2025-04-25 10:41:38 -07:00
parent c18b29e7d6
commit da2457da9f
6 changed files with 17 additions and 24 deletions
+4 -4
View File
@@ -29,6 +29,8 @@ import {
getRelayTagValues, getRelayTagValues,
toNostrURI, toNostrURI,
unionFilters, unionFilters,
getRelaysFromList,
RelayMode,
} from "@welshman/util" } from "@welshman/util"
import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util" import type {TrustedEvent, Filter, EventContent, EventTemplate} from "@welshman/util"
import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net" import {Pool, PublishStatus, AuthStatus, SocketStatus} from "@welshman/net"
@@ -42,10 +44,8 @@ import {
MergedThunk, MergedThunk,
profilesByPubkey, profilesByPubkey,
relaySelectionsByPubkey, relaySelectionsByPubkey,
getWriteRelayUrls,
tagEvent, tagEvent,
tagEventForReaction, tagEventForReaction,
getRelayUrls,
userRelaySelections, userRelaySelections,
userInboxRelaySelections, userInboxRelaySelections,
nip44EncryptToSelf, nip44EncryptToSelf,
@@ -72,7 +72,7 @@ import {
export const getPubkeyHints = (pubkey: string) => { export const getPubkeyHints = (pubkey: string) => {
const selections = relaySelectionsByPubkey.get().get(pubkey) const selections = relaySelectionsByPubkey.get().get(pubkey)
const relays = selections ? getWriteRelayUrls(selections) : [] const relays = selections ? getRelaysFromList(selections, RelayMode.Write) : []
const hints = relays.length ? relays : INDEXER_RELAYS const hints = relays.length ? relays : INDEXER_RELAYS
return hints return hints
@@ -238,7 +238,7 @@ export const setInboxRelayPolicy = (url: string, enabled: boolean) => {
const list = get(userInboxRelaySelections) || makeList({kind: INBOX_RELAYS}) const list = get(userInboxRelaySelections) || makeList({kind: INBOX_RELAYS})
// Only update inbox policies if they already exist or we're adding them // Only update inbox policies if they already exist or we're adding them
if (enabled || getRelayUrls(list).includes(url)) { if (enabled || getRelaysFromList(list).includes(url)) {
const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url) const tags = getRelayTags(getListTags(list)).filter(t => normalizeRelayUrl(t[1]) !== url)
if (enabled) { if (enabled) {
+3 -2
View File
@@ -7,8 +7,9 @@
DELETE, DELETE,
isReplaceable, isReplaceable,
getAddress, getAddress,
getRelaysFromList,
} from "@welshman/util" } from "@welshman/util"
import {pubkey, userRelaySelections, publishThunk, getRelayUrls, repository} from "@welshman/app" import {pubkey, userRelaySelections, publishThunk, repository} from "@welshman/app"
import {preventDefault} from "@lib/html" import {preventDefault} from "@lib/html"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
@@ -40,7 +41,7 @@
const denominator = chunks.length + 2 const denominator = chunks.length + 2
const relays = uniq([ const relays = uniq([
...INDEXER_RELAYS, ...INDEXER_RELAYS,
...getRelayUrls($userRelaySelections), ...getRelaysFromList($userRelaySelections),
...getMembershipUrls($userMembership), ...getMembershipUrls($userMembership),
]) ])
+2 -2
View File
@@ -25,6 +25,7 @@ import {
getTagValue, getTagValue,
getAddress, getAddress,
isShareableRelayUrl, isShareableRelayUrl,
getRelaysFromList,
} from "@welshman/util" } from "@welshman/util"
import type {TrustedEvent, Filter, List} from "@welshman/util" import type {TrustedEvent, Filter, List} from "@welshman/util"
import {feedFromFilters, makeRelayFeed, makeIntersectionFeed} from "@welshman/feeds" import {feedFromFilters, makeRelayFeed, makeIntersectionFeed} from "@welshman/feeds"
@@ -41,7 +42,6 @@ import {
loadFollows, loadFollows,
loadProfile, loadProfile,
loadInboxRelaySelections, loadInboxRelaySelections,
getRelayUrls,
} from "@welshman/app" } from "@welshman/app"
import {createScroller} from "@lib/html" import {createScroller} from "@lib/html"
import {daysBetween} from "@lib/util" import {daysBetween} from "@lib/util"
@@ -421,7 +421,7 @@ export const loadUserData = (pubkey: string, relays: string[] = []) => {
export const discoverRelays = (lists: List[]) => export const discoverRelays = (lists: List[]) =>
Promise.all( Promise.all(
uniq(lists.flatMap(getRelayUrls)) uniq(lists.flatMap($l => getRelaysFromList($l)))
.filter(isShareableRelayUrl) .filter(isShareableRelayUrl)
.map(url => loadRelay(url)), .map(url => loadRelay(url)),
) )
+1 -1
View File
@@ -18,6 +18,7 @@ import {
always, always,
} from "@welshman/lib" } from "@welshman/lib"
import {load} from "@welshman/net" import {load} from "@welshman/net"
import {collection} from "@welshman/store"
import { import {
getIdFilters, getIdFilters,
WRAP, WRAP,
@@ -47,7 +48,6 @@ import {routerContext, Router} from "@welshman/router"
import { import {
pubkey, pubkey,
repository, repository,
collection,
profilesByPubkey, profilesByPubkey,
tracker, tracker,
makeTrackerStore, makeTrackerStore,
+2 -2
View File
@@ -19,6 +19,7 @@
FOLLOWS, FOLLOWS,
PROFILE, PROFILE,
RELAYS, RELAYS,
getRelaysFromList,
} from "@welshman/util" } from "@welshman/util"
import {Nip46Broker, makeSecret} from "@welshman/signer" import {Nip46Broker, makeSecret} from "@welshman/signer"
import type {Socket} from "@welshman/net" import type {Socket} from "@welshman/net"
@@ -33,7 +34,6 @@
session, session,
signer, signer,
dropSession, dropSession,
getRelayUrls,
userInboxRelaySelections, userInboxRelaySelections,
loginWithNip01, loginWithNip01,
loginWithNip46, loginWithNip46,
@@ -204,7 +204,7 @@
{kinds: [WRAP], "#p": [$pubkey], since: ago(WEEK, 2)}, {kinds: [WRAP], "#p": [$pubkey], since: ago(WEEK, 2)},
{kinds: [WRAP], "#p": [$pubkey], limit: 100}, {kinds: [WRAP], "#p": [$pubkey], limit: 100},
], ],
relays: getRelayUrls($userInboxRelaySelections), relays: getRelaysFromList($userInboxRelaySelections),
}) })
} }
}, },
+5 -13
View File
@@ -1,15 +1,7 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {derived} from "svelte/store" import {pubkey, relaySelections, inboxRelaySelections, derivePubkeyRelays} from "@welshman/app"
import { import {RelayMode} from "@welshman/util"
getRelayUrls,
userRelaySelections,
userInboxRelaySelections,
getReadRelayUrls,
getWriteRelayUrls,
relaySelections,
inboxRelaySelections,
} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte" import Icon from "@lib/components/Icon.svelte"
import Button from "@lib/components/Button.svelte" import Button from "@lib/components/Button.svelte"
import Collapse from "@lib/components/Collapse.svelte" import Collapse from "@lib/components/Collapse.svelte"
@@ -19,9 +11,9 @@
import {discoverRelays} from "@app/requests" import {discoverRelays} from "@app/requests"
import {setRelayPolicy, setInboxRelayPolicy} from "@app/commands" import {setRelayPolicy, setInboxRelayPolicy} from "@app/commands"
const readRelayUrls = derived(userRelaySelections, getReadRelayUrls) const readRelayUrls = derivePubkeyRelays($pubkey!, RelayMode.Read)
const writeRelayUrls = derived(userRelaySelections, getWriteRelayUrls) const writeRelayUrls = derivePubkeyRelays($pubkey!, RelayMode.Write)
const inboxRelayUrls = derived(userInboxRelaySelections, getRelayUrls) const inboxRelayUrls = derivePubkeyRelays($pubkey!, RelayMode.Inbox)
const addReadRelay = () => const addReadRelay = () =>
pushModal(RelayAdd, { pushModal(RelayAdd, {