From 7b2c4626ae67f9d337d285bdd9170f511a9c14aa Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 13:14:03 -0700 Subject: People search looks among the people you follow first. "derek ross leaked his key and started a new npub. i tried searching him up and found this … it says no posts" … "Did we get our search to bring up his new account … as the top result?" (Adam, 2026-11-17). Search for "derek ross" came up with an empty impostor key: Primal's user search (our main source) doesn't index his new key yet and ranks by its own trust score, and only one NIP-50 relay has it, 34th. Adam already follows the new key. Now a follow whose name or NIP-05 matches the query ranks with coinos usernames, above the indexes; the chat feature hands its follow list and the profiles it holds to the search, and fetches follows' profiles it has never seen once a session, the first time a search asks. Rows found while those are still loading aren't cached, so the next search sees them; older cached results are dropped (search cache v3). New search-follows-test (follow first, impostor still listed after, renamed old key not matched, NIP-05 match, partial answers not cached) passes, with search-scope, search-avatar-loading and features-smoke. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- src/recipient-search.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/recipient-search.js') diff --git a/src/recipient-search.js b/src/recipient-search.js index 4853c66..285221c 100644 --- a/src/recipient-search.js +++ b/src/recipient-search.js @@ -114,7 +114,8 @@ export function warmSearch() { // Profiles cap at 200 by recency; whole-query results keep for 12 hours. const PROF_KEY = 'btc-wallet-search-profiles'; // Discard old results that identified migrated accounts by their wallet key. -const QUERY_KEY = 'btc-wallet-search-queries-v2'; +// v3: results from before the people-you-follow source came in +const QUERY_KEY = 'btc-wallet-search-queries-v3'; const QUERY_TTL = 12 * 3600_000; const profileCache = new Map(); // pk -> { name, picture } const queryCache = new Map(); // q -> rows @@ -150,6 +151,15 @@ function persistCaches() { }, 800); } +// The people this account follows, as the chat feature knows them +// ([{ pk, name, nip05, picture }], profiles it already holds). A match among +// them outranks the search indexes: Primal ranks by its own trust score and +// doesn't index a brand-new key for a while, so someone you follow who just +// moved to a new npub (Derek Ross, 2026-11-17: an empty impostor came up +// instead) is found where you'd look first. +let localPeople = null; +export function setLocalPeople(fn) { localPeople = fn; } + // Worth searching? A partial username or npub — never an address, invoice, // or key the Send form knows how to handle whole. Known payment prefixes are // excluded so typing an address never triggers a search. @@ -214,6 +224,19 @@ export async function searchRecipients(qRaw, onPartial = null) { const exact = parseNostrPubkey(q); if (exact) { add(exact, {}, 0); emit(); } + let partial = false; // follows' names still loading: don't keep these rows + if (!exact && localPeople) { + const joined = q.replace(/ /g, ''); + const hit = (v) => { const x = String(v || '').toLowerCase().replace(/\s+/g, ' '); return x.includes(q) || (joined !== q && x.replace(/ /g, '').includes(joined)); }; + let people = []; + try { people = localPeople() || []; } catch {} + if (people.partial) partial = true; + for (const p of people) { + const nip05 = typeof p.nip05 === 'string' ? p.nip05.replace(/^_@/, '') : undefined; + if (hit(p.name) || hit(nip05)) add(p.pk, { name: p.name, picture: p.picture, nip05 }, 1); + } + emit(); + } await Promise.allSettled([ fetch(`${REGISTRAR}/search?q=${encodeURIComponent(q)}`) @@ -243,6 +266,7 @@ export async function searchRecipients(qRaw, onPartial = null) { const rows = snapshot(); await fillProfiles(rows).catch(() => {}); for (const r of rows) r.known = true; // looked: no picture now means none + if (partial) return rows; if (queryCache.size > 200) { queryCache.clear(); queryAt.clear(); } queryCache.set(q, rows); queryAt.set(q, Date.now()); -- cgit v1.2.3