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) {