mirror of
https://github.com/layer-systems/website.git
synced 2026-09-12 13:43:01 +02:00
Fix search profile lookup review feedback
Co-authored-by: mroxso <24775431+mroxso@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
533fc6cb22
commit
e8f2de3f0b
@@ -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) };
|
||||
}
|
||||
|
||||
|
||||
@@ -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' });
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user