diff --git a/src/app/components/MenuSpace.svelte b/src/app/components/MenuSpace.svelte index ab11e2ee..69156390 100644 --- a/src/app/components/MenuSpace.svelte +++ b/src/app/components/MenuSpace.svelte @@ -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}) - {#if owner} + {#if $relay?.pubkey}
  • - + Contact Owner diff --git a/src/app/components/RelayDescription.svelte b/src/app/components/RelayDescription.svelte index e6bc19e1..7e67c7ac 100644 --- a/src/app/components/RelayDescription.svelte +++ b/src/app/components/RelayDescription.svelte @@ -6,6 +6,6 @@ const relay = deriveRelay(props.url) -{#if $relay?.profile?.description} -

    {$relay?.profile.description}

    +{#if $relay?.description} +

    {$relay.description}

    {/if} diff --git a/src/app/components/RelayItem.svelte b/src/app/components/RelayItem.svelte index ed74afa5..4df072d7 100644 --- a/src/app/components/RelayItem.svelte +++ b/src/app/components/RelayItem.svelte @@ -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)
    @@ -21,20 +21,20 @@
    {@render children?.()} - {#if $relay?.profile?.description} -

    {$relay?.profile.description}

    + {#if $relay?.description} +

    {$relay.description}

    {/if} - {#if $relay?.profile?.contact} - {displayUrl($relay.profile.contact)} + {#if $relay?.contact} + {displayUrl($relay.contact)} • {/if} - {#if Array.isArray($relay?.profile?.supported_nips)} + {#if Array.isArray($relay?.supported_nips)} - {$relay.profile.supported_nips.length} NIPs + data-tip="NIPs supported: {$relay.supported_nips.join(', ')}"> + {$relay.supported_nips.length} NIPs • {/if} diff --git a/src/app/components/RelaySummary.svelte b/src/app/components/RelaySummary.svelte index 2a2b3cbf..1c514063 100644 --- a/src/app/components/RelaySummary.svelte +++ b/src/app/components/RelaySummary.svelte @@ -25,8 +25,8 @@
    - {#if $relay?.profile?.icon} - + {#if $relay?.icon} + {:else} {/if} diff --git a/src/app/components/SpaceAvatar.svelte b/src/app/components/SpaceAvatar.svelte index 357a1078..a6d1c3bf 100644 --- a/src/app/components/SpaceAvatar.svelte +++ b/src/app/components/SpaceAvatar.svelte @@ -17,4 +17,4 @@ icon={RemoteControllerMinimalistic} class="!h-10 !w-10" alt={displayRelayUrl(url)} - src={$relay?.profile?.icon} /> + src={$relay?.icon} /> diff --git a/src/app/components/SpaceDetail.svelte b/src/app/components/SpaceDetail.svelte index 53342692..15f52d5e 100644 --- a/src/app/components/SpaceDetail.svelte +++ b/src/app/components/SpaceDetail.svelte @@ -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() @@ -30,8 +30,8 @@
    - {#if $relay?.profile?.icon} - + {#if $relay?.icon} + {:else} {/if} @@ -46,16 +46,16 @@
    - {#if $relay?.profile?.terms_of_service || $relay?.profile?.privacy_policy} + {#if $relay?.terms_of_service || $relay?.privacy_policy}
    - {#if $relay.profile.terms_of_service} - + {#if $relay.terms_of_service} + Terms of Service {/if} - {#if $relay.profile.privacy_policy} - + {#if $relay.privacy_policy} + Privacy Policy diff --git a/src/app/components/SpaceRelayStatus.svelte b/src/app/components/SpaceRelayStatus.svelte index 5636308b..686520ac 100644 --- a/src/app/components/SpaceRelayStatus.svelte +++ b/src/app/components/SpaceRelayStatus.svelte @@ -12,7 +12,6 @@ const {url}: Props = $props() const relay = deriveRelay(url) - const owner = $derived($relay?.profile?.pubkey)
    @@ -23,17 +22,17 @@
    - {#if $relay?.profile} - {@const {software, version, supported_nips, limitation} = $relay.profile} + {#if $relay} + {@const {pubkey, software, version, supported_nips, limitation} = $relay}
    - {#if owner} + {#if pubkey}
    - Administrator: + Administrator:
    {/if} - {#if $relay?.profile?.contact} + {#if $relay?.contact}
    - Contact: {$relay.profile.contact} + Contact: {$relay.contact}
    {/if} {#if software} diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index 35c1296f..82e907a4 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -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." } } diff --git a/src/app/core/state.ts b/src/app/core/state.ts index 7ccaf1ae..11c47686 100644 --- a/src/app/core/state.ts +++ b/src/app/core/state.ts @@ -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]}]}) diff --git a/src/app/util/storage.ts b/src/app/util/storage.ts index 2c34f7ca..a77b7079 100644 --- a/src/app/util/storage.ts +++ b/src/app/util/storage.ts @@ -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({table: "relays", getId: prop("url")}) + const collection = new Collection({table: "relays", getId: prop("url")}) relays.set(await collection.get()) return throttled(3000, relays).subscribe(collection.set) } +const syncRelayStats = async () => { + const collection = new Collection({table: "relayStats", getId: prop("url")}) + + relayStats.set(await collection.get()) + + return throttled(3000, relayStats).subscribe(collection.set) +} + const syncHandles = async () => { const collection = new Collection({table: "handles", getId: prop("nip05")}) @@ -233,6 +242,7 @@ export const syncDataStores = async () => { syncEvents(), syncTracker(), syncRelays(), + syncRelayStats(), syncHandles(), syncZappers(), syncFreshness(), diff --git a/src/routes/discover/+page.svelte b/src/routes/discover/+page.svelte index 34040d2b..a1bfb703 100644 --- a/src/routes/discover/+page.svelte +++ b/src/routes/discover/+page.svelte @@ -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!