Switch to new relays store

This commit is contained in:
Jon Staab
2025-10-24 09:38:57 -07:00
parent e163286dd4
commit 3dff1fcb4d
11 changed files with 53 additions and 45 deletions
+2 -3
View File
@@ -61,7 +61,6 @@
const userRooms = deriveUserRooms(url) const userRooms = deriveUserRooms(url)
const otherRooms = deriveOtherRooms(url) const otherRooms = deriveOtherRooms(url)
const members = deriveSpaceMembers(url) const members = deriveSpaceMembers(url)
const owner = $derived($relay?.profile?.pubkey)
const hasAlerts = $derived($alerts.some(a => getTagValue("feed", a.tags)?.includes(url))) const hasAlerts = $derived($alerts.some(a => getTagValue("feed", a.tags)?.includes(url)))
const spaceKinds = derived( const spaceKinds = derived(
@@ -149,9 +148,9 @@
View Members ({$members.length}) View Members ({$members.length})
</Button> </Button>
</li> </li>
{#if owner} {#if $relay?.pubkey}
<li> <li>
<Link href={makeChatPath([owner])}> <Link href={makeChatPath([$relay.pubkey])}>
<Icon icon={Letter} /> <Icon icon={Letter} />
Contact Owner Contact Owner
</Link> </Link>
+2 -2
View File
@@ -6,6 +6,6 @@
const relay = deriveRelay(props.url) const relay = deriveRelay(props.url)
</script> </script>
{#if $relay?.profile?.description} {#if $relay?.description}
<p class={props.class}>{$relay?.profile.description}</p> <p class={props.class}>{$relay.description}</p>
{/if} {/if}
+11 -11
View File
@@ -4,13 +4,13 @@
import Link from "@lib/components/Link.svelte" import Link from "@lib/components/Link.svelte"
import {displayUrl} from "@welshman/lib" import {displayUrl} from "@welshman/lib"
import {displayRelayUrl} from "@welshman/util" import {displayRelayUrl} from "@welshman/util"
import {deriveRelay} from "@welshman/app" import {deriveRelay, deriveRelayStats} from "@welshman/app"
const {url, children} = $props() const {url, children} = $props()
const relay = deriveRelay(url) const relay = deriveRelay(url)
const relayStats = deriveRelayStats(url)
const connections = $derived($relay?.stats?.open_count || 0) const connections = $derived($relayStats?.open_count || 0)
</script> </script>
<div class="card2 card2-sm bg-alt column gap-2"> <div class="card2 card2-sm bg-alt column gap-2">
@@ -21,20 +21,20 @@
</div> </div>
{@render children?.()} {@render children?.()}
</div> </div>
{#if $relay?.profile?.description} {#if $relay?.description}
<p class="ellipsize">{$relay?.profile.description}</p> <p class="ellipsize">{$relay.description}</p>
{/if} {/if}
<span class="flex items-center gap-1 whitespace-nowrap text-sm"> <span class="flex items-center gap-1 whitespace-nowrap text-sm">
{#if $relay?.profile?.contact} {#if $relay?.contact}
<Link external class="ellipsize underline" href={$relay.profile.contact} <Link external class="ellipsize underline" href={$relay.contact}
>{displayUrl($relay.profile.contact)}</Link> >{displayUrl($relay.contact)}</Link>
&bull; &bull;
{/if} {/if}
{#if Array.isArray($relay?.profile?.supported_nips)} {#if Array.isArray($relay?.supported_nips)}
<span <span
class="tooltip cursor-pointer underline" class="tooltip cursor-pointer underline"
data-tip="NIPs supported: {$relay.profile.supported_nips.join(', ')}"> data-tip="NIPs supported: {$relay.supported_nips.join(', ')}">
{$relay.profile.supported_nips.length} NIPs {$relay.supported_nips.length} NIPs
</span> </span>
&bull; &bull;
{/if} {/if}
+2 -2
View File
@@ -25,8 +25,8 @@
<div class="avatar relative"> <div class="avatar relative">
<div <div
class="center !flex h-12 w-12 min-w-12 rounded-full border-2 border-solid border-base-300 bg-base-300"> class="center !flex h-12 w-12 min-w-12 rounded-full border-2 border-solid border-base-300 bg-base-300">
{#if $relay?.profile?.icon} {#if $relay?.icon}
<img alt="" src={$relay.profile.icon} /> <img alt="" src={$relay.icon} />
{:else} {:else}
<Icon icon={Ghost} size={5} /> <Icon icon={Ghost} size={5} />
{/if} {/if}
+1 -1
View File
@@ -17,4 +17,4 @@
icon={RemoteControllerMinimalistic} icon={RemoteControllerMinimalistic}
class="!h-10 !w-10" class="!h-10 !w-10"
alt={displayRelayUrl(url)} alt={displayRelayUrl(url)}
src={$relay?.profile?.icon} /> src={$relay?.icon} />
+8 -8
View File
@@ -19,7 +19,7 @@
const {url}: Props = $props() const {url}: Props = $props()
const relay = deriveRelay(url) const relay = deriveRelay(url)
const owner = $derived($relay?.profile?.pubkey) const owner = $derived($relay?.pubkey)
const back = () => history.back() const back = () => history.back()
</script> </script>
@@ -30,8 +30,8 @@
<div class="avatar relative"> <div class="avatar relative">
<div <div
class="center !flex h-16 w-16 min-w-16 rounded-full border-2 border-solid border-base-300 bg-base-300"> class="center !flex h-16 w-16 min-w-16 rounded-full border-2 border-solid border-base-300 bg-base-300">
{#if $relay?.profile?.icon} {#if $relay?.icon}
<img alt="" src={$relay.profile.icon} /> <img alt="" src={$relay.icon} />
{:else} {:else}
<Icon icon={Ghost} size={6} /> <Icon icon={Ghost} size={6} />
{/if} {/if}
@@ -46,16 +46,16 @@
</div> </div>
</div> </div>
<RelayDescription {url} /> <RelayDescription {url} />
{#if $relay?.profile?.terms_of_service || $relay?.profile?.privacy_policy} {#if $relay?.terms_of_service || $relay?.privacy_policy}
<div class="flex gap-3"> <div class="flex gap-3">
{#if $relay.profile.terms_of_service} {#if $relay.terms_of_service}
<Link href={$relay.profile.terms_of_service} class="badge badge-neutral flex gap-2"> <Link href={$relay.terms_of_service} class="badge badge-neutral flex gap-2">
<Icon icon={BillList} size={4} /> <Icon icon={BillList} size={4} />
Terms of Service Terms of Service
</Link> </Link>
{/if} {/if}
{#if $relay.profile.privacy_policy} {#if $relay.privacy_policy}
<Link href={$relay?.profile?.privacy_policy} class="badge badge-neutral flex gap-2"> <Link href={$relay.privacy_policy} class="badge badge-neutral flex gap-2">
<Icon icon={ShieldUser} size={4} /> <Icon icon={ShieldUser} size={4} />
Privacy Policy Privacy Policy
</Link> </Link>
+6 -7
View File
@@ -12,7 +12,6 @@
const {url}: Props = $props() const {url}: Props = $props()
const relay = deriveRelay(url) const relay = deriveRelay(url)
const owner = $derived($relay?.profile?.pubkey)
</script> </script>
<div class="card2 bg-alt flex flex-col gap-4"> <div class="card2 bg-alt flex flex-col gap-4">
@@ -23,17 +22,17 @@
</h3> </h3>
<SocketStatusIndicator {url} /> <SocketStatusIndicator {url} />
</div> </div>
{#if $relay?.profile} {#if $relay}
{@const {software, version, supported_nips, limitation} = $relay.profile} {@const {pubkey, software, version, supported_nips, limitation} = $relay}
<div class="flex flex-wrap gap-1"> <div class="flex flex-wrap gap-1">
{#if owner} {#if pubkey}
<div class="badge badge-neutral"> <div class="badge badge-neutral">
<span class="ellipsize">Administrator: <ProfileLink unstyled pubkey={owner} /></span> <span class="ellipsize">Administrator: <ProfileLink unstyled {pubkey} /></span>
</div> </div>
{/if} {/if}
{#if $relay?.profile?.contact} {#if $relay?.contact}
<div class="badge badge-neutral"> <div class="badge badge-neutral">
<span class="ellipsize">Contact: {$relay.profile.contact}</span> <span class="ellipsize">Contact: {$relay.contact}</span>
</div> </div>
{/if} {/if}
{#if software} {#if software}
+1 -1
View File
@@ -294,7 +294,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
export const checkRelayProfile = async (url: string) => { export const checkRelayProfile = async (url: string) => {
const relay = await loadRelay(url) const relay = await loadRelay(url)
if (!relay?.profile) { if (!relay) {
return "Sorry, we weren't able to find that relay." return "Sorry, we weren't able to find that relay."
} }
} }
+5 -5
View File
@@ -96,7 +96,7 @@ import {
RelayMode, RelayMode,
verifyEvent, verifyEvent,
} from "@welshman/util" } from "@welshman/util"
import type {TrustedEvent, PublishedList, List, Filter} from "@welshman/util" import type {TrustedEvent, RelayProfile, PublishedList, List, Filter} from "@welshman/util"
import {decrypt} from "@welshman/signer" import {decrypt} from "@welshman/signer"
import {routerContext, Router} from "@welshman/router" import {routerContext, Router} from "@welshman/router"
import { import {
@@ -121,7 +121,7 @@ import {
makeUserData, makeUserData,
makeUserLoader, makeUserLoader,
} from "@welshman/app" } from "@welshman/app"
import type {Thunk, Relay} from "@welshman/app" import type {Thunk} from "@welshman/app"
export const fromCsv = (s: string) => (s || "").split(",").filter(identity) export const fromCsv = (s: string) => (s || "").split(",").filter(identity)
@@ -279,7 +279,7 @@ export const deriveEventsForUrl = (url: string, filters: Filter[]) =>
export const deriveSignedEventsForUrl = (url: string, filters: Filter[]) => export const deriveSignedEventsForUrl = (url: string, filters: Filter[]) =>
derived([deriveEventsForUrl(url, filters), deriveRelay(url)], ([$events, $relay]) => derived([deriveEventsForUrl(url, filters), deriveRelay(url)], ([$events, $relay]) =>
$relay?.profile ? $events.filter(spec({pubkey: $relay.profile.self})) : [], $relay?.self ? $events.filter(spec({pubkey: $relay.self})) : [],
) )
// Context // Context
@@ -556,8 +556,8 @@ export const makeChannelId = (url: string, room: string) => `${url}'${room}`
export const splitChannelId = (id: string) => id.split("'") export const splitChannelId = (id: string) => id.split("'")
export const hasNip29 = (relay?: Relay) => export const hasNip29 = (relay?: RelayProfile) =>
relay?.profile?.supported_nips?.map?.(String)?.includes?.("29") relay?.supported_nips?.map?.(String)?.includes?.("29")
export const channelEvents = deriveEvents(repository, {filters: [{kinds: [ROOM_META]}]}) export const channelEvents = deriveEvents(repository, {filters: [{kinds: [ROOM_META]}]})
+13 -3
View File
@@ -21,13 +21,14 @@ import {
DIRECT_MESSAGE_FILE, DIRECT_MESSAGE_FILE,
verifiedSymbol, verifiedSymbol,
} from "@welshman/util" } from "@welshman/util"
import type {Zapper, TrustedEvent} from "@welshman/util" import type {Zapper, TrustedEvent, RelayProfile} from "@welshman/util"
import type {RepositoryUpdate, WrapItem} from "@welshman/net" import type {RepositoryUpdate, WrapItem} from "@welshman/net"
import type {Handle, Relay} from "@welshman/app" import type {Handle, RelayStats} from "@welshman/app"
import { import {
plaintext, plaintext,
tracker, tracker,
relays, relays,
relayStats,
repository, repository,
handles, handles,
zappers, zappers,
@@ -157,13 +158,21 @@ const syncTracker = async () => {
} }
const syncRelays = async () => { const syncRelays = async () => {
const collection = new Collection<Relay>({table: "relays", getId: prop("url")}) const collection = new Collection<RelayProfile>({table: "relays", getId: prop("url")})
relays.set(await collection.get()) relays.set(await collection.get())
return throttled(3000, relays).subscribe(collection.set) return throttled(3000, relays).subscribe(collection.set)
} }
const syncRelayStats = async () => {
const collection = new Collection<RelayStats>({table: "relayStats", getId: prop("url")})
relayStats.set(await collection.get())
return throttled(3000, relayStats).subscribe(collection.set)
}
const syncHandles = async () => { const syncHandles = async () => {
const collection = new Collection<Handle>({table: "handles", getId: prop("nip05")}) const collection = new Collection<Handle>({table: "handles", getId: prop("nip05")})
@@ -233,6 +242,7 @@ export const syncDataStores = async () => {
syncEvents(), syncEvents(),
syncTracker(), syncTracker(),
syncRelays(), syncRelays(),
syncRelayStats(),
syncHandles(), syncHandles(),
syncZappers(), syncZappers(),
syncFreshness(), syncFreshness(),
+2 -2
View File
@@ -2,10 +2,10 @@
import {onMount} from "svelte" import {onMount} from "svelte"
import {debounce} from "throttle-debounce" import {debounce} from "throttle-debounce"
import {dec, tryCatch} from "@welshman/lib" import {dec, tryCatch} from "@welshman/lib"
import type {RelayProfile} from "@welshman/util"
import {ROOMS, normalizeRelayUrl, isRelayUrl} from "@welshman/util" import {ROOMS, normalizeRelayUrl, isRelayUrl} from "@welshman/util"
import {Router} from "@welshman/router" import {Router} from "@welshman/router"
import {load} from "@welshman/net" import {load} from "@welshman/net"
import type {Relay} from "@welshman/app"
import {relays, createSearch, loadRelay} from "@welshman/app" import {relays, createSearch, loadRelay} from "@welshman/app"
import {createScroller} from "@lib/html" import {createScroller} from "@lib/html"
import {fly} from "@lib/transition" import {fly} from "@lib/transition"
@@ -62,7 +62,7 @@
createSearch( createSearch(
$relays.filter(r => $groupSelectionsPubkeysByUrl.has(r.url) && r.url !== termUrl), $relays.filter(r => $groupSelectionsPubkeysByUrl.has(r.url) && r.url !== termUrl),
{ {
getValue: (relay: Relay) => relay.url, getValue: (relay: RelayProfile) => relay.url,
sortFn: ({score, item}) => { sortFn: ({score, item}) => {
if (score && score > 0.1) return -score! if (score && score > 0.1) return -score!