From 8990a205d28f9fd4d9747094b9051c361facc1c5 Mon Sep 17 00:00:00 2001 From: Bhavishy Date: Thu, 2 Apr 2026 23:42:48 +0530 Subject: [PATCH] fix: query content kinds via NIP-50 in room and space search --- src/app/components/SpaceSearch.svelte | 71 +++++++-------------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/src/app/components/SpaceSearch.svelte b/src/app/components/SpaceSearch.svelte index f25313fe..687555ad 100644 --- a/src/app/components/SpaceSearch.svelte +++ b/src/app/components/SpaceSearch.svelte @@ -2,16 +2,15 @@ import {tick} from "svelte" import {debounce} from "throttle-debounce" import {request} from "@welshman/net" - import {userSearchRelayList} from "@welshman/app" - import {formatTimestampAsDate, groupBy, now, uniqBy, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib" + import {formatTimestampAsDate, groupBy, now, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib" import type {TrustedEvent, Filter} from "@welshman/util" - import {getRelaysFromList, MESSAGE, sortEventsDesc} from "@welshman/util" + import {sortEventsDesc} from "@welshman/util" import CloseCircle from "@assets/icons/close-circle.svg?dataurl" import Magnifier from "@assets/icons/magnifier.svg?dataurl" import {fly} from "@lib/transition" import Button from "@lib/components/Button.svelte" import Icon from "@lib/components/Icon.svelte" - import {DEFAULT_RELAYS} from "@app/core/state" + import {CONTENT_KINDS} from "@app/core/state" import {goToEvent} from "@app/util/routes" type Props = { @@ -21,9 +20,9 @@ const {url, h}: Props = $props() - type SearchScope = "room" | "space" | "everything" + type SearchScope = "room" | "space" - const scopes: SearchScope[] = h ? ["room", "space", "everything"] : ["space", "everything"] + const scopes: SearchScope[] = h ? ["room", "space"] : ["space"] let term = $state("") let show = $state(false) @@ -31,23 +30,12 @@ let results = $state([]) let loading = $state(false) let input: HTMLInputElement | undefined = $state() - let currentSearchId = 0 let controller: AbortController | undefined - const searchRelayUrls = $derived(getRelaysFromList($userSearchRelayList)) - const effectiveEverythingRelays = $derived( - uniqBy(identity => identity, searchRelayUrls).length > 0 - ? uniqBy(identity => identity, searchRelayUrls) - : DEFAULT_RELAYS, - ) const relayStatus = $derived( scope === "room" ? `Using space relay: ${url} (room filter applied).` - : scope === "space" - ? `Using space relay: ${url}.` - : searchRelayUrls.length > 0 - ? `Using your search relays (${effectiveEverythingRelays.length}).` - : `Using default relays (${effectiveEverythingRelays.length}) because no search relays are configured.`, + : `Using space relay: ${url}.`, ) const open = () => { @@ -68,23 +56,17 @@ controller = undefined } - const getRelayUrls = () => { - if (scope === "everything") { - return effectiveEverythingRelays - } - - return [url] - } + const getRelayUrls = () => [url] const getFilter = (searchTerm: string): Filter => { if (scope === "room" && h) { - return {kinds: [MESSAGE], "#h": [h], search: searchTerm} + return {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm} } - return {kinds: [MESSAGE], search: searchTerm} + return {kinds: CONTENT_KINDS, search: searchTerm} } - const search = debounce(300, async (searchTerm: string, searchId: number) => { + const search = debounce(300, async (searchTerm: string) => { controller?.abort() if (!searchTerm.trim()) { @@ -104,32 +86,23 @@ filters: [getFilter(searchTerm.trim())], }) - if (searchId === currentSearchId) { - results = sortEventsDesc(uniqBy((event: TrustedEvent) => event.id, events)) - } + results = sortEventsDesc(events) } catch (error) { - if ( - !(error instanceof DOMException && error.name === "AbortError") && - searchId === currentSearchId - ) { + if (!(error instanceof DOMException && error.name === "AbortError")) { results = [] } } finally { - if (searchId === currentSearchId) { - loading = false - } + loading = false } }) const onInput = () => { - currentSearchId += 1 - void search(term, currentSearchId) + void search(term) } const setScope = (value: SearchScope) => { scope = value - currentSearchId += 1 - void search(term, currentSearchId) + void search(term) } const eventsByAge = $derived(groupBy(e => getAgeSection(e.created_at), results)) @@ -195,11 +168,7 @@ bind:value={term} class="min-w-0 grow" type="text" - placeholder={scope === "room" - ? "Search this room..." - : scope === "space" - ? "Search this space..." - : "Search everything..."} + placeholder={scope === "room" ? "Search this room..." : "Search this space..."} oninput={onInput} />
@@ -207,7 +176,7 @@ {/each}
@@ -216,10 +185,8 @@ {#if !term}

{scope === "room" - ? "Search for messages in this room." - : scope === "space" - ? "Search for messages in this space." - : "Search across your configured search relays."} + ? "Search for content in this room." + : "Search for content in this space."}

{:else if loading}

Searching...