diff options
Diffstat (limited to 'src/features')
| -rw-r--r-- | src/features/messages.js | 30 |
1 files changed, 29 insertions, 1 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))]; |
