Files
instantadpay/qa/messages-notice.mjs
T
martbost a2c77d01d1 Stop payout notices interrupting members who are earning
Marty hit this viewing daily ads: a popup after every single return to
the dashboard, each one a different payout notice.

Two causes, both fixed.

The channel was shared. "You just got paid 40.8923 POL" and "Welcome to
my line, here are your first three moves" were stored identically, as
kind 'broadcast' — the kind the sign-in modal is meant to interrupt for.
Dismissing one just promoted the next unread notice, so a backlog became
a carousel. System messages are now kind 'notice': they land in the
inbox, count toward its badge, and never pop. Only a message a person
actually wrote can interrupt.

The modal also had no memory. loadDashboard() runs on far more than
sign-in — after every ad view, campaign edit and chat close — and it
re-popped each time. It now shows at most once per page load and never
twice for the same message.

The 79 existing machine-generated rows are retagged by a migration in
ensureSchema, 15 of them unread and currently popping. Matched on
subject rather than sender on purpose: these come from member 1 at
ADMIN_EMAIL, which is also Marty's own member address, so his genuine
broadcasts sit under the same sender and must be left alone. Verified
against the live data first — "Credits returned: a counting error on our
side" and the broken-banner note are his, and stay as broadcasts.

qa/messages-notice.mjs covers it: a flood of 25 notices produces no
interruption, the human message still does, and chat stays in its own
lane. Member walk clean.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 08:09:50 -05:00

67 lines
3.3 KiB
JavaScript

// The sign-in modal must interrupt for a message a PERSON wrote, and never for a
// system notice. Regression for the 2026-09-18 report: a member viewing daily ads got a
// fresh popup after every single view, because every payout notice was stored as a
// 'broadcast' and loadDashboard() re-pops on each refresh.
//
// node qa/messages-notice.mjs (JSON mode, no DB needed)
import { createRequire } from 'node:module';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
const require = createRequire(import.meta.url);
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'iap-msg-'));
const messages = require('../messages.js');
messages.init({ dataDir: dir });
const ok = [], bad = [];
const t = (n, c, extra) => { (c ? ok : bad).push(n + (c || !extra ? '' : ' -> ' + extra)); };
const ME = 'earner@example.com';
// a real sponsor writing to their team
await messages.deliver(36, 'sponsor@example.com', [ME], 'Welcome to my line', '<p>hi</p>');
// the system, reporting money that moved
await messages.deliver(1, 'house@instantadpay.com', [ME], 'You just got paid 40.8923 POL on InstantAdPay', '<p>paid</p>', 'notice');
await messages.deliver(1, 'house@instantadpay.com', [ME], 'You missed 43.06 POL on InstantAdPay', '<p>missed</p>', 'notice');
const box = await messages.inbox(ME);
t('every message reaches the inbox', box.length === 3, String(box.length));
t('the inbox badge counts notices too', (await messages.unreadCount(ME)) === 3, String(await messages.unreadCount(ME)));
// the whole point
const un = await messages.newestUnread(ME);
t('the modal picks the human message, not the payout notice',
un && un.subject === 'Welcome to my line', un && un.subject);
// acknowledge it; nothing should be left to interrupt with
await messages.markRead(ME, un.id);
const after = await messages.newestUnread(ME);
t('once acknowledged, nothing else pops', after === null, after && after.subject);
t('but the notices are still unread in the inbox', (await messages.unreadCount(ME)) === 2,
String(await messages.unreadCount(ME)));
// a flood of notices must never produce a single interruption
for (let i = 0; i < 25; i++) {
await messages.deliver(1, 'house@instantadpay.com', [ME], 'You just got paid ' + i + ' POL on InstantAdPay', '<p>x</p>', 'notice');
}
t('25 more payout notices still pop nothing', (await messages.newestUnread(ME)) === null);
t('and they all show up in the inbox', (await messages.inbox(ME)).length === 28,
String((await messages.inbox(ME)).length));
// an untagged deliver is still treated as a human broadcast (back-compat)
await messages.deliver(36, 'sponsor@example.com', [ME], 'Team call tonight', '<p>call</p>');
const un2 = await messages.newestUnread(ME);
t('an untagged message still interrupts, as before', un2 && un2.subject === 'Team call tonight', un2 && un2.subject);
// chat never pops the modal and never lands in the inbox list
await messages.sendChat(36, 'sponsor@example.com', ME, 'you around?');
t('chat stays out of the inbox list', (await messages.inbox(ME)).length === 29,
String((await messages.inbox(ME)).length));
t('chat is counted separately', (await messages.chatUnread(ME)) === 1, String(await messages.chatUnread(ME)));
fs.rmSync(dir, { recursive: true, force: true });
console.log('PASS ' + ok.length);
for (const b of bad) console.log('FAIL ' + b);
process.exit(bad.length ? 1 : 0);