aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/features/messages.js23
-rw-r--r--tools/own-boost-feed-test.js104
2 files changed, 120 insertions, 7 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 57f0e23..03fabee 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -7771,22 +7771,28 @@ export function messagesFeature(ctx) {
if (!staged) feedStaged.set(c, staged = new Set());
// (with those waiting a moment to go in together — admitQueues — or a
// copy from a second relay, or another version of a clip, slips in)
+ const noteOf = (e) => (e.kind === REPOST ? repostInner(e) : e);
+ // Your own boost is the exception: it has a row of its own at the time
+ // you boosted, whether or not the post is in the feed already, and it
+ // doesn't keep the post itself (or someone else's repost of it) out.
+ const own = (e) => e.kind === REPOST && isMe(e.pubkey);
const held = [...c.notes, ...(c.deferred || []), ...((admitQueues.get(c) || {}).evs || [])];
const known = new Set(held.map((e) => e.id));
for (const e of evs || []) noteForSpam(e);
// A note shows once: as itself, or under the first repost of it to
// arrive — counting the ones still warming at the door.
// (`staged` holds the note's id too, for a repost)
- const noteOf = (e) => (e.kind === REPOST ? repostInner(e) : e);
- const notesIn = new Set(held.map((e) => noteOf(e)?.id).filter(Boolean));
+ const notesIn = new Set(held.filter((e) => !own(e)).map((e) => noteOf(e)?.id).filter(Boolean));
+ const boostedIn = new Set(held.filter(own).map((e) => noteOf(e)?.id).filter(Boolean));
// an addressable post (a 34235/34236 clip) once, however many versions of it come
- for (const e of held) { const a = noteOf(e) && addrOf(noteOf(e)); if (a) notesIn.add(a); }
- const addrNew = (e) => { const n = noteOf(e); const a = n && addrOf(n); return !a || (!notesIn.has(a) && !staged.has(a) && !!staged.add(a)); };
- const fresh = (e) => { const n = noteOf(e); return !!n && !notesIn.has(n.id) && !staged.has(n.id); };
- const unstage = (e) => { staged.delete(e.id); const n = noteOf(e); if (n) { staged.delete(n.id); const a = addrOf(n); if (a) staged.delete(a); } };
+ for (const e of held) { const a = !own(e) && noteOf(e) && addrOf(noteOf(e)); if (a) notesIn.add(a); }
+ const addrNew = (e) => { const n = noteOf(e); const a = !own(e) && n && addrOf(n); return !a || (!notesIn.has(a) && !staged.has(a) && !!staged.add(a)); };
+ const stageId = (e) => (own(e) ? 'own:' : '') + noteOf(e).id;
+ const fresh = (e) => { const n = noteOf(e); return !!n && !(own(e) ? boostedIn : notesIn).has(n.id) && !staged.has(stageId(e)); };
+ const unstage = (e) => { staged.delete(e.id); const n = noteOf(e); if (n) { staged.delete(stageId(e)); const a = !own(e) && addrOf(n); if (a) staged.delete(a); } };
const def = feedDef(c.id);
let add = (evs || []).filter((e) => (e.kind === REPOST ? !(def && def.replies) && !!repostInner(e) && !hidden(repostInner(e)) && !reboosted(e) : feedKeeps(def, e)) && !hidden(e)
- && fresh(e) && !known.has(e.id) && !staged.has(e.id) && addrNew(e) && known.add(e.id) && staged.add(e.id) && staged.add(noteOf(e).id));
+ && fresh(e) && !known.has(e.id) && !staged.has(e.id) && addrNew(e) && known.add(e.id) && staged.add(e.id) && staged.add(stageId(e)));
if (def && def.search) add = add.filter((e) => !nearCopy(c, held, e));
if (!add.length) return false;
if (def && def.curated) {
@@ -11823,6 +11829,9 @@ export function messagesFeature(ctx) {
const evt = id.signer instanceof Uint8Array ? finalizeEvent(partial, id.signer) : await id.signer.signEvent(partial);
noteEvent(evt);
render();
+ // in the feeds that carry your posts now, as your own post is
+ const carries = (def) => !!def && !def.replies && (!!def.all || feedAuthors(def).includes(id.pubkey));
+ for (const c of new Set([feed, feedStates.get(FOLLOWING)])) if (c && !c.stopped && carries(feedDef(c.id))) mergeFeed([evt], {}, c).catch(() => {});
const ok = await publishOn(relays, evt);
toast(ok ? t('postBoosted') : t('msgSendFailed'));
}
diff --git a/tools/own-boost-feed-test.js b/tools/own-boost-feed-test.js
new file mode 100644
index 0000000..e5e3440
--- /dev/null
+++ b/tools/own-boost-feed-test.js
@@ -0,0 +1,104 @@
+// Your own boost shows in your feed. "I tried boosting this post but I don't
+// see it in my feed" (Adam, 2026-11-22): the post was already in Following
+// (he follows its author), and a note shows once, so his boost was folded
+// away. "We dedupe other boosts right? so maybe make an exception for our
+// own": my boost has its own row at the time I boosted, under "<me>
+// reposted", and the post itself stays where it was.
+// Run: bun tools/own-boost-feed-test.js
+import puppeteer, { seedWords, skipSeedCheck } from './puppeteer.js';
+import { cacheKeyFor } from '../src/wallet.js';
+import { generateSecretKey, getPublicKey, finalizeEvent } from 'nostr-tools/pure';
+import { privateKeyFromSeedWords } from 'nostr-tools/nip06';
+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 PNK = key(), FILLER = key();
+const now = Math.floor(Date.now() / 1000);
+const note = (who, content, ago) => finalizeEvent({ kind: 1, created_at: now - ago, tags: [], content }, who.sk);
+const PAFF = note(PNK, 'Running a PAFF server on my phone pledging storage', 72000);
+const POSTS = [PAFF, ...Array.from({ length: 12 }, (_, i) => note(FILLER, `filler post number ${i + 1} with words enough to tell apart ${'abcdefghijkl'[i].repeat(6)}`, 600 + i * 900))];
+const html = await buildHtml({ minify: true, pwa: false });
+const server = Bun.serve({ port: 5347, 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({ relays: 'read', executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
+const page = await browser.newPage();
+await page.evaluateOnNewDocument((fx) => {
+ const Real = window.WebSocket;
+ const fits = (ev, f) => (!f.kinds || f.kinds.includes(ev.kind)) && (!f.authors || f.authors.includes(ev.pubkey)) && (!f.ids || f.ids.includes(ev.id));
+ const pubd = () => { try { return JSON.parse(localStorage.getItem('__pub') || '[]'); } catch { return []; } };
+ window.WebSocket = function (...a) {
+ const ws = new Real(...a); const send = ws.send.bind(ws);
+ const say = (m) => ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(m) }));
+ ws.send = (d) => {
+ try {
+ const m = JSON.parse(d);
+ if (m[0] === 'REQ') { const fs = m.slice(2); setTimeout(() => { if (window.__live) for (const ev of fx.concat(pubd()).filter((e) => fs.some((f) => fits(e, f)))) say(['EVENT', m[1], ev]); say(['EOSE', m[1]]); }, 0); return; }
+ if (m[0] === 'EVENT') { if (m[1].kind === 6) { const all = pubd(); if (!all.some((e) => e.id === m[1].id)) localStorage.setItem('__pub', JSON.stringify([...all, m[1]])); } setTimeout(() => say(['OK', m[1].id, true, '']), 0); return; }
+ } catch {}
+ return send(d);
+ };
+ return ws;
+ };
+ window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real);
+}, POSTS);
+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 text = () => page.evaluate(() => document.body.innerText);
+const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await text()).toLowerCase().includes(x.toLowerCase())) return true; await sleep(250); } return false; };
+const rows = () => page.evaluate(() => [...document.querySelectorAll('.notes-feed > .row[data-key]')].map((r) => ({ paff: r.textContent.includes('Running a PAFF server'), reposted: /reposted/.test(r.querySelector('.note-reposted')?.textContent || '') })));
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto('http://localhost:5347/', { 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, p, f]) => {
+ localStorage.setItem(k + ':follows', JSON.stringify({ tags: [['p', p], ['p', f]], c: '', at: Math.floor(Date.now() / 1000) }));
+ localStorage.setItem(k + ':profiles', JSON.stringify({ [p]: { name: 'pnk', t: Date.now() }, [f]: { name: 'Filler', t: Date.now() } }));
+ localStorage.setItem('btc-wallet-feed:' + k, 'following');
+ }, [base, PNK.pk, FILLER.pk]);
+ await page.evaluateOnNewDocument(() => { window.__live = true; });
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click());
+ check('the followed post is in the feed', await waitText('Running a PAFF server', 30000));
+ await sleep(1500);
+ let r = await rows();
+ check('...once, below newer posts, not as a repost', r.filter((x) => x.paff).length === 1 && r.findIndex((x) => x.paff) > 3 && !r.find((x) => x.paff).reposted, JSON.stringify(r.map((x) => +x.paff)));
+ const tapped = await page.evaluate(() => { const row = [...document.querySelectorAll('.notes-feed > .row[data-key]')].find((n) => n.textContent.includes('Running a PAFF server')); const b = row && [...row.querySelectorAll('.note-acts button')].find((x) => /boost/i.test(x.getAttribute('aria-label') || x.title || '')); if (b) { b.click(); return true; } return false; });
+ check('Boost tapped', tapped);
+ let top = null;
+ for (let i = 0; i < 40; i++) { r = await rows(); top = r[0]; if (top && top.paff && top.reposted) break; await sleep(250); }
+ check('the boost is at the top of my feed, under "… reposted"', !!top && top.paff && top.reposted, JSON.stringify(r.slice(0, 3)));
+ check('the row I tapped is still where it was', r.filter((x) => x.paff).length === 2);
+ check('the boost was published', await page.evaluate(() => JSON.parse(localStorage.getItem('__pub') || '[]').length === 1));
+ await sleep(1500); // the feed cache is written
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click());
+ await waitText('Running a PAFF server', 30000);
+ await sleep(4000);
+ r = await rows();
+ const both = (r) => !!r[0] && r[0].paff && r[0].reposted && r.filter((x) => x.paff).length === 2 && r.filter((x) => x.paff && x.reposted).length === 1 && r[r.length - 1].paff && !r[r.length - 1].reposted;
+ check('after a reload: my boost first (the newest), the post itself still in its place', both(r), JSON.stringify(r.map((x) => [+x.paff, +x.reposted])));
+ // a second device: nothing cached, the post and the boost both come from relays
+ await page.evaluate(() => { for (const k of Object.keys(localStorage)) if (/feed-cache|feedcache|:feed:|notes/i.test(k)) localStorage.removeItem(k); });
+ await page.evaluate(async () => { if (indexedDB.databases) for (const d of await indexedDB.databases()) if (/feed|note/i.test(d.name || '')) indexedDB.deleteDatabase(d.name); });
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]')?.click());
+ await waitText('Running a PAFF server', 30000);
+ await sleep(4000);
+ r = await rows();
+ check('with no cache: the same two rows', both(r), JSON.stringify(r.map((x) => [+x.paff, +x.reposted])));
+ check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ my own boost shows in my feed' : '\n❌ failed');
+process.exit(ok ? 0 : 1);