From 540ba10654626d89201ee5a8fc1fd18d1a8d7166 Mon Sep 17 00:00:00 2001 From: dtonon Date: Wed, 10 Jun 2026 18:48:02 +0100 Subject: [PATCH] Scope search by group client-side, pyramid rejects search + #h --- src/lib/search.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/lib/search.ts b/src/lib/search.ts index e32aa07..7d22e01 100644 --- a/src/lib/search.ts +++ b/src/lib/search.ts @@ -19,14 +19,21 @@ function snippetOf(content: string): string { // NIP-50 search over the forum relay: thread OPs (kind 11) and replies // (kind 1111), deduped by thread. Simple mode scopes to the single group; -// full mode spans every visible room. +// full mode spans every visible room. The group scope is applied client-side +// on the `h` tag: pyramid returns nothing when `search` is combined with a +// `#h` filter. export async function searchThreads(query: string): Promise { const filter: Filter = { kinds: [11, 1111], search: query, limit: 30 }; - if (MODE === "simple") filter["#h"] = [GROUP_ID]; - else if (groupsStore.list.length > 0) - filter["#h"] = groupsStore.list.map((g) => g.id); + const groups = + MODE === "simple" + ? new Set([GROUP_ID]) + : new Set(groupsStore.list.map((g) => g.id)); - const events = await queryForum(filter, { label: "search" }); + const all = await queryForum(filter, { label: "search" }); + const events = all.filter((e) => { + const h = e.tags.find((t) => t[0] === "h")?.[1]; + return h !== undefined && (groups.size === 0 || groups.has(h)); + }); const byThread = new Map(); const opless: SearchResult[] = [];