aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/features/messages.js28
-rw-r--r--tools/notif-custom-emoji-test.js96
2 files changed, 118 insertions, 6 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 0a14b9c..cedd8db 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -13706,8 +13706,11 @@ export function messagesFeature(ctx) {
if (my.includes(ev.pubkey)) return null;
if (ev.kind === 7) {
if (!lastE) return null;
- const emoji = !ev.content || ev.content === '+' ? '\u2764\ufe0f' : ev.content.slice(0, 12);
- return { id: ev.id, what: 'react', actor: ev.pubkey, target: lastE, hint, emoji, ts: ev.created_at };
+ // a :shortcode: keeps its whole name and the picture its NIP-30 tag names
+ const code = shortcodeOf(ev.content || '');
+ const tag = code && (ev.tags || []).find((x) => x[0] === 'emoji' && x[1] === code && /^https?:\/\//.test(x[2] || ''));
+ const emoji = !ev.content || ev.content === '+' ? '\u2764\ufe0f' : code ? ev.content.slice(0, 64) : ev.content.slice(0, 12);
+ return { id: ev.id, what: 'react', actor: ev.pubkey, target: lastE, hint, emoji, emojiUrl: tag ? tag[2] : undefined, ts: ev.created_at };
}
if (ev.kind === 6) return lastE ? { id: ev.id, what: 'boost', actor: ev.pubkey, target: lastE, hint, ts: ev.created_at } : null;
if (ev.kind === COMMENT) {
@@ -13727,9 +13730,16 @@ export function messagesFeature(ctx) {
const c = notifNow();
const known = new Set(c.items.map((x) => x.id));
for (const ev of evs) noteForSpam(ev);
- const add = evs.map((ev) => ((ev.kind === 1 || ev.kind === COMMENT) && hidden(ev) ? null : notifItem(ev)))
- .filter((x) => x && !hiddenPk(x.actor) && !known.has(x.id) && known.add(x.id));
- if (!add.length) return false;
+ const items = evs.map((ev) => ((ev.kind === 1 || ev.kind === COMMENT) && hidden(ev) ? null : notifItem(ev)));
+ // a custom-emoji reaction saved before rows kept its picture gets it now
+ let healed = false;
+ for (const x of items) {
+ if (!x || !x.emojiUrl || !known.has(x.id)) continue;
+ const old = c.items.find((y) => y.id === x.id);
+ if (old && !old.emojiUrl) { old.emojiUrl = x.emojiUrl; old.emoji = x.emoji; healed = true; }
+ }
+ const add = items.filter((x) => x && !hiddenPk(x.actor) && !known.has(x.id) && known.add(x.id));
+ if (!add.length) { if (healed) persistNotifs(); return healed; }
warmNotifFaces(add);
// One zap, two receipts: a coinos zap publishes its own (9737) beside the
// LNURL server's (9735). The same person, post and amount within a few
@@ -13822,7 +13832,13 @@ export function messagesFeature(ctx) {
}
function notifLabel(x) {
if (x.what === 'zap') return t('alertZap', { sats: fmtSats(x.sats) + ' sats' });
- if (x.what === 'react') return t('alertReact', { emoji: x.emoji });
+ if (x.what === 'react') {
+ const code = shortcodeOf(x.emoji);
+ const url = code && (x.emojiUrl || emojiUrl(code));
+ if (!url) return t('alertReact', { emoji: x.emoji });
+ const [a, b = ''] = t('alertReact', { emoji: '\u0000' }).split('\u0000');
+ return h('span', {}, a, reactImg(code, url), b);
+ }
if (x.what === 'boost') return t('alertBoost');
if (x.what === 'reply') return t('alertReply');
return t('alertMention');
diff --git a/tools/notif-custom-emoji-test.js b/tools/notif-custom-emoji-test.js
new file mode 100644
index 0000000..5847a0c
--- /dev/null
+++ b/tools/notif-custom-emoji-test.js
@@ -0,0 +1,96 @@
+// Notifications: a custom-emoji reaction (NIP-30, ":peepoClap:" with an
+// emoji tag) reads "reacted" plus its picture — it showed the bare
+// :peepoClap: text, because the row kept the content and not the tag.
+// A row saved before that is healed when the relay hands the reaction again.
+// Run: bun tools/notif-custom-emoji-test.js
+import puppeteer 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 A = generateSecretKey(), B = generateSecretKey();
+const now = Math.floor(Date.now() / 1000);
+const PNG = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==', 'base64');
+const html = await buildHtml({ minify: true, pwa: false });
+const server = Bun.serve({ port: 5313, fetch: (req) => {
+ const path = new URL(req.url).pathname;
+ if (path.endsWith('.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 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)));
+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; };
+
+try {
+ await page.setViewport({ width: 390, height: 844 });
+ await page.goto('http://localhost:5313/', { 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');
+ const ME = getPublicKey(privateKeyFromSeedWords(mn));
+ const target = 't'.repeat(64);
+ const react = (sk, code, ts) => finalizeEvent({ kind: 7, created_at: ts, content: ':' + code + ':',
+ tags: [['e', target], ['p', ME], ['emoji', code, 'http://localhost:5313/' + code + '.png']] }, sk);
+ const OLD = react(A, 'peepoClap', now - 120); // saved by the old code, as text
+ const NEW = react(B, 'aVeryLongShortcodeName', now - 60); // new: arrives from the relay
+ await page.evaluateOnNewDocument((evs) => {
+ 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') {
+ const fs = m.slice(2);
+ const hit = evs.filter((ev) => fs.some((f) => (f.kinds || []).includes(7) && (f['#p'] || []).length));
+ setTimeout(() => {
+ for (const e of hit) ws.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EVENT', m[1], e]) }));
+ 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);
+ }, [OLD, NEW]);
+ await page.evaluate(([k, me, old, target]) => {
+ const st = JSON.parse(localStorage.getItem(k + ':messages') || '{}');
+ st.notifs = [{ id: old.id, what: 'react', actor: old.pubkey, target, hint: [], emoji: ':peepoClap:', ts: old.created_at }];
+ st.notifsPk = me; st.notifsV = 2;
+ localStorage.setItem(k + ':messages', JSON.stringify(st));
+ }, [base, ME, OLD, target]);
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await waitText('receive', 20000);
+ await page.evaluate(() => document.querySelector('.app-nav-button[aria-label="Notifications"]')?.click());
+ let imgs = [];
+ for (let i = 0; i < 60; i++) {
+ imgs = await page.evaluate(() => [...document.querySelectorAll('.alert-row img.cemoji')].map((e) => e.getAttribute('alt')));
+ if (imgs.length >= 2) break;
+ await sleep(250);
+ }
+ console.log('\n[custom-emoji reactions in Notifications]');
+ check('a reaction arriving now shows its picture, whole name kept', imgs.includes(':aVeryLongShortcodeName:'), JSON.stringify(imgs));
+ check('a row saved as text gets its picture once the relay hands it again', imgs.includes(':peepoClap:'), JSON.stringify(imgs));
+ const txt = await page.evaluate(() => [...document.querySelectorAll('.alert-row')].map((r) => r.innerText).join(' | '));
+ check('no bare :shortcode: text left', !/:peepoClap:|:aVeryLong/.test(txt), txt.slice(0, 200));
+ check('no page errors', errs.length === 0, errs.slice(0, 2).join(' | '));
+} finally { await browser.close(); server.stop(true); }
+console.log(ok ? '\n✅ custom-emoji reactions show their pictures' : '\n❌ failed');
+process.exit(ok ? 0 : 1);