From 77d672b6d17364d1a8933f80c0563d1b5845e685 Mon Sep 17 00:00:00 2001 From: Jure <44338+hoornet@users.noreply.github.com> Date: Mon, 6 Apr 2026 15:05:31 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20duplicate=20people=20in=20search=20result?= =?UTF-8?q?s=20=E2=80=94=20dedup=20by=20pubkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/nostr/search.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/lib/nostr/search.ts b/src/lib/nostr/search.ts index 7ab29f8..010271d 100644 --- a/src/lib/nostr/search.ts +++ b/src/lib/nostr/search.ts @@ -82,7 +82,15 @@ export async function searchUsers(query: string, limit = 20): Promise(); + for (const e of events) { + const existing = byPubkey.get(e.pubkey); + if (!existing || (e.created_at ?? 0) > (existing.created_at ?? 0)) { + byPubkey.set(e.pubkey, e); + } + } + return Array.from(byPubkey.values()); } export async function resolveNip05(identifier: string): Promise { @@ -227,7 +235,17 @@ export async function advancedSearch(parsed: ParsedSearch, limit = 50): Promise< let notes = dedup(noteEvents, hybridNoteEvents); let articles = dedup(articleEvents, hybridArticleEvents); - const users = Array.from(userEvents); + // Deduplicate users by pubkey (kind 0 is replaceable — keep newest per author) + const users = (() => { + const byPubkey = new Map(); + for (const e of userEvents) { + const existing = byPubkey.get(e.pubkey); + if (!existing || (e.created_at ?? 0) > (existing.created_at ?? 0)) { + byPubkey.set(e.pubkey, e); + } + } + return Array.from(byPubkey.values()); + })(); // Client-side author filter — search relays may not intersect authors with search properly if (resolvedAuthors.length > 0) {