From 210c2978a1a608f27e2caeb4eb39fffdc28347bc Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 22 Oct 2026 09:35:11 -0700 Subject: Media grid shows a clip or picture once however many posts carry it (same file or Blossom hash, or the same words from the same person re-uploaded); on a big window a small clip in the pager is drawn at most 1.5x its pixels instead of blown up across the monitor Co-Authored-By: Claude Opus 5.5 --- src/features/messages.js | 39 ++++++++++++++--- tools/media-grid-dups-test.js | 99 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 tools/media-grid-dups-test.js diff --git a/src/features/messages.js b/src/features/messages.js index 7be3630..4900c40 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -13946,8 +13946,14 @@ export function messagesFeature(ctx) { if (d && d.probed && !d.w && d.ranges && !videoDims.has(url)) return playerShape(url); }).finally(() => { if (mediaMode === 'videos') scheduleRepaint(); }); } + // One picture or clip shows once in the grid, however many posts carry it + // (Adam, 2026-10-22: a conference promo filled the Videos view with + // copies): the same file (a Blossom hash names it wherever it's hosted), + // or the same words from the same person posted again with another upload. + const sameFile = (url) => { const m = /\/([0-9a-f]{64})(?:\.\w+)?(?:[?#]|$)/i.exec(url); return m ? m[1].toLowerCase() : url.replace(/[?#].*$/, ''); }; + const saidAgain = (ev) => { const w = String(ev.content || '').replace(/https?:\/\/\S+/g, '').replace(/\s+/g, ' ').trim(); return w.length >= 8 ? ev.pubkey + '|' + w : null; }; function mediaItems(c, kind) { - const out = [], seen = new Set(); + const out = [], seen = new Set(), said = new Map(); const r = mediaIndex(c.id); indexMedia(r, c.notes); const evs = [...r[kind].values()].sort((a, b) => b.created_at - a.created_at); @@ -13956,14 +13962,19 @@ export function messagesFeature(ctx) { if (hidden(ev)) continue; // a grid shows the picture itself — no warning to fold it behind if (curated ? notForPublic(ev) : modOn('sensitive') && sensitiveWhy(ev) !== null && !isMe(ev.pubkey)) continue; + const again = saidAgain(ev); + if (again && said.has(again) && said.get(again) !== ev.id) continue; if (kind === 'videos') learnVideoMeta(ev); const urls = kind === 'videos' ? clipUrlsOf(ev).filter(fitClip) : noteMediaUrls(ev.content).filter((u) => !u.startsWith('https://i.ytimg.com/')); + // (the words are taken by a post that shows: one whose clip doesn't fit + // the screen leaves them to the next) + if (again && urls.length) said.set(again, ev.id); for (const url of urls) { - const it = { ev, url }; - if (seen.has(mediaKey(it))) continue; - seen.add(mediaKey(it)); - out.push(it); + const f = sameFile(url); + if (seen.has(f)) continue; + seen.add(f); + out.push({ ev, url }); } } return out; @@ -14485,6 +14496,7 @@ export function messagesFeature(ctx) { m.closest('.mp-slide').classList.add('mp-gone'); m.insertAdjacentElement('afterend', h('div', { class: 'mp-missing' }, h('div', { class: 'mp-missing-ico' }, 'šŸ–¼'), h('div', {}, t('mediaPicGone')), host ? h('div', { class: 'small muted' }, host) : null)); } })); + if (video) capUpscale(media); const caption = mediaCaption(ev, true); const stop = (fn) => (e) => { e.stopPropagation(); fn(e); }; const slide = h('div', { class: 'mp-slide', 'data-k': mediaKey(it) }, @@ -14537,6 +14549,23 @@ export function messagesFeature(ctx) { // (the clip holds still meanwhile, and the time shows); the drag is the // bar's alone, never the pager's swipe or its tap. const clock = (t) => { t = Math.max(0, Math.floor(t || 0)); const m = Math.floor(t / 60), x = t % 60; return m + ':' + String(x).padStart(2, '0'); }; + // A big screen blew a small clip up into blocks (Adam, 2026-10-22: "videos + // that are low res … so pixellated on my large 1920 monitor"). In a big + // window (a phone on its side is too short) a clip is drawn at most 1.5Ɨ + // its own pixels, + // smaller ones sitting in the middle on the pager's black. A phone fills + // its screen as before. + const MAX_UPSCALE = 1.5; + function capUpscale(v) { + const fit = () => { + const big = v.videoWidth && matchMedia('(min-width: 1000px) and (min-height: 600px)').matches; + const k = MAX_UPSCALE / (window.devicePixelRatio || 1); + v.style.maxWidth = big ? Math.round(v.videoWidth * k) + 'px' : ''; + v.style.maxHeight = big ? Math.round(v.videoHeight * k) + 'px' : ''; + }; + v.addEventListener('loadedmetadata', fit); + if (v.readyState >= 1) fit(); + } // up for a few seconds, and on while a finger is on it // (a mouse brings it up by moving, so it goes sooner once the mouse is // still, and stays while the pointer rests on the bar itself) diff --git a/tools/media-grid-dups-test.js b/tools/media-grid-dups-test.js new file mode 100644 index 0000000..360ae0c --- /dev/null +++ b/tools/media-grid-dups-test.js @@ -0,0 +1,99 @@ +// The Videos grid shows a clip once, however many posts carry it: the same +// file (or a Blossom hash's mirror), or the same words from the same person +// with a fresh upload (Adam, 2026-10-22). And on a big screen with a mouse, a +// small clip opened in the pager is drawn at most 1.5Ɨ its own pixels, not +// blown up across the monitor. Run: bun tools/media-grid-dups-test.js +import puppeteer from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { buildHtml } from '../build.js'; +import { existsSync } from 'node:fs'; +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +let ok = true; +const check = (n, c, d = '') => { console.log(` ${c ? 'āœ“' : 'āœ—'} ${n}${d ? ' — ' + d : ''}`); if (!c) ok = false; }; +const png = Bun.spawnSync(['ffmpeg', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=320x180', '-frames:v', '1', '-f', 'image2', '-c:v', 'png', 'pipe:1']).stdout; +const clip = (name, size) => { + const f = '/tmp/coinos-vpager-' + name + '.webm'; + if (!existsSync(f)) Bun.spawnSync(['ffmpeg', '-y', '-loglevel', 'error', '-f', 'lavfi', '-i', 'testsrc=size=' + size + ':rate=10', '-t', '30', '-c:v', 'libvpx', '-b:v', '100k', f]); + return f; +}; +const CLIPS = { wide: clip('wide', '320x180'), again: clip('wide', '320x180'), other: clip('wide', '320x180'), last: clip('last', '240x240') }; +const SK = generateSecretKey(), AUTHOR = getPublicKey(SK); +const now = Math.floor(Date.now() / 1000); +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 0, fetch: (req) => { + const path = new URL(req.url).pathname; + const m = /^\/(wide|again|other|last)\.webm$/.exec(path); + if (m) { + const f = Bun.file(CLIPS[m[1]]), range = /^bytes=(\d+)-(\d*)$/.exec(req.headers.get('range') || ''); + if (!range) return new Response(f, { headers: { 'content-type': 'video/webm', 'accept-ranges': 'bytes' } }); + const a = +range[1], b = range[2] ? Math.min(+range[2], f.size - 1) : f.size - 1; + return new Response(f.slice(a, b + 1), { status: 206, headers: { 'content-type': 'video/webm', 'accept-ranges': 'bytes', 'content-range': 'bytes ' + a + '-' + b + '/' + f.size, 'content-length': String(b - a + 1) } }); + } + if (path === '/still.png') return new Response(png, { headers: { 'content-type': 'image/png' } }); + if (path.startsWith('/punks') || path === '/verify-worker.js') return new Response(Bun.file('dist' + path)); + return new Response(html, { headers: { 'content-type': 'text/html' } }); +} }); +const U = (n) => server.url.origin + '/' + n + '.webm'; +const post = (content, url, ago) => finalizeEvent({ kind: 1, created_at: now - ago, tags: [['imeta', 'url ' + url, 'image ' + server.url.origin + '/still.png', 'm video/webm']], content }, SK); +const seeded = [ + // one clip, three posts (a promo posted again and again) + post('see you at the conference ' + U('wide'), U('wide'), 100), + post('tickets going fast ' + U('wide'), U('wide'), 150), + post('last call ' + U('wide') + '?x=1', U('wide') + '?x=1', 160), + // the same words from the same person, uploaded afresh each time + post('Transylvania lightning conference 2026 ' + U('again'), U('again'), 200), + post('Transylvania lightning conference 2026 ' + U('other'), U('other'), 300), + post('the last clip ' + U('last'), U('last'), 400), +]; + +const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox', '--autoplay-policy=no-user-gesture-required'] }); +const page = await browser.newPage(); +await page.evaluateOnNewDocument(() => { + const Real = window.WebSocket; + window.WebSocket = function (...a) { const ws = new Real(...a); const send = ws.send.bind(ws); ws.send = (d) => { try { const m = JSON.parse(d); if (m[0] === 'REQ') { setTimeout(() => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EOSE', m[1]]) })), 0); return; } if (m[0] === 'EVENT') return; } catch {} return send(d); }; return ws; }; + window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real); +}); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; }; +const waitFor = async (fn, arg, ms = 10000) => { for (let i = 0; i < ms / 100; i++) { if (await page.evaluate(fn, arg)) return true; await sleep(100); } return false; }; +try { + await page.setViewport({ width: 1600, height: 900 }); + await page.goto(server.url.href, { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.reload({ waitUntil: 'domcontentloaded' }); + await sleep(400); + await click('create a new wallet'); await sleep(600); + await page.waitForSelector('.words .w .t'); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await click('skip verification'); + await waitText('receive', 20000); + const base = cacheKeyFor(mn + '\n'); + await page.evaluate(([k, pk, ns]) => { + localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', pk]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':feedNotes', JSON.stringify(ns)); + localStorage.setItem(k + ':profiles', JSON.stringify({ [pk]: { name: 'Clip Poster', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, AUTHOR, seeded]); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]').click()); + check('the clips are in the feed', await waitFor(() => document.querySelectorAll('.notes-feed video.note-video').length >= 6, null, 20000)); + await page.evaluate(() => document.querySelector('.media-mode[data-mode="videos"]').click()); + await waitFor(() => document.querySelectorAll('.media-grid .media-tile').length >= 3, null, 15000); + await sleep(1500); + const tiles = await page.evaluate(() => document.querySelectorAll('.media-grid .media-tile').length); + check('one tile per clip: the reposted file once, the re-uploaded post once, the other one', tiles === 3, tiles + ' tiles'); + await page.evaluate(() => document.querySelector('.media-grid .media-tile').click()); + check('the pager opens', await waitFor(() => !!document.querySelector('.mp-slide.mp-cur video.mp-media'), null, 6000)); + check('the clip is drawn no bigger than 1.5Ɨ its pixels', await waitFor(() => { const v = document.querySelector('.mp-slide.mp-cur video.mp-media'); return v && v.videoWidth && v.getBoundingClientRect().width <= v.videoWidth * 1.5 + 1 && v.style.maxWidth; }, null, 8000), + JSON.stringify(await page.evaluate(() => { const v = document.querySelector('.mp-slide.mp-cur video.mp-media'); return v && { vw: v.videoWidth, w: v.getBoundingClientRect().width, max: v.style.maxWidth }; }))); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { + await browser.close(); + server.stop(true); +} +console.log(ok ? '\nāœ… the grid shows each clip once; small clips stay sharp on a big screen' : '\nāŒ failed'); +process.exit(ok ? 0 : 1); -- cgit v1.2.3