aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/socket.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-11-16 00:21:08 -0800
committerAdam Soltys <[email protected]>2023-11-16 00:21:08 -0800
commit5a13331a525fa298c1b7435db5e468138ba8572e (patch)
tree4b68c57868532a75036aa272fa18b0e4d0d65e68 /src/lib/socket.js
parent96c67006bde6fa5a9d92edcb84e48744e0a36cf5 (diff)
downloadcoinos-ui-5a13331a525fa298c1b7435db5e468138ba8572e.tar.gz
coinos-ui-5a13331a525fa298c1b7435db5e468138ba8572e.zip
ui tweaks
Diffstat (limited to 'src/lib/socket.js')
0 files changed, 0 insertions, 0 deletions
d */ .highlight .ch { color: #888 } /* Comment.Hashbang */ .highlight .cm { color: #888 } /* Comment.Multiline */ .highlight .cp { color: #C00; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888 } /* Comment.Single */ .highlight .cs { color: #C00; font-weight: bold; background-color: #FFF0F0 } /* Comment.Special */ .highlight .gd { color: #000; background-color: #FDD } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #A00 } /* Generic.Error */ .highlight .gh { color: #333 } /* Generic.Heading */ .highlight .gi { color: #000; background-color: #DFD } /* Generic.Inserted */ .highlight .go { color: #888 } /* Generic.Output */ .highlight .gp { color: #555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666 } /* Generic.Subheading */ .highlight .gt { color: #A00 } /* Generic.Traceback */ .highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Sensitive posts: Popular (everyone's public feed) leaves out posts their
// authors marked with a content warning (NIP-36 — what a Misskey artist's
// "sensitive" media becomes over mostr), NSFW-tagged posts, and posts from
// accounts whose own profile says they post adult work. Elsewhere a marked
// post is folded behind its warning with a Show.
// Run: bun tools/sensitive-feed-test.js
import puppeteer from './puppeteer.js';
import { cacheKeyFor } from '../src/wallet.js';
import { finalizeEvent, generateSecretKey, getPublicKey } from 'nostr-tools/pure';
import { buildHtml, buildVerifyWorker } 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 A = key(), ART = key(), B = key();
const now = Math.floor(Date.now() / 1000);
const post = (who, text, ago, tags = []) => finalizeEvent({ kind: 1, created_at: now - ago, tags, content: text }, who.sk);
const SAFE = post(A, 'This is a perfectly ordinary post about the weather and the bitcoin price today', 100);
const CW = post(A, 'This post was marked sensitive by its author for everyone to see', 200, [['content-warning', 'spoilers']]);
const TAGGED = post(B, 'This post carries the nsfw hashtag and should not be in the public feed', 300, [['t', 'nsfw']]);
const ARTIST = post(ART, 'This is a drawing I made for the autumn campaign please enjoy it', 400);
const SAFE2 = post(B, 'Another ordinary post that everybody should see in the public feed', 500);
const PROFILES = [
  finalizeEvent({ kind: 0, created_at: now, tags: [], content: JSON.stringify({ name: 'Plain Person' }) }, A.sk),
  finalizeEvent({ kind: 0, created_at: now, tags: [], content: JSON.stringify({ name: 'Artist', about: 'I draw things :role_nsfw: so please be 18 or older' }) }, ART.sk),
  finalizeEvent({ kind: 0, created_at: now, tags: [], content: JSON.stringify({ name: 'Other Person' }) }, B.sk),
];
const html = await buildHtml({ minify: true, pwa: false });
const worker = await buildVerifyWorker({ minify: true });
const server = Bun.serve({ port: 0, fetch(req) {
  const path = new URL(req.url).pathname;
  if (path === '/api/feed') return Response.json({ version: 1, generatedAt: Date.now(), popUntil: now - 1000, notes: [SAFE, CW, TAGGED, ARTIST, SAFE2], profiles: PROFILES });
  if (path === '/verify-worker.js') return new Response(worker, { headers: { 'Content-Type': 'text/javascript' } });
  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 shim = () => {
  const Real = window.WebSocket;
  window.WebSocket = function (...a) {
    const ws = new Real(...a);
    const send = ws.send.bind(ws);
    ws.send = (data) => {
      try { const m = JSON.parse(data); 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(data);
    };
    return ws;
  };
  window.WebSocket.prototype = Real.prototype; Object.assign(window.WebSocket, Real);
};
const errs = [];
try {
  console.log('\n[Popular]');
  let page = await browser.newPage();
  page.on('pageerror', (e) => errs.push(String(e)));
  await page.evaluateOnNewDocument(shim);
  await page.goto(server.url.origin + '/feed');
  await page.waitForFunction(() => document.body.innerText.includes('perfectly ordinary post'), { timeout: 15000 }).catch(() => {});
  await sleep(1500);
  let text = await page.evaluate(() => document.body.innerText);
  check('ordinary posts are there', text.includes('perfectly ordinary post') && text.includes('Another ordinary post'));
  check('a post marked sensitive is left out', !text.includes('marked sensitive by its author'));
  check('...and an #nsfw one', !text.includes('carries the nsfw hashtag'));
  check('...and one from an account whose profile says adult content', !text.includes('a drawing I made'));
  await page.close();

  console.log('\n[a followed person\'s marked post]');
  page = await browser.newPage();
  page.on('pageerror', (e) => errs.push(String(e)));
  await page.evaluateOnNewDocument(shim);
  await page.setViewport({ width: 390, height: 844 });
  await page.goto(server.url.origin + '/', { waitUntil: 'domcontentloaded' });
  await page.evaluate(() => localStorage.setItem('btc-wallet-network', 'regtest'));
  await page.reload({ waitUntil: 'domcontentloaded' });
  await sleep(400);
  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);
  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 page.waitForFunction(() => /receive/i.test(document.body.innerText), { timeout: 20000 });
  await sleep(3000); // the starter follows land first
  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: 'Plain Person', t: Date.now() } }));
    localStorage.setItem('btc-wallet-feed:' + k, 'following');
  }, [base, A.pk, [SAFE, CW]]);
  await page.reload({ waitUntil: 'domcontentloaded' });
  await page.waitForFunction(() => /receive/i.test(document.body.innerText), { timeout: 20000 });
  await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Feed"]').click());
  await page.waitForFunction(() => document.body.innerText.includes('perfectly ordinary post'), { timeout: 15000 }).catch(() => {});
  await sleep(800);
  text = await page.evaluate(() => document.body.innerText);
  check('the marked post is folded behind its warning', text.includes('Sensitive: spoilers') && !text.includes('marked sensitive by its author'), (text.match(/Sensitive[^\n]*/) || [''])[0]);
  await page.evaluate(() => [...document.querySelectorAll('.note-folded button')].find((b) => /show/i.test(b.textContent)).click());
  await sleep(400);
  check('Show opens it', (await page.evaluate(() => document.body.innerText)).includes('marked sensitive by its author'));
  check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
} finally { await browser.close(); server.stop(true); }
console.log(ok ? '\n✅ sensitive posts stay out of Popular, folded elsewhere' : '\n❌ failed');
process.exit(ok ? 0 : 1);