From e8f2de3f0baa06e67f4a1b7bbcf4c90c2cbf0dab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 6 Sep 2026 20:58:23 +0000 Subject: [PATCH] Fix search profile lookup review feedback Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com> --- src/apps/search/index.tsx | 20 ++++++++++++++++---- src/apps/search/searchUtils.test.ts | 6 ++++++ src/apps/search/searchUtils.ts | 4 ++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/apps/search/index.tsx b/src/apps/search/index.tsx index 4c8363b..745e8bc 100644 --- a/src/apps/search/index.tsx +++ b/src/apps/search/index.tsx @@ -25,9 +25,9 @@ interface SearchResults { function profileMatches(event: NostrEvent, term: string): boolean { try { const metadata = JSON.parse(event.content) as NostrMetadata; - const query = term.toLocaleLowerCase(); + const query = term.toLowerCase(); return [metadata.name, metadata.display_name, metadata.nip05] - .some((value) => value?.toLocaleLowerCase().includes(query)); + .some((value) => value?.toLowerCase()?.includes(query)); } catch { return false; } @@ -42,14 +42,26 @@ function useSearch(input: SearchInput) { queryFn: async ({ signal }) => { const options = { signal: AbortSignal.any([signal, AbortSignal.timeout(6000)]) }; if (input.type === 'profile') { - const events = await nostr.query([{ kinds: [0, 1], authors: [input.pubkey], limit: LIMIT }], options); + const events = await nostr.query( + [ + { kinds: [0], authors: [input.pubkey], limit: LIMIT }, + { kinds: [1], authors: [input.pubkey], limit: LIMIT }, + ], + { ...options, relays: input.relays }, + ); return { notes: events.filter((event) => event.kind === 1), profiles: events.filter((event) => event.kind === 0) }; } if (input.type === 'nip05') { const pointer = await nip05.queryProfile(input.value); if (!pointer || !/^[0-9a-f]{64}$/.test(pointer.pubkey)) return { notes: [], profiles: [] }; - const events = await nostr.query([{ kinds: [0, 1], authors: [pointer.pubkey], limit: LIMIT }], options); + const events = await nostr.query( + [ + { kinds: [0], authors: [pointer.pubkey], limit: LIMIT }, + { kinds: [1], authors: [pointer.pubkey], limit: LIMIT }, + ], + options, + ); return { notes: events.filter((event) => event.kind === 1), profiles: events.filter((event) => event.kind === 0) }; } diff --git a/src/apps/search/searchUtils.test.ts b/src/apps/search/searchUtils.test.ts index 7b14cb6..1f0ed67 100644 --- a/src/apps/search/searchUtils.test.ts +++ b/src/apps/search/searchUtils.test.ts @@ -12,6 +12,12 @@ describe('parseSearchInput', () => { expect(parseSearchInput(nip19.npubEncode(pubkey))).toEqual({ type: 'profile', pubkey }); }); + it('preserves relay hints from nprofiles', () => { + const pubkey = 'f'.repeat(64); + const relays = ['wss://relay.example']; + expect(parseSearchInput(nip19.nprofileEncode({ pubkey, relays }))).toEqual({ type: 'profile', pubkey, relays }); + }); + it('recognizes NIP-05 addresses', () => { expect(parseSearchInput('Alice@Example.com')).toEqual({ type: 'nip05', value: 'alice@example.com' }); }); diff --git a/src/apps/search/searchUtils.ts b/src/apps/search/searchUtils.ts index e2c4aff..1211bf5 100644 --- a/src/apps/search/searchUtils.ts +++ b/src/apps/search/searchUtils.ts @@ -3,7 +3,7 @@ import { nip19 } from 'nostr-tools'; export type SearchInput = | { type: 'empty' } | { type: 'hashtag'; value: string } - | { type: 'profile'; pubkey: string } + | { type: 'profile'; pubkey: string; relays?: string[] } | { type: 'nip05'; value: string } | { type: 'text'; value: string }; @@ -20,7 +20,7 @@ export function parseSearchInput(input: string): SearchInput { try { const decoded = nip19.decode(value); if (decoded.type === 'npub') return { type: 'profile', pubkey: decoded.data }; - if (decoded.type === 'nprofile') return { type: 'profile', pubkey: decoded.data.pubkey }; + if (decoded.type === 'nprofile') return { type: 'profile', pubkey: decoded.data.pubkey, relays: decoded.data.relays }; } catch { // A normal text search need not be a NIP-19 identifier. }