diff options
| -rw-r--r-- | src/features/messages.js | 13 | ||||
| -rw-r--r-- | tools/link-preview-test.js | 15 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/features/messages.js b/src/features/messages.js index 95fcde8..6875856 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -14099,8 +14099,21 @@ export function messagesFeature(ctx) { // You could only find out by posting. This runs the draft through noteBody // — the very renderer the feed uses — so the preview is not a lookalike of // the real thing, it IS the real thing. + // A link's card needs its page read first: the feed warms that before a + // post shows, a draft only once the typing settles (not one registrar call + // per keystroke of a URL), then repaints into the card. + let draftPvTimer = null; + function warmDraftPreviews(body) { + const want = notePreviewUrls(body).filter((u) => !previews.has(u)); + clearTimeout(draftPvTimer); + if (!want.length) return; + draftPvTimer = setTimeout(() => { + for (const u of want) warmPreview(u).then(() => { if (previews.get(u)) scheduleRepaint(); }); + }, 500); + } function draftPreview(text) { const body = String(text || '').trim(); + warmDraftPreviews(body); return h('div', { class: 'draft-preview' }, h('div', { class: 'draft-preview-tag' }, t('composePreviewTag')), body diff --git a/tools/link-preview-test.js b/tools/link-preview-test.js index 190b220..bf68bbc 100644 --- a/tools/link-preview-test.js +++ b/tools/link-preview-test.js @@ -30,7 +30,9 @@ const server = Bun.serve({ port: 5311, fetch: (req) => { const target = u.searchParams.get('url'); previewHits.push(target); const meta = target === 'https://news.example/story/1' ? { url: target, title: 'Lawmakers doubt the plan', description: 'A story in one line.', image: 'http://localhost:5311/card.png', site: 'News Example' } - : {}; + : target === 'https://movies.example/movie/1382/play?t=4910' + ? { url: target, title: 'Hackers (1995) · from 1:21:50', description: 'Teenage hackers.', image: 'http://localhost:5311/movie.png', site: 'PAFF' } + : {}; return new Response(JSON.stringify(meta), { headers: { 'content-type': 'application/json', 'access-control-allow-origin': '*' } }); } if (u.pathname.endsWith('.png')) return new Response(PNG, { headers: { 'content-type': 'image/png' } }); @@ -117,6 +119,17 @@ try { let kept = 0; // written behind, a second after the card was learned for (let i = 0; i < 12 && !kept; i++) { kept = await page.evaluate(() => JSON.parse((window.coinosCache || localStorage).getItem('coinos-link-previews') || '[]').length); if (!kept) await sleep(300); } check('the card is remembered for next time', kept === 1, kept + ' kept'); + // a draft's preview shows the card too (Adam, 2026-11-17: a paff.club + // movie link stayed a bare URL in Preview), once the typing settles + const opened = await page.evaluate(() => { const b = [...document.querySelectorAll('button')].find((n) => (n.getAttribute('aria-label') || n.textContent).trim().toLowerCase() === 'new post'); if (b) { b.click(); return true; } return false; }); + await sleep(400); + const typeDraft = (v) => page.evaluate((val) => { const e = document.querySelector('coinos-text'); e.focus(); e.value = val; e.dispatchEvent(new Event('input', { bubbles: true })); }, v); + await typeDraft('watch this\n\nhttps://movies.example/movie/1382/play?t=4910'); + await page.evaluate(() => [...document.querySelectorAll('button')].find((b) => /preview/i.test(b.getAttribute('aria-label') || ''))?.click()); + let draft = null; + for (let i = 0; i < 20; i++) { draft = await page.evaluate(() => { const p = document.querySelector('.draft-preview'); return p && { card: !!p.querySelector('.link-card'), title: p.querySelector('.link-title')?.textContent }; }); if (draft?.card) break; await sleep(250); } + check('a draft\'s preview shows the link as its card', opened && draft?.card && /Hackers/.test(draft.title || ''), JSON.stringify(draft)); + check('...asked for once the typing settled, not per keystroke', previewHits.filter((u) => u.startsWith('https://movies.example')).length === 1, JSON.stringify(previewHits)); check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); } finally { await browser.close(); server.stop(true); } console.log(ok ? '\n✅ links show as the cards their pages describe' : '\n❌ failed'); |
