diff options
| author | Adam Soltys <[email protected]> | 2026-09-29 11:01:43 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-29 11:01:43 -0700 |
| commit | 3948ad95beb6e5e40dd275b7c4909ec8c4dee8a9 (patch) | |
| tree | 43e3057ae2c7118f7d25aa6b4931755b15e36322 | |
| parent | 75d437e81824865ba21fb9c732b351b75c78a180 (diff) | |
| download | coinosv3-3948ad95beb6e5e40dd275b7c4909ec8c4dee8a9.tar.gz coinosv3-3948ad95beb6e5e40dd275b7c4909ec8c4dee8a9.zip | |
Quoted notes are found on more relays and never show as a bare "view note"; Back from a post keeps the feed's place.
- findNote: the reference's hints, its author's NIP-65 relays and ours,
plus a wide net of big public relays, all at once, first answer wins.
A real quote (SuiGenerisJohn → 0c5e0f08…) sat only on nostr.mom,
named by neither the nevent nor its author's relay list.
- A feed row whose quote isn't in yet shows the quote card with
"Fetching note…" / "Couldn't find that note" instead of a link;
the card replaces it once found.
- Opening a post remembers the scroll position like opening a profile
does; Back restores it instead of landing at the top of the feed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Du1qT1wbkYwYK6zkGH79Rp
| -rw-r--r-- | src/features/messages.js | 65 | ||||
| -rw-r--r-- | tools/avatar-profile-test.js | 11 | ||||
| -rw-r--r-- | tools/quote-card-test.js | 19 |
3 files changed, 73 insertions, 22 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 00f66b9..b5b4c01 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -3079,17 +3079,28 @@ export function messagesFeature(ctx) { // A profile opens at its top: keeping the feed's scroll offset landed the // reader deep in that person's posts, which read as a thread. Back (a // popstate) puts them where they were on the page they left. - const profReturn = []; // [{ pk, y }] per profile opened, newest last + // The same for a post opened into its thread: Back lands on the row the + // reader tapped, not the top of the feed. + const pageReturn = []; // [{ key, y }] per profile/thread opened, newest last + const pageKey = () => ui.noteThread && !(ui.profilePk && ui.profOverThread) ? 'thread' + : ui.profilePk ? 'p:' + ui.profilePk : ''; + function rememberPlace(key) { + if (pageKey() === key) return; + let y = 0; try { y = window.scrollY || 0; } catch {} + pageReturn.push({ key, y }); + if (pageReturn.length > 20) pageReturn.shift(); + } if (typeof window !== 'undefined') window.addEventListener('popstate', () => { - const top = profReturn[profReturn.length - 1]; - if (!top || ui.profilePk === top.pk) return; - profReturn.pop(); - requestAnimationFrame(() => { try { window.scrollTo(0, top.y); } catch {} }); + const top = pageReturn[pageReturn.length - 1]; + if (!top || pageKey() === top.key) return; + pageReturn.pop(); + const y = top.y; + // twice: the page under it may paint its rows a frame late + requestAnimationFrame(() => { try { window.scrollTo(0, y); } catch {} + requestAnimationFrame(() => { try { if (Math.abs(window.scrollY - y) > 2) window.scrollTo(0, y); } catch {} }); }); }); function openProfile(pk) { - let y = 0; try { y = window.scrollY || 0; } catch {} - if (ui.profilePk !== pk) profReturn.push({ pk, y }); - if (profReturn.length > 20) profReturn.shift(); + rememberPlace('p:' + pk); ui.profilePk = pk; // Opened from inside a thread (an author's avatar/name), the profile // stacks ON TOP of it — back returns to the conversation. The screen @@ -5389,15 +5400,35 @@ export function messagesFeature(ctx) { // wanted, half a minute on, with any relay hints the reference carried. const QUOTE_RETRY_MS = 30_000; const quoted = new Map(); // id -> { status, ev, at } + // Where a referenced note may be: the reference's hints, its author's own + // relays, ours — and when none of those has it, a wider net of big public + // relays (a quoted note in the wild sat only on nostr.mom, which neither + // the reference nor its author's relay list named). + const WIDE_RELAYS = ['wss://nostr.mom', 'wss://relay.nostr.band', 'wss://nostr.wine', 'wss://relay.snort.social', + 'wss://offchain.pub', 'wss://relay.nostr.bg', 'wss://nostr.oxtr.dev', 'wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.primal.net']; + // All at once, first answer wins: asked in turn, a note on a far relay + // took longer than the feed waits for a row. + function findNote(ref) { + const pick = (evs) => (evs || []).find((e) => e.id === ref.id) || null; + const ask = (relays) => (relays.length ? queryOn(relays, { ids: [ref.id] }, 4500).then(pick).catch(() => null) : Promise.resolve(null)); + const near = [...new Set([...(ref.relays || []), ...zapRelays()])]; + const asks = [ + ask(near), + ref.author ? relaysOf(ref.author).catch(() => []).then((rs) => ask(rs.filter((r) => !near.includes(r)))) : Promise.resolve(null), + ask(WIDE_RELAYS.filter((r) => !near.includes(r))), + ]; + return new Promise((resolve) => { + let left = asks.length; + for (const a of asks) a.then((ev) => { if (ev) resolve(ev); else if (--left === 0) resolve(null); }); + }); + } function quotedNote(ref) { let c = quoted.get(ref.id); if (c && (c.status !== 'missing' || Date.now() - (c.at || 0) < QUOTE_RETRY_MS)) return c; if (!c) { c = { status: 'loading', ev: null, at: 0 }; quoted.set(ref.id, c); } c.at = Date.now(); c.promise = (async () => { - const relays = [...new Set([...(ref.relays || []), ...zapRelays()])]; - const evs = await queryOn(relays, { ids: [ref.id] }, 4500).catch(() => []); - c.ev = (evs || [])[0] || c.ev || null; + c.ev = (await findNote(ref).catch(() => null)) || c.ev || null; c.status = c.ev ? 'ready' : 'missing'; if (c.ev) cacheNotifNotes([c.ev]); // the open thread quotes it: keep it with the thread for the next reload @@ -5428,9 +5459,10 @@ export function messagesFeature(ctx) { let c = feedPaint ? feedPaint.quotes.get(ref.id) : quotedNote(ref); if (feedPaint && !c?.ev) { const live = quoteWarm(ref); - if (!(live.ev && live.warm)) return h('a', { - href: '#', onClick: (e) => { e.preventDefault(); e.stopPropagation(); openNoteRef(ref); }, - }, t('noteRefLink')); + // not (yet) found: the card says so where the quote will be — never a + // bare "view note" link that only leads to the same answer + if (!(live.ev && live.warm)) return h('div', { class: 'quote-card' }, + h('span', { class: 'small faint' }, t(live.status === 'missing' ? 'noteRefNotFound' : 'noteRefLoading'))); c = { ...live }; feedPaint.quotes.set(ref.id, c); } @@ -6900,6 +6932,7 @@ export function messagesFeature(ctx) { return c; } function openNoteThread(ev) { + rememberPlace('thread'); ui.noteThread = { rootId: rootIdOf(ev), focusId: ev.id, seed: ev, scrollPending: true }; ui.profOverThread = false; // a freshly opened thread goes on top render(); @@ -6912,9 +6945,7 @@ export function messagesFeature(ctx) { const cached = saved && (saved.root.id === ref.id ? saved.root : saved.replies.find((e) => e.id === ref.id)); if (cached) { openNoteThread(cached); return; } toast(t('noteRefLoading')); - const relays = [...new Set([...(ref.relays || []), ...NOTE_RELAYS])]; - const evs = await queryOn(relays, { ids: [ref.id] }, 4000).catch(() => []); - const ev = (evs || [])[0]; + const ev = quoted.get(ref.id)?.ev || await findNote(ref).catch(() => null); if (ev) openNoteThread(ev); else toast(t('noteRefNotFound')); } diff --git a/tools/avatar-profile-test.js b/tools/avatar-profile-test.js index 6e84429..54c40dc 100644 --- a/tools/avatar-profile-test.js +++ b/tools/avatar-profile-test.js @@ -69,6 +69,17 @@ try { } check('back returns to the feed where the reader was', back.feed && Math.abs(back.y - feedY) < 60, 'scrollY ' + back.y + ' vs ' + feedY); + // a post opened into its thread: Back lands where the reader was + await page.evaluate(() => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.innerText.includes('post number 13')); r.scrollIntoView({ block: 'center' }); }); + await sleep(700); + const y0 = await page.evaluate(() => window.scrollY); + await page.evaluate(() => [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.innerText.includes('post number 13')).querySelector('.note-text').click()); + await sleep(1500); + const inThread = await page.evaluate(() => !!document.querySelector('.thread-page')); + await page.goBack(); await sleep(1500); + const y1 = await page.evaluate(() => window.scrollY); + check('back from a post returns to the same place in the feed', inThread && y0 > 500 && Math.abs(y1 - y0) < 60, 'scrollY ' + y1 + ' vs ' + y0); + // "Their timeline" from the profile: its chip names it (it was a blank pill) await page.evaluate(() => { const r = [...document.querySelectorAll('.notes-feed .note-avatar')].find((n) => n.closest('[data-key]')?.innerText.includes('Bob Poster')); r.click(); }); await sleep(1000); diff --git a/tools/quote-card-test.js b/tools/quote-card-test.js index 91edf3b..d2d7d7e 100644 --- a/tools/quote-card-test.js +++ b/tools/quote-card-test.js @@ -25,6 +25,7 @@ const found = await pool.querySync(['wss://relay.primal.net', 'wss://nos.lol'], const target = (found || []).filter((e) => e.content && e.content.length > 20)[0]; if (!target) { console.log(' ✗ no note to quote (relays quiet)'); process.exit(1); } const nevent = neventOf(target.id, target.pubkey); +const FAR = 'nevent1qvzqqqqqqypzqntcggz30qhq60ltqdx32zku9d46unhrkjtcv7fml7jx3dh4h94nqqsqchs0pz4hnqm6jurakjwcd6wcrph7wyy80j0ljup68p4hynvsz3q3nhre2'; const html = await buildHtml({ minify: true, pwa: false }); const server = Bun.serve({ port: 5269, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) }); @@ -59,21 +60,24 @@ try { await waitText('receive', 20000); const base = cacheKeyFor(mn + '\n'); const A = 'a'.repeat(63) + '9'; - await page.evaluate(([k, pk, ref]) => { + await page.evaluate(([k, pk, ref, FAR]) => { localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', pk]], c: '', at: Math.floor(Date.now()/1000) })); localStorage.setItem(k + ':feedNotes', JSON.stringify([ { id: 'd'.repeat(64), pubkey: pk, kind: 1, created_at: Math.floor(Date.now()/1000), content: 'what he said nostr:' + ref, tags: [] }, + // quotes a note that sits only on nostr.mom — not in the reference, not in its author's relay list + { id: 'e'.repeat(64), pubkey: pk, kind: 1, created_at: Math.floor(Date.now()/1000) - 60, content: 'I remember this.\n\nnostr:' + FAR, tags: [] }, ])); localStorage.setItem(k + ':profiles', JSON.stringify({ [pk]: { name: 'Quoter', t: Date.now() } })); - }, [base, A, nevent]); + }, [base, A, nevent, FAR]); if (process.argv.includes('--slow')) await page.evaluate(() => localStorage.setItem('__slowQuote', '1')); await page.reload({ waitUntil: 'domcontentloaded' }); await waitText('receive', 20000); await page.evaluate(() => document.querySelector('.app-bottom-nav .app-nav-button').click()); await sleep(7000); if (process.argv.includes('--slow')) { - for (let i = 0; i < 40 && !(await page.evaluate(() => document.body.innerText.includes('view note'))); i++) await sleep(250); - check('a late quote first paints as a link', await page.evaluate(() => document.body.innerText.includes('view note'))); + for (let i = 0; i < 40 && !(await page.evaluate(() => !!document.querySelector('.quote-card'))); i++) await sleep(250); + check('a late quote first paints as a placeholder card, not a link', await page.evaluate(() => !document.body.innerText.includes('view note') + && [...document.querySelectorAll('.quote-card')].some((q) => /Couldn.t find|Fetching note/.test(q.innerText)))); await sleep(SLOW_MS + 4000); } @@ -87,7 +91,12 @@ try { check('...with whose note it is', !!(card && card.hasAvatar), card ? card.text.slice(0, 50) : ''); const body = target.content.replace(/\s+/g, ' ').slice(0, 24); check('...and what it actually said', !!(card && card.text.replace(/\s+/g, ' ').includes(body.slice(0, 18))), body); - check('no "view note" link left in the post', !(await page.evaluate(() => document.body.innerText)).includes('view note')); + if (!process.argv.includes('--slow')) { + const far = await page.evaluate(() => { const r = [...document.querySelectorAll('.notes-feed [data-key]')].find((n) => n.innerText.includes('Quoter') && n.innerText.includes('I remember this')); return r && r.querySelector('.quote-card')?.innerText; }); + check('a quote found only on a far relay still shows as its card', !!far && !/Couldn.t find|Fetching/.test(far), JSON.stringify((far || '').slice(0, 60))); + } + // (a quote inside a quote stays a link on purpose: one level of cards) + check('no "view note" link left in the post', !(await page.evaluate(() => [...document.querySelectorAll('.notes-feed a')].some((a) => a.textContent === 'view note' && !a.closest('.quote-card'))))); // the outer post keeps its actions; the quote has none of its own const acts = await page.evaluate(() => ({ outer: document.querySelectorAll('.notes-feed > .row .note-acts').length, |
