fix: include MESSAGE kind and local matches in space search

This commit is contained in:
Jon Staab
2026-04-28 14:29:33 -07:00
parent 99b26680b6
commit 976ccdabd4
+16 -7
View File
@@ -2,9 +2,10 @@
import {tick} from "svelte" import {tick} from "svelte"
import {debounce} from "throttle-debounce" import {debounce} from "throttle-debounce"
import {request} from "@welshman/net" import {request} from "@welshman/net"
import {formatTimestampAsDate, groupBy, now, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib" import {repository, tracker} from "@welshman/app"
import {formatTimestampAsDate, groupBy, uniqBy, now, MINUTE, HOUR, DAY, WEEK} from "@welshman/lib"
import type {TrustedEvent, Filter} from "@welshman/util" import type {TrustedEvent, Filter} from "@welshman/util"
import {sortEventsDesc} from "@welshman/util" import {MESSAGE, sortEventsDesc} from "@welshman/util"
import CloseCircle from "@assets/icons/close-circle.svg?dataurl" import CloseCircle from "@assets/icons/close-circle.svg?dataurl"
import Magnifier from "@assets/icons/magnifier.svg?dataurl" import Magnifier from "@assets/icons/magnifier.svg?dataurl"
import {fly} from "@lib/transition" import {fly} from "@lib/transition"
@@ -53,8 +54,11 @@
const getFilter = (searchTerm: string): Filter => const getFilter = (searchTerm: string): Filter =>
h h
? {kinds: CONTENT_KINDS, "#h": [h], search: searchTerm} ? {kinds: [MESSAGE, ...CONTENT_KINDS], "#h": [h], search: searchTerm}
: {kinds: CONTENT_KINDS, search: searchTerm} : {kinds: [MESSAGE, ...CONTENT_KINDS], search: searchTerm}
const getLocalResults = (filter: Filter) =>
repository.query([filter]).filter(event => tracker.getRelays(event.id).has(url))
const search = debounce(300, async (searchTerm: string) => { const search = debounce(300, async (searchTerm: string) => {
controller?.abort() controller?.abort()
@@ -68,18 +72,23 @@
controller = new AbortController() controller = new AbortController()
loading = true loading = true
const filter = getFilter(searchTerm.trim())
const localResults = getLocalResults(filter)
results = sortEventsDesc(localResults)
try { try {
const events = await request({ const events = await request({
relays: getRelayUrls(), relays: getRelayUrls(),
autoClose: true, autoClose: true,
signal: controller.signal, signal: controller.signal,
filters: [getFilter(searchTerm.trim())], filters: [filter],
}) })
results = sortEventsDesc(events) results = sortEventsDesc(uniqBy((e: TrustedEvent) => e.id, [...events, ...localResults]))
} catch (error) { } catch (error) {
if (!(error instanceof DOMException && error.name === "AbortError")) { if (!(error instanceof DOMException && error.name === "AbortError")) {
results = [] results = sortEventsDesc(localResults)
} }
} finally { } finally {
loading = false loading = false