diff options
| -rw-r--r-- | src/features/hats.js | 45 | ||||
| -rw-r--r-- | src/features/messages.js | 34 | ||||
| -rw-r--r-- | src/i18n.js | 3 | ||||
| -rw-r--r-- | src/style.css | 5 | ||||
| -rw-r--r-- | tools/feed-long-note-test.js | 85 | ||||
| -rw-r--r-- | tools/hats-santa-test.js | 70 |
6 files changed, 237 insertions, 5 deletions
diff --git a/src/features/hats.js b/src/features/hats.js index a00f285..bf0ec31 100644 --- a/src/features/hats.js +++ b/src/features/hats.js @@ -81,6 +81,17 @@ const HATS = [ <path d="M41.5 26 l0.9 2 2 0.9 -2 0.9 -0.9 2 -0.9 -2 -2 -0.9 2 -0.9 Z" fill="#ffe08a"/>`), }, { + // Free to everyone through December (the registrar says when: its + // /hats/<pk> answer lists the hats free right now). Kept after. + id: 'santa', nameKey: 'hatSanta', sat: null, seasonal: true, w: 104, b: 73, r: -8, + art: svg(`<path d="M11 33 Q12 14 30 8.5 Q45 4.5 53 12.5 Q56.5 16.5 56 22 Q53 17.5 47 16.5 Q50.5 24 51.5 33 Z" fill="#d62f35"/> + <path d="M30 8.5 Q45 4.5 53 12.5 Q56.5 16.5 56 22 Q53 17.5 47 16.5 Q44 13 37 12 Q34 10 30 8.5 Z" fill="#b5242a"/> + <path d="M17 31 Q18 18 29 12" stroke="#ec5a5f" stroke-width="2" fill="none" stroke-linecap="round"/> + <circle cx="56" cy="23.5" r="5.2" fill="#f7f5f0" stroke="#d9d4ca" stroke-width="0.9"/> + <rect x="7" y="29.5" width="50" height="10.5" rx="5.25" fill="#f7f5f0" stroke="#d9d4ca" stroke-width="0.9"/> + <path d="M14 33 q2 1.5 4 0 M24 34.5 q2 1.5 4 0 M35 33 q2 1.5 4 0 M45 34.5 q2 1.5 4 0" stroke="#e2ddd3" stroke-width="1.1" fill="none" stroke-linecap="round"/>`), + }, + { // Not for sale: gifted by the operator to beta testers (see the // registrar's /hats/grant). Appears in the shop only once owned. id: 'construction', nameKey: 'hatConstruction', sat: null, w: 108, b: 71, r: -6, @@ -330,7 +341,7 @@ export function hatsFeature(ctx) { if (!me) { ui.hatShopData = { owned: [], equipped: null }; render(); return; } const attempt = (retriesLeft) => fetch(`${REGISTRAR}/hats/${me}?net=${hatNet()}`).then((r) => r.json()).then((j) => { if (!ui.hatShop) return; - ui.hatShopData = { owned: j.owned || [], equipped: j.equipped || null, prices: j.prices || null }; + ui.hatShopData = { owned: j.owned || [], equipped: j.equipped || null, prices: j.prices || null, free: j.free || [] }; const now = Date.now(); worn.set(hatNet() + ':' + me, { hat: j.equipped || null, t: now }); saveStore(); @@ -382,6 +393,29 @@ export function hatsFeature(ctx) { } } + // A free seasonal hat: no invoice, the registrar just hands it over. + async function takeFree(hat) { + ui.hatBuying = hat.id; + render(); + try { + const id = await identity(); + if (!id) { + if (!hook('nostrReconnectPrompt')) toast(t('msgNoIdentity')); + return; + } + const rec = await post('/hats/free', { hat: hat.id, net: hatNet() }, id.signer); + ui.hatShopData = { ...ui.hatShopData, owned: rec.owned, equipped: rec.equipped }; + worn.set(hatNet() + ':' + id.pubkey, { hat: rec.equipped, t: Date.now() }); + saveStore(); + toast(t('hatYours', { name: t(hat.nameKey) })); + } catch (e) { + toast(e.message || String(e)); + } finally { + ui.hatBuying = null; + render(); + } + } + async function equip(hatId) { ui.hatBuying = hatId || 'none'; render(); @@ -409,6 +443,8 @@ export function hatsFeature(ctx) { return (d && d.prices && d.prices[hat.id]) || hat.sat; }; + const isFree = (hat, d) => !!(d && (d.free || []).includes(hat.id)); + const demo = (hat) => h('span', { class: 'hat-demo' }, h('span', { class: 'hat-demo-head' }), h('span', { class: 'ava-hat', style: posStyle(hat), html: hat.art })); @@ -426,6 +462,8 @@ export function hatsFeature(ctx) { action = h('button', { class: 'btn-sm hat-btn wearing', onClick: () => equip(null) }, t('hatWearing')); } else if (ownedHere) { action = h('button', { class: 'btn-sm hat-btn', onClick: () => equip(hat.id) }, t('hatWear')); + } else if (isFree(hat, d)) { + action = h('button', { class: 'btn-sm hat-btn', disabled: !!ui.hatBuying, onClick: () => takeFree(hat) }, t('hatFree')); } else if (ui.hatConfirm === hat.id) { action = h('button', { class: 'btn-sm hat-btn confirm', onClick: () => buy(hat) }, t('hatConfirmTap')); } else { @@ -440,6 +478,7 @@ export function hatsFeature(ctx) { h('div', { class: 'chat-name' }, t(hat.nameKey)), ownedHere ? h('div', { class: 'muted small' }, t('hatOwned')) + : isFree(hat, d) ? h('div', { class: 'muted small' }, t('hatSantaWhen')) : hat.id === 'crown' ? h('div', { class: 'muted small' }, t('hatCrownWho')) : null), action); } @@ -458,7 +497,9 @@ export function hatsFeature(ctx) { // unpriced hats (the crown, the beta hard hat) are not // merchandise — they appear only in the collection of a head // that owns them, never as a listing - ...HATS.filter((hat) => (priceOf(hat) || 0) > 0 || ((d && d.owned) || []).includes(hat.id)) + // a free seasonal hat leads the list while it's in season + ...HATS.filter((hat) => isFree(hat, d)) + .concat(HATS.filter((hat) => !isFree(hat, d) && ((priceOf(hat) || 0) > 0 || ((d && d.owned) || []).includes(hat.id)))) .map((hat) => shopRow(hat, d, me))), d && d.offline ? h('div', { class: 'small faint', style: 'text-align:center' }, t('hatShopOffline')) : null), h('button', { class: 'btn-ghost btn-block', onClick: closeShop }, t('back'))); diff --git a/src/features/messages.js b/src/features/messages.js index 2351e2b..952350f 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -12946,6 +12946,36 @@ export function messagesFeature(ctx) { // context: a reply shows the post it answers above itself (the // Conversations feed, a profile's Replies tab) — a quote card, which opens // that post; the reply's own tap opens the thread at the reply. + // A really long note (ZeroHedge's run to dozens of lines) shows its first + // ten lines in a feed, fading out, with Show more under it; its thread, and + // a tap on Show more, give the whole thing. "Could you collapse REALLY long + // notes, with a 'more...' link to expand" (npub1muckyme, 2026-11-30). + // Long = more than 16 lines at this screen's width, by estimate, so a + // collapsed note always hides a good part of itself, never a line or two. + const NOTE_CLAMP_OVER = 16; + const noteExpanded = new Set(); + function noteLines(text) { + const w = Math.min((typeof window !== 'undefined' && window.innerWidth) || 400, 680); + const perLine = Math.max(24, Math.floor((w - 90) / 9.5)); // 18px text + let n = 0; + for (const para of String(text || '').split('\n')) n += Math.max(1, Math.ceil(para.length / perLine)); + return n; + } + function noteTextBlock(ev, open, focus) { + const clampable = open && !focus; + const text = ev.kind === ARTICLE ? '' : momentStripped(ev, shownTranslation(ev)?.text ?? noteText(ev)); + const clamp = clampable && ev.kind !== ARTICLE && !noteExpanded.has(ev.id) && noteLines(text) > NOTE_CLAMP_OVER; + const body = h('div', { class: 'note-text' + (clamp ? ' note-clamped' : ''), style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, + momentLink(ev), + ...(ev.kind === ARTICLE ? (open ? [articleCard(ev)] : articleBody(ev)) : noteBody(text, 0, noteEmojiTags(ev)))); + if (!clamp) return body; + return h('div', { class: 'note-clamp-wrap' }, body, + h('button', { + class: 'note-more', type: 'button', + onClick: (e) => { e.stopPropagation(); noteExpanded.add(ev.id); render(); }, + }, t('showMore'))); + } + function noteRow(pk, ev, name, { open = true, focus = false, joined = false, context = false } = {}) { if (ev.kind === REPOST) { const inner = repostInner(ev); @@ -13052,9 +13082,7 @@ export function messagesFeature(ctx) { zapText(ev) ? h('div', {}, ...noteBody(zapText(ev))) : null) : foreign ? h('div', { class: 'note-text small muted', style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, (ev.kind === 64 ? '\u265f ' : '') + altText) - : h('div', { class: 'note-text', style: 'white-space:pre-wrap;overflow-wrap:anywhere' }, - momentLink(ev), - ...(ev.kind === ARTICLE ? (open ? [articleCard(ev)] : articleBody(ev)) : noteBody(momentStripped(ev, shownTranslation(ev)?.text ?? noteText(ev)), 0, noteEmojiTags(ev)))), + : noteTextBlock(ev, open, focus), foreign || pending ? null : translateLine(ev), ev.kind === POLL ? pollBox(ev) : null, pending ? null : noteActions(pk, ev, { canZap }), diff --git a/src/i18n.js b/src/i18n.js index e3a1ad7..2b513c6 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -988,6 +988,9 @@ const STR = { hatConstruction: 'Hard hat', hatCrown: 'The Crown', hatKnight: 'Knight\u2019s helm', + hatSanta: 'Santa hat', + hatSantaWhen: 'Free for everyone through December', + hatFree: 'Free', hatCrownWho: "Adam's. Sorry.", hatCrownTaken: 'not for sale', hatOwned: 'In your hat rack', diff --git a/src/style.css b/src/style.css index 311cfbb..4a86697 100644 --- a/src/style.css +++ b/src/style.css @@ -755,6 +755,11 @@ html:has(#app .chat-card), body:has(#app .chat-card) { overflow: hidden; } .note-content > * { grid-column: 1 / -1; min-width: 0; } .note-content > .note-header { grid-column: 2; grid-row: 1; } .note-content > .note-text { font-size: 18px; line-height: 1.5; } +/* a really long note in a feed: ten lines, fading out, then Show more */ +.note-content > .note-clamp-wrap > .note-text { font-size: 18px; line-height: 1.5; } +.note-text.note-clamped { max-height: 15em; overflow: hidden; + -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent); mask-image: linear-gradient(to bottom, #000 72%, transparent); } +.note-more { background: none; border: 0; padding: 4px 0 2px; color: var(--accent, #f7931a); font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; } .note-acts { margin-top: 8px; gap: 4px; width: 100%; } .note-acts > .note-act { flex: 1 1 0; min-width: 0; justify-content: center; padding-inline: 2px; } /* server comparison table (Settings → Advanced → Ark server) */ diff --git a/tools/feed-long-note-test.js b/tools/feed-long-note-test.js new file mode 100644 index 0000000..cfac264 --- /dev/null +++ b/tools/feed-long-note-test.js @@ -0,0 +1,85 @@ +// A REALLY long note is collapsed in the feed with Show more under it. +// "could you collapse REALLY long notes, with a 'more...' link to expand if +// the user wants to read them. I follow ZeroHedge News ... and their notes +// are huge!" (npub1muckyme in the coinos community, 2026-11-30). A short note +// is left alone; Show more opens the long one in place (not its thread); +// the thread shows it whole. +// Run: bun tools/feed-long-note-test.js +import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js'; +import { cacheKeyFor } from '../src/wallet.js'; +import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure'; +import { buildHtml } from '../build.js'; +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 key = () => { const sk = generateSecretKey(); return { sk, pk: getPublicKey(sk) }; }; +const AUTHOR = key(), FRIEND = key(); +const now = Math.floor(Date.now() / 1000); +const para = (i) => `Paragraph ${i}: markets moved sharply today as traders digested a flood of new data, and analysts warned that volatility could persist well into next week.`; +const LONG = finalizeEvent({ kind: 1, created_at: now - 100, tags: [], content: 'LONGSTART ' + Array.from({ length: 14 }, (_, i) => para(i + 1)).join('\n\n') + ' LONGEND' }, AUTHOR.sk); +const SHORT = finalizeEvent({ kind: 1, created_at: now - 50, tags: [], content: 'a short one, gm' }, FRIEND.sk); +const html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5351, 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'] }); +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)).includes(x)) return true; await sleep(250); } return false; }; +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto('http://localhost:5351/', { 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 seedWords(page); + const mn = (await page.$$eval('.words .w .t', (l) => l.map((e) => e.textContent.trim()))).join(' '); + await skipSeedCheck(page); + 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], ['p', f]], c: '', at: Math.floor(Date.now() / 1000) })); + localStorage.setItem(k + ':feedNotes', JSON.stringify(ns)); + localStorage.setItem(k + ':profiles', JSON.stringify({ [a]: { name: 'Hedgie', t: Date.now() }, [f]: { name: 'Friendly', t: Date.now() } })); + localStorage.setItem('btc-wallet-feed:' + k, 'following'); + }, [base, AUTHOR.pk, FRIEND.pk, [SHORT, LONG]]); + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('Receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + check('the feed shows both posts', await waitText('a short one, gm', 15000) && await waitText('LONGSTART', 5000)); + const state = () => page.evaluate((id) => { + const row = document.querySelector(`[data-zap-post="${id}"]`); + const txt = row?.querySelector('.note-text'); + return { clamped: !!row?.querySelector('.note-clamped'), more: !!row?.querySelector('.note-more'), h: txt ? txt.getBoundingClientRect().height : 0, full: txt ? txt.scrollHeight : 0 }; + }, LONG.id); + const s1 = await state(); + check('the long note is collapsed', s1.clamped && s1.h < s1.full * 0.6, JSON.stringify(s1)); + check('...about ten lines tall', s1.h > 200 && s1.h < 300, String(s1.h)); + check('...with Show more under it', s1.more); + if (process.env.SHOT) { await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"]`).scrollIntoView(), LONG.id); await sleep(300); await page.screenshot({ path: process.env.SHOT }); } + const short = await page.evaluate((id) => !!document.querySelector(`[data-zap-post="${id}"] .note-clamped, [data-zap-post="${id}"] .note-more`), SHORT.id); + check('the short note is left alone', !short); + await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"] .note-more`).click(), LONG.id); + await sleep(700); + const s2 = await state(); + check('Show more opens it in place', !s2.clamped && !s2.more && s2.h >= s2.full - 2, JSON.stringify(s2)); + check('...without opening its thread', !(await page.evaluate(() => location.pathname)).includes('nevent'), await page.evaluate(() => location.pathname)); + // the thread: whole, no Show more + await page.reload({ waitUntil: 'domcontentloaded' }); + await waitText('Receive', 20000); + await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click()); + await waitText('LONGSTART', 15000); + check('collapsed again after a reload', (await state()).clamped); + await page.evaluate((id) => document.querySelector(`[data-zap-post="${id}"] .note-header`).click(), LONG.id); + await sleep(1500); + const inThread = await page.evaluate((id) => { const rows = [...document.querySelectorAll(`[data-zap-post="${id}"]`)]; const r = rows[rows.length - 1]; return { n: rows.length, clamped: !!r?.querySelector('.note-clamped'), path: location.pathname }; }, LONG.id); + check('its thread shows it whole', inThread.n > 0 && !inThread.clamped && inThread.path.includes('nevent') || inThread.path.includes('note1'), JSON.stringify(inThread)); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ really long notes collapse' : '\n❌ failed'); +process.exit(ok ? 0 : 1); diff --git a/tools/hats-santa-test.js b/tools/hats-santa-test.js new file mode 100644 index 0000000..a9966e1 --- /dev/null +++ b/tools/hats-santa-test.js @@ -0,0 +1,70 @@ +// A free Santa hat for everyone, through December. "Let's add a free Santa +// hat to the hat shop for everyone. Available only through the month of +// December." (Adam, 2026-12-01). The registrar says which hats are free right +// now (/hats/<pk> → free: ['santa']); the shop lists the Santa hat first with +// a Free button that takes it (POST /hats/free, no invoice) and puts it on. +// Out of season (free: []) the Santa hat isn't listed unless you own it. +// Run: bun tools/hats-santa-test.js +import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js'; +import { buildHtml } from '../build.js'; +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 html = await buildHtml({ minify: true, pwa: false }); +const server = Bun.serve({ port: 5349, 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'] }); +const page = await browser.newPage(); +const errs = []; +page.on('pageerror', (e) => errs.push(String(e))); +// the registrar, mocked +let season = true, rec = { owned: [], equipped: null }, taken = null; +await page.setRequestInterception(true); +const cors = { 'access-control-allow-origin': '*', 'access-control-allow-headers': 'content-type,authorization', 'access-control-allow-methods': 'GET,POST,OPTIONS' }; +page.on('request', (r) => { + const u = new URL(r.url()); + if (u.hostname !== 'names.coinos.io' || !u.pathname.startsWith('/hats')) return r.continue(); + const send = (b) => r.respond({ status: 200, contentType: 'application/json', headers: cors, body: JSON.stringify(b) }); + if (r.method() === 'OPTIONS') return send({}); + if (u.pathname === '/hats/free' && r.method() === 'POST') { + taken = { body: JSON.parse(r.postData() || '{}'), auth: r.headers().authorization || '' }; + rec = { owned: ['santa'], equipped: 'santa' }; + return send(rec); + } + if (/^\/hats\/[0-9a-f]{64}$/.test(u.pathname)) return send({ ...rec, prices: { beanie: 21, trucker: 2100 }, free: season ? ['santa'] : [] }); + if (u.pathname === '/hats/worn') return send({ hats: {} }); + return send({ hats: {} }); +}); +const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase() === x); if (e) { e.click(); return true; } return false; }, t); +const text = () => page.evaluate(() => document.body.innerText); +const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await text()).includes(x)) return true; await sleep(250); } return false; }; +try { + await page.setViewport({ width: 390, height: 844 }); + await page.goto('http://localhost:5349/', { waitUntil: 'domcontentloaded' }); + await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest')); + await page.goto('http://localhost:5349/', { waitUntil: 'domcontentloaded' }); + await waitText('Create a new wallet', 20000); await sleep(400); + await page.evaluate(() => [...document.querySelectorAll('button')].find((n) => /create a new wallet/i.test(n.textContent))?.click()); await sleep(600); + await seedWords(page); await skipSeedCheck(page); await sleep(1500); + await page.goto('http://localhost:5349/hats', { waitUntil: 'domcontentloaded' }); + check('in December the shop lists the Santa hat', await waitText('Santa hat')); + const t1 = await text(); + check('...first, ahead of the Toque', t1.indexOf('Santa hat') < t1.indexOf('Toque')); + check('...saying it is free through December', t1.includes('Free for everyone through December')); + check('...with a Free button', await click('free')); + check('taking it puts it on', await waitText('Wearing ✓', 10000)); + check('...through POST /hats/free for the santa hat, NIP-98 signed', taken && taken.body.hat === 'santa' && /^Nostr /.test(taken.auth), JSON.stringify(taken?.body)); + check('...and says it is yours', (await text()).includes('Santa hat is yours')); + // out of season, a head without one sees no Santa hat at all + season = false; rec = { owned: [], equipped: null }; + await page.goto('http://localhost:5349/hats', { waitUntil: 'domcontentloaded' }); + await waitText('Toque'); + check('out of season the Santa hat is not listed', !(await text()).includes('Santa hat')); + // ...but one already taken stays in the rack + rec = { owned: ['santa'], equipped: null }; + await page.goto('http://localhost:5349/hats', { waitUntil: 'domcontentloaded' }); + await waitText('Toque'); + check('...unless you took one: it stays in your rack', (await text()).includes('Santa hat') && (await text()).includes('In your hat rack')); + check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | ')); +} finally { await browser.close(); server.stop(true); } +console.log(ok ? '\n✅ free Santa hat' : '\n❌ failed'); +process.exit(ok ? 0 : 1); |
