Compare commits

...

1 Commits

Author SHA1 Message Date
Jon Staab 949a7a7618 fix: include MESSAGE kind and local matches in space search 2026-04-30 17:34:12 +05:30
2 changed files with 36 additions and 7 deletions
+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
+20
View File
@@ -147,6 +147,7 @@ import {
makeUserData, makeUserData,
makeUserLoader, makeUserLoader,
manageRelay, manageRelay,
deriveProfile,
displayProfileByPubkey, displayProfileByPubkey,
getProfile, getProfile,
} from "@welshman/app" } from "@welshman/app"
@@ -155,6 +156,25 @@ import {readFeed} from "@lib/feeds"
export const fromCsv = (s: string) => (s || "").split(",").filter(identity) export const fromCsv = (s: string) => (s || "").split(",").filter(identity)
const profileStoreCache = new Map<string, ReturnType<typeof deriveProfile>>()
export const deriveDedupedProfile = (
...args: Parameters<typeof deriveProfile>
): ReturnType<typeof deriveProfile> => {
const key = JSON.stringify(args)
const cached = profileStoreCache.get(key)
if (cached) {
return cached
}
const store = deriveProfile(...args)
profileStoreCache.set(key, store)
return store
}
export const ROOM = "h" export const ROOM = "h"
export const PROTECTED = ["-"] export const PROTECTED = ["-"]