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

View File

@@ -61,7 +61,6 @@
const userRooms = deriveUserRooms(url)
const otherRooms = deriveOtherRooms(url)
const members = deriveSpaceMembers(url)
const owner = $derived($relay?.profile?.pubkey)
const hasAlerts = $derived($alerts.some(a => getTagValue("feed", a.tags)?.includes(url)))
const spaceKinds = derived(
@@ -149,9 +148,9 @@
View Members ({$members.length})
</Button>
</li>
{#if owner}
{#if $relay?.pubkey}
<li>
<Link href={makeChatPath([owner])}>
<Link href={makeChatPath([$relay.pubkey])}>
<Icon icon={Letter} />
Contact Owner
</Link>

View File

@@ -6,6 +6,6 @@
const relay = deriveRelay(props.url)
</script>
{#if $relay?.profile?.description}
<p class={props.class}>{$relay?.profile.description}</p>
{#if $relay?.description}
<p class={props.class}>{$relay.description}</p>
{/if}

View File

@@ -4,13 +4,13 @@
import Link from "@lib/components/Link.svelte"
import {displayUrl} from "@welshman/lib"
import {displayRelayUrl} from "@welshman/util"
import {deriveRelay} from "@welshman/app"
import {deriveRelay, deriveRelayStats} from "@welshman/app"
const {url, children} = $props()
const relay = deriveRelay(url)
const connections = $derived($relay?.stats?.open_count || 0)
const relayStats = deriveRelayStats(url)
const connections = $derived($relayStats?.open_count || 0)
</script>
<div class="card2 card2-sm bg-alt column gap-2">
@@ -21,20 +21,20 @@
</div>
{@render children?.()}
</div>
{#if $relay?.profile?.description}
<p class="ellipsize">{$relay?.profile.description}</p>
{#if $relay?.description}
<p class="ellipsize">{$relay.description}</p>
{/if}
<span class="flex items-center gap-1 whitespace-nowrap text-sm">
{#if $relay?.profile?.contact}
<Link external class="ellipsize underline" href={$relay.profile.contact}
>{displayUrl($relay.profile.contact)}</Link>
{#if $relay?.contact}
<Link external class="ellipsize underline" href={$relay.contact}
>{displayUrl($relay.contact)}</Link>
&bull;
{/if}
{#if Array.isArray($relay?.profile?.supported_nips)}
{#if Array.isArray($relay?.supported_nips)}
<span
class="tooltip cursor-pointer underline"
data-tip="NIPs supported: {$relay.profile.supported_nips.join(', ')}">
{$relay.profile.supported_nips.length} NIPs
data-tip="NIPs supported: {$relay.supported_nips.join(', ')}">
{$relay.supported_nips.length} NIPs
</span>
&bull;
{/if}

View File

@@ -25,8 +25,8 @@
<div class="avatar relative">
<div
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}
<img alt="" src={$relay.profile.icon} />
{#if $relay?.icon}
<img alt="" src={$relay.icon} />
{:else}
<Icon icon={Ghost} size={5} />
{/if}

View File

@@ -17,4 +17,4 @@
icon={RemoteControllerMinimalistic}
class="!h-10 !w-10"
alt={displayRelayUrl(url)}
src={$relay?.profile?.icon} />
src={$relay?.icon} />

View File

@@ -19,7 +19,7 @@
const {url}: Props = $props()
const relay = deriveRelay(url)
const owner = $derived($relay?.profile?.pubkey)
const owner = $derived($relay?.pubkey)
const back = () => history.back()
</script>
@@ -30,8 +30,8 @@
<div class="avatar relative">
<div
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}
<img alt="" src={$relay.profile.icon} />
{#if $relay?.icon}
<img alt="" src={$relay.icon} />
{:else}
<Icon icon={Ghost} size={6} />
{/if}
@@ -46,16 +46,16 @@
</div>
</div>
<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">
{#if $relay.profile.terms_of_service}
<Link href={$relay.profile.terms_of_service} class="badge badge-neutral flex gap-2">
{#if $relay.terms_of_service}
<Link href={$relay.terms_of_service} class="badge badge-neutral flex gap-2">
<Icon icon={BillList} size={4} />
Terms of Service
</Link>
{/if}
{#if $relay.profile.privacy_policy}
<Link href={$relay?.profile?.privacy_policy} class="badge badge-neutral flex gap-2">
{#if $relay.privacy_policy}
<Link href={$relay.privacy_policy} class="badge badge-neutral flex gap-2">
<Icon icon={ShieldUser} size={4} />
Privacy Policy
</Link>

View File

@@ -12,7 +12,6 @@
const {url}: Props = $props()
const relay = deriveRelay(url)
const owner = $derived($relay?.profile?.pubkey)
</script>
<div class="card2 bg-alt flex flex-col gap-4">
@@ -23,17 +22,17 @@
</h3>
<SocketStatusIndicator {url} />
</div>
{#if $relay?.profile}
{@const {software, version, supported_nips, limitation} = $relay.profile}
{#if $relay}
{@const {pubkey, software, version, supported_nips, limitation} = $relay}
<div class="flex flex-wrap gap-1">
{#if owner}
{#if pubkey}
<div class="badge badge-neutral">
<span class="ellipsize">Administrator: <ProfileLink unstyled pubkey={owner} /></span>
<span class="ellipsize">Administrator: <ProfileLink unstyled {pubkey} /></span>
</div>
{/if}
{#if $relay?.profile?.contact}
{#if $relay?.contact}
<div class="badge badge-neutral">
<span class="ellipsize">Contact: {$relay.profile.contact}</span>
<span class="ellipsize">Contact: {$relay.contact}</span>
</div>
{/if}
{#if software}

View File

@@ -294,7 +294,7 @@ export const checkRelayAccess = async (url: string, claim = "") => {
export const checkRelayProfile = async (url: string) => {
const relay = await loadRelay(url)
if (!relay?.profile) {
if (!relay) {
return "Sorry, we weren't able to find that relay."
}
}

View File

@@ -96,7 +96,7 @@ import {
RelayMode,
verifyEvent,
} 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 {routerContext, Router} from "@welshman/router"
import {
@@ -121,7 +121,7 @@ import {
makeUserData,
makeUserLoader,
} 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)
@@ -279,7 +279,7 @@ export const deriveEventsForUrl = (url: string, filters: Filter[]) =>
export const deriveSignedEventsForUrl = (url: string, filters: Filter[]) =>
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
@@ -556,8 +556,8 @@ export const makeChannelId = (url: string, room: string) => `${url}'${room}`
export const splitChannelId = (id: string) => id.split("'")
export const hasNip29 = (relay?: Relay) =>
relay?.profile?.supported_nips?.map?.(String)?.includes?.("29")
export const hasNip29 = (relay?: RelayProfile) =>
relay?.supported_nips?.map?.(String)?.includes?.("29")
export const channelEvents = deriveEvents(repository, {filters: [{kinds: [ROOM_META]}]})

View File

@@ -21,13 +21,14 @@ import {
DIRECT_MESSAGE_FILE,
verifiedSymbol,
} 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 {Handle, Relay} from "@welshman/app"
import type {Handle, RelayStats} from "@welshman/app"
import {
plaintext,
tracker,
relays,
relayStats,
repository,
handles,
zappers,
@@ -157,13 +158,21 @@ const syncTracker = 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())
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 collection = new Collection<Handle>({table: "handles", getId: prop("nip05")})
@@ -233,6 +242,7 @@ export const syncDataStores = async () => {
syncEvents(),
syncTracker(),
syncRelays(),
syncRelayStats(),
syncHandles(),
syncZappers(),
syncFreshness(),

View File

@@ -2,10 +2,10 @@
import {onMount} from "svelte"
import {debounce} from "throttle-debounce"
import {dec, tryCatch} from "@welshman/lib"
import type {RelayProfile} from "@welshman/util"
import {ROOMS, normalizeRelayUrl, isRelayUrl} from "@welshman/util"
import {Router} from "@welshman/router"
import {load} from "@welshman/net"
import type {Relay} from "@welshman/app"
import {relays, createSearch, loadRelay} from "@welshman/app"
import {createScroller} from "@lib/html"
import {fly} from "@lib/transition"
@@ -62,7 +62,7 @@
createSearch(
$relays.filter(r => $groupSelectionsPubkeysByUrl.has(r.url) && r.url !== termUrl),
{
getValue: (relay: Relay) => relay.url,
getValue: (relay: RelayProfile) => relay.url,
sortFn: ({score, item}) => {
if (score && score > 0.1) return -score!