aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-11-22 12:06:11 -0700
committerAdam Soltys <[email protected]>2026-11-22 12:06:11 -0700
commita1040ecb9908a8290ed9809795b1dc8bdea9ed38 (patch)
tree3cd8a0963822d0c7fe173b63d7987a8d5aef43aa
parent2772773d6d1b214eaf435f56e439ef8ec56b9bed (diff)
downloadcoinosv3-a1040ecb9908a8290ed9809795b1dc8bdea9ed38.tar.gz
coinosv3-a1040ecb9908a8290ed9809795b1dc8bdea9ed38.zip
A name typed after an @ is a mention when it is someone you follow. "I tried to tag PNK in my latest post, but when I click it, it brings me to the search page for PNK rather than to his profile. What's going on there?" (Adam, 2026-11-22). His post (6029d21f) holds the plain text "@pnk": the name was typed out and not picked from the list under the box, so no key went into the text and no p tag onto the post, pnk was never told, and a tap on a bare @name can only open the people search with the name filled in. When exactly one person you follow goes by the name typed, that is now who it means: a post, a scheduled post or a reply being sent gets their nostr:npub in place of the name, so every client shows the mention and their p tag goes on, and a tap on a bare @name in any post opens that person instead of the search. Two follows by the same name, or none, and it stays as typed and the tap searches as before. mention-ac-test posts a followed name typed out in full beside an unknown one and checks the first goes out as the npub; feed-mention-tap-test taps a plain "@poster" (opens the follow) and "@somebody" (still a search); features-smoke passes.
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01VMan6Upic5L6MMJzkTn8zg
-rw-r--r--src/features/messages.js30
-rw-r--r--tools/feed-mention-tap-test.js22
-rw-r--r--tools/mention-ac-test.js5
3 files changed, 54 insertions, 3 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 5ec55c7..0299c5f 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -11468,7 +11468,9 @@ export function messagesFeature(ctx) {
} else if (/^@[A-Za-z0-9_]{2,32}$/.test(part)) {
out.push(h('a', {
href: '#', title: t('searchPeopleFor', { q: part.slice(1) }),
- onClick: (e) => { e.preventDefault(); e.stopPropagation(); openPeopleSearch(part.slice(1)); },
+ // the one person you follow by that name is who it means; anyone
+ // else is a search
+ onClick: (e) => { e.preventDefault(); e.stopPropagation(); const pk = followNamed(part.slice(1)); if (pk) openProfile(pk); else openPeopleSearch(part.slice(1)); },
}, part));
} else if (/^#[A-Za-z0-9_\u00C0-\uFFFF]{2,64}$/.test(part)) {
out.push(h('a', {
@@ -13307,6 +13309,7 @@ export function messagesFeature(ctx) {
}
async function publishPost(text, media = []) {
const id = await requireIdentity();
+ text = linkNamed(text);
const hashtags = postHashtags(text);
const temp = {
id: 'pending:' + Math.random().toString(36).slice(2),
@@ -13352,6 +13355,7 @@ export function messagesFeature(ctx) {
const SCHED_MIN_AHEAD = 120;
async function schedulePost(text, media, at) {
const id = await requireIdentity();
+ text = linkNamed(text);
if (!(at > Math.floor(Date.now() / 1000) + SCHED_MIN_AHEAD)) throw new Error(t('schedTooSoon'));
const partial = { kind: 1, content: text, created_at: at, tags: postTags(text, media, id.pubkey) };
const evt = id.signer instanceof Uint8Array ? finalizeEvent(partial, id.signer) : await id.signer.signEvent(partial);
@@ -13431,6 +13435,7 @@ export function messagesFeature(ctx) {
async function publishReply(c, s, text) {
const id = await requireIdentity();
+ text = linkNamed(text);
const target = c.replies.find((e) => e.id === s.focusId) || c.root || s.seed;
const rootId = c.rootId;
const pTags = [...new Set([
@@ -18081,6 +18086,29 @@ export function messagesFeature(ctx) {
return h('div', { class: 'mention-ac', onMousedown: (e) => e.preventDefault() }, // the box keeps focus and caret
...(hits.length ? resultRows(h, hits, pickMention, (pk, ava) => ava) : []));
}
+ // A name typed out after an @ and never picked from the list ("thanks to
+ // @pnk") went out as plain text: no key, no p tag, and a tap on it could
+ // only search for the name (Adam, 2026-11-22). When exactly one person you
+ // follow goes by that name, that is who it means: the tap opens them, and
+ // a post or reply being sent gets their nostr:npub in its place, so every
+ // client shows the mention and they are told. Two follows by the same
+ // name, or none, and it stays as typed.
+ function followNamed(handle) {
+ const want = String(handle || '').toLowerCase();
+ let hit = null;
+ for (const pk of followsNow().set) {
+ if (isMe(pk) || hiddenPk(pk)) continue;
+ const p = profiles.get(pk);
+ if (!p || !p.name || String(p.name).trim().toLowerCase() !== want) continue;
+ if (hit) return null;
+ hit = pk;
+ }
+ return hit;
+ }
+ const linkNamed = (text) => String(text || '').split(NOTE_SPLIT).map((part) => {
+ const pk = part && /^@[A-Za-z0-9_]{2,32}$/.test(part) ? followNamed(part.slice(1)) : null;
+ return pk ? 'nostr:' + npubOf(pk) : part;
+ }).join('');
// The people a text mentions (nostr:npub / nprofile), for its p tags.
const mentionedPks = (text) => [...new Set([...String(text || '').matchAll(/nostr:((?:npub|nprofile)1[a-z0-9]+)/gi)]
.map((m) => parseNostrRef(m[1].toLowerCase())).filter((r) => r && r.type === 'pubkey').map((r) => r.pk))];
diff --git a/tools/feed-mention-tap-test.js b/tools/feed-mention-tap-test.js
index d381288..fde2ddb 100644
--- a/tools/feed-mention-tap-test.js
+++ b/tools/feed-mention-tap-test.js
@@ -14,6 +14,8 @@ const key = () => { const sk = generateSecretKey(); return { sk, pk: getPublicKe
const AUTHOR = key(), FRIEND = key();
const now = Math.floor(Date.now() / 1000);
const POST = finalizeEvent({ kind: 1, created_at: now - 100, tags: [['p', FRIEND.pk]], content: 'say hello to nostr:' + npubEncode(FRIEND.pk) + ' today' }, AUTHOR.sk);
+// a name typed out as plain text: no key in it, no p tag
+const PLAIN = finalizeEvent({ kind: 1, created_at: now - 50, tags: [], content: 'big thanks to @poster and @somebody for testing' }, FRIEND.sk);
const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 5319, fetch: (req) => { const p = new URL(req.url).pathname; if (p === '/verify-worker.js' || p.startsWith('/punks')) return new Response(Bun.file('dist' + p)); return new Response(html, { headers: { 'content-type': 'text/html' } }); } });
const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
@@ -39,11 +41,11 @@ try {
await waitText('Receive', 20000);
const base = cacheKeyFor(mn + '\n');
await page.evaluate(([k, a, f, ns]) => {
- localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', a]], c: '', at: Math.floor(Date.now() / 1000) }));
+ localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', a], ['p', f]], c: '', at: Math.floor(Date.now() / 1000) }));
localStorage.setItem(k + ':feedNotes', JSON.stringify(ns));
localStorage.setItem(k + ':profiles', JSON.stringify({ [a]: { name: 'Poster', t: Date.now() }, [f]: { name: 'Friendly', t: Date.now() } }));
localStorage.setItem('btc-wallet-feed:' + k, 'following');
- }, [base, AUTHOR.pk, FRIEND.pk, [POST]]);
+ }, [base, AUTHOR.pk, FRIEND.pk, [PLAIN, POST]]);
await page.reload({ waitUntil: 'domcontentloaded' });
await waitText('Receive', 20000);
await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click());
@@ -52,6 +54,22 @@ try {
await sleep(1200);
const where = await page.evaluate(() => location.pathname);
check('the tap opens Friendly\'s profile, not the post', where.startsWith('/npub1') && !where.includes('nevent'), where);
+ // a typed-out name: the one follow who goes by it opens, anyone else is a search
+ const tapPlain = async (name) => {
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('Receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click());
+ await waitText('big thanks to', 15000);
+ await page.evaluate((n) => [...document.querySelectorAll('[data-zap-post] a')].find((a) => a.textContent === n).click(), name);
+ await sleep(1200);
+ };
+ await tapPlain('@poster');
+ const where2 = await page.evaluate(() => location.pathname);
+ check('"@poster" typed as plain text opens the follow named Poster', where2 === '/' + npubEncode(AUTHOR.pk) || where2.startsWith('/npub1'), where2);
+ check('...and it is Poster\'s page', await waitText('Poster', 5000) && !(await page.evaluate(() => !!document.querySelector('.user-search, [data-key="user-search"]'))));
+ await tapPlain('@somebody');
+ const where3 = await page.evaluate(() => location.pathname);
+ check('"@somebody", whom you do not follow, is still a search', !where3.startsWith('/npub1'), where3);
check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ a mention opens the person' : '\n❌ failed');
diff --git a/tools/mention-ac-test.js b/tools/mention-ac-test.js
index e476e61..04d7e12 100644
--- a/tools/mention-ac-test.js
+++ b/tools/mention-ac-test.js
@@ -106,11 +106,16 @@ try {
await sleep(300);
check('...and on a second line, in place', /\ncc nostr:npub1[a-z0-9]+ $/.test(await value()) && !(await value()).includes('@glo'), JSON.stringify((await value()).slice(-90)));
+ // a name typed out in full and never picked from the list
+ await page.keyboard.type('ty @globetrotter and @nobody9 ok');
+ await sleep(300);
+
console.log('\n[posting]');
await page.evaluate(() => { window.__published = []; [...document.querySelectorAll('.post-actions button')].find((b) => /^post$/i.test(b.textContent.trim())).click(); });
await waitFor(() => window.__published.some((e) => e.kind === 1), 8000);
const ev = (await page.evaluate(() => window.__published)).find((e) => e.kind === 1);
check('the post carries both p tags', !!ev && [FRIEND, STRANGER].every((pk) => ev.tags.some((x) => x[0] === 'p' && x[1] === pk)), JSON.stringify(ev && ev.tags));
+ check('a followed name typed out, not picked, goes out as their npub', !!ev && ev.content.endsWith('ty nostr:' + npubEncode(FRIEND) + ' and @nobody9 ok'), JSON.stringify(ev && ev.content.slice(-110)));
check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ @mentions suggest people and tag them' : '\n❌ failed');