aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-17 13:14:03 -0700
committerAdam Soltys <[email protected]>2026-11-17 13:14:03 -0700
commit7b2c4626ae67f9d337d285bdd9170f511a9c14aa (patch)
tree7f8cf107c23d63b01b49f8f76629bb2307d224b4
parent550776ed795f1da392ea39a7de5850630f02b16f (diff)
downloadcoinosv3-7b2c4626ae67f9d337d285bdd9170f511a9c14aa.tar.gz
coinosv3-7b2c4626ae67f9d337d285bdd9170f511a9c14aa.zip
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.
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ
-rw-r--r--src/features/messages.js26
-rw-r--r--src/recipient-search.js26
-rw-r--r--tools/search-follows-test.js53
3 files changed, 103 insertions, 2 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index d5d286a..95fcde8 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -39,7 +39,7 @@ import { createThreadPrefetch } from '../thread-prefetch.js';
import { makeImageThumbnails } from '../image-thumbnails.js';
import { createFeedCache, FEED_CACHE_POSTS, FEED_SEED_POSTS } from '../feed-cache.js';
import { POPULAR_RELAYS, FIREHOSE_RELAYS, popularCandidates } from '../popular-feed.js';
-import { makeSearcher, resultRows, fallbackAvatar, warmSearch, punkImageUrl, punkSmallUrl, primalCache, searchRecipients, searchable } from '../recipient-search.js';
+import { makeSearcher, resultRows, fallbackAvatar, warmSearch, punkImageUrl, punkSmallUrl, primalCache, searchRecipients, searchable, setLocalPeople } from '../recipient-search.js';
import { getNetwork } from '../api.js';
import { decodeBolt11 } from '../ark/lightning.js';
import { hexToBytes, bytesToHex } from '@noble/hashes/utils';
@@ -17186,6 +17186,30 @@ export function messagesFeature(ctx) {
e.id && !e.isNew ? h('button', { class: 'btn-ghost btn-block', onClick: () => deleteFeed(e.id) }, t('feedDelete')) : null);
}
+ // People search looks among your follows first (recipient-search.js). Their
+ // names come from the profiles this device holds; the ones it has never
+ // seen are fetched once a session, the first time a search asks.
+ let followFacesAsked = false, followFacesPending = false;
+ setLocalPeople(() => {
+ const set = follows && follows.set;
+ if (!set || !set.size) return [];
+ if (!followFacesAsked) {
+ followFacesAsked = true;
+ const missing = [...set].filter((pk) => !profiles.get(pk)?.name && !profInFlight.has(pk));
+ if (missing.length) {
+ followFacesPending = true;
+ fetchProfiles(missing.slice(0, 2000)).catch(() => {}).finally(() => { followFacesPending = false; });
+ }
+ }
+ const out = [];
+ out.partial = followFacesPending;
+ for (const pk of set) {
+ const p = profiles.get(pk);
+ if (p && (p.name || p.nip05)) out.push({ pk, name: p.name, nip05: p.nip05, picture: p.picture });
+ }
+ return out;
+ });
+
// ---- user search: the header magnifier ----------------------------------
// Same engine the Send form and DMs use (registrar names + Primal cache +
// NIP-50 relays); tapping a result opens their profile, and profile-Back
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());
diff --git a/tools/search-follows-test.js b/tools/search-follows-test.js
new file mode 100644
index 0000000..c0d8673
--- /dev/null
+++ b/tools/search-follows-test.js
@@ -0,0 +1,53 @@
+// People search finds the people you follow first (Adam, 2026-11-17: Derek
+// Ross moved to a new npub after his key leaked; searching "derek ross" came
+// up with an empty impostor, because Primal doesn't index the new key yet
+// and ranks by its own trust score). A follow whose name or NIP-05 matches
+// outranks the search indexes; while follows' names are still loading, the
+// answer isn't cached. Run: bun tools/search-follows-test.js
+globalThis.localStorage = { getItem: () => null, setItem() {}, removeItem() {} };
+const NEW = '6e479b7a5671f58a7a5d04ecedb00c1345b8918a8f8e270dc807ddb2818dba28';
+const OLD = '3f770d65d3a764a9c5cb503ae123e62ec7598ad035d836e2a810f3877a745b24';
+const FAKE = '1419ab45e0bdf22b51aeb0ddf2435b568e530b8ecf6f6f82172b181302f076ee';
+// Primal's answer for "derekross": the impostor first
+class FakeWS {
+ constructor() { this.readyState = 0; setTimeout(() => { this.readyState = 1; this._open?.(); }, 5); }
+ addEventListener(t, f) { if (t === 'open') this._open = f; }
+ send(raw) {
+ const [, sid, { cache: [, args] }] = JSON.parse(raw);
+ const evs = args.query === 'derekross' ? [{ kind: 0, pubkey: FAKE, content: JSON.stringify({ name: 'Derek Ross' }) }] : [];
+ setTimeout(() => { for (const e of evs) this.onmessage({ data: JSON.stringify(['EVENT', sid, e]) }); this.onmessage({ data: JSON.stringify(['EOSE', sid]) }); }, 5);
+ }
+ close() {}
+}
+globalThis.WebSocket = FakeWS;
+globalThis.fetch = async () => ({ json: async () => ({ results: [] }) });
+const { searchRecipients, setLocalPeople } = await import('../src/recipient-search.js');
+
+let fails = 0;
+const check = (name, ok, extra = '') => { console.log(`${ok ? ' ✓' : ' ✗'} ${name}${extra ? ' — ' + extra : ''}`); if (!ok) fails++; };
+
+let partial = true;
+setLocalPeople(() => {
+ const out = [
+ { pk: NEW, name: 'Derek Ross', nip05: '[email protected]' },
+ { pk: OLD, name: 'nobody' },
+ { pk: 'a'.repeat(64), name: 'Someone Else' },
+ ];
+ out.partial = partial;
+ return out;
+});
+let rows = await searchRecipients('derek ross');
+check('a follow named Derek Ross comes first', rows[0]?.pk === NEW, rows.map((r) => r.pk.slice(0, 8)).join(','));
+check('the index result still listed after it', rows.some((r) => r.pk === FAKE));
+check('the renamed old key is not a match', !rows.some((r) => r.pk === OLD));
+partial = false;
+setLocalPeople(() => [{ pk: NEW, name: 'Derek Ross (new)', nip05: '[email protected]' }]);
+rows = await searchRecipients('derek ross');
+check('a partial answer was not cached (asks again)', rows[0]?.name === 'Derek Ross (new)', rows[0]?.name);
+rows = await searchRecipients('derekross.me');
+check('NIP-05 matches too', rows[0]?.pk === NEW);
+setLocalPeople(() => []);
+rows = await searchRecipients('derek ross');
+check('a complete answer is cached', rows[0]?.pk === NEW);
+console.log(fails ? 'FAIL' : 'PASS');
+process.exit(fails ? 1 : 0);