Scope search by group client-side, pyramid rejects search + #h

This commit is contained in:
dtonon 2026-06-10 18:48:02 +01:00
parent a77b8a29c3
commit 540ba10654

View file

@ -19,14 +19,21 @@ function snippetOf(content: string): string {
// NIP-50 search over the forum relay: thread OPs (kind 11) and replies // 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; // (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<SearchResult[]> { export async function searchThreads(query: string): Promise<SearchResult[]> {
const filter: Filter = { kinds: [11, 1111], search: query, limit: 30 }; const filter: Filter = { kinds: [11, 1111], search: query, limit: 30 };
if (MODE === "simple") filter["#h"] = [GROUP_ID]; const groups =
else if (groupsStore.list.length > 0) MODE === "simple"
filter["#h"] = groupsStore.list.map((g) => g.id); ? 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<string, SearchResult>(); const byThread = new Map<string, SearchResult>();
const opless: SearchResult[] = []; const opless: SearchResult[] = [];