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>
This commit is contained in:
+19
-8
@@ -27,32 +27,43 @@ async function lastBroadcastAt(fromEmail) {
|
||||
return mine.length ? Math.max(...mine) : 0;
|
||||
}
|
||||
// deliver one message to many recipients (already-resolved emails). Returns count.
|
||||
async function deliver(fromMember, fromEmail, recipients, subject, body) {
|
||||
//
|
||||
// `kind` separates the two things that used to share this channel:
|
||||
// 'broadcast' — a person wrote it to their team. Rare, and worth interrupting for.
|
||||
// 'notice' — the system generated it (payout landed, purchase confirmed, and so on).
|
||||
// These arrive constantly, so they belong in the inbox and must never pop
|
||||
// a modal. Before this split they did, which meant a member with a backlog
|
||||
// of payout notices got a fresh popup after every single ad view.
|
||||
async function deliver(fromMember, fromEmail, recipients, subject, body, kind) {
|
||||
const k = kind === 'notice' ? 'notice' : 'broadcast';
|
||||
const now = Date.now();
|
||||
let n = 0;
|
||||
if (db.enabled()) {
|
||||
for (const to of recipients) {
|
||||
await db.q("INSERT INTO sponsor_messages (from_member,from_email,to_email,subject,body,sent,kind) VALUES (?,?,?,?,?,?,'broadcast')",
|
||||
[fromMember || 0, fromEmail, to, subject, body, now]);
|
||||
await db.q("INSERT INTO sponsor_messages (from_member,from_email,to_email,subject,body,sent,kind) VALUES (?,?,?,?,?,?,?)",
|
||||
[fromMember || 0, fromEmail, to, subject, body, now, k]);
|
||||
n++;
|
||||
}
|
||||
} else {
|
||||
if (!J.db) J.load();
|
||||
for (const to of recipients) {
|
||||
J.db.items.push({ id: J.db.nextId++, kind: 'broadcast', fromMember: fromMember || 0, fromEmail, toEmail: to, subject, body, sent: now, readTs: 0 });
|
||||
J.db.items.push({ id: J.db.nextId++, kind: k, fromMember: fromMember || 0, fromEmail, toEmail: to, subject, body, sent: now, readTs: 0 });
|
||||
n++;
|
||||
}
|
||||
J.save();
|
||||
}
|
||||
return n;
|
||||
}
|
||||
const isBroadcast = i => (i.kind || 'broadcast') === 'broadcast';
|
||||
// Both kinds are inbox mail; only 'chat' is the separate two-way thread.
|
||||
const isBroadcast = i => (i.kind || 'broadcast') !== 'chat';
|
||||
// ...but only a message a PERSON wrote may interrupt with the modal.
|
||||
const isHuman = i => (i.kind || 'broadcast') === 'broadcast';
|
||||
const isChat = i => i.kind === 'chat';
|
||||
async function inbox(email) {
|
||||
const e = String(email || '').toLowerCase();
|
||||
if (db.enabled()) {
|
||||
const rows = await db.q(`SELECT id, from_member, subject, body, sent, read_ts FROM sponsor_messages
|
||||
WHERE to_email=? AND kind='broadcast' ORDER BY sent DESC LIMIT 100`, [e]);
|
||||
WHERE to_email=? AND kind<>'chat' ORDER BY sent DESC LIMIT 100`, [e]);
|
||||
return rows.map(r => ({ id: r.id, fromMember: r.from_member, subject: r.subject, body: r.body,
|
||||
sent: Number(r.sent), read: !!r.read_ts }));
|
||||
}
|
||||
@@ -145,7 +156,7 @@ async function threadList(email) {
|
||||
async function unreadCount(email) {
|
||||
const e = String(email || '').toLowerCase();
|
||||
if (db.enabled()) {
|
||||
const r = await db.q("SELECT COUNT(*) n FROM sponsor_messages WHERE to_email=? AND kind='broadcast' AND read_ts IS NULL", [e]);
|
||||
const r = await db.q("SELECT COUNT(*) n FROM sponsor_messages WHERE to_email=? AND kind<>'chat' AND read_ts IS NULL", [e]);
|
||||
return r[0].n;
|
||||
}
|
||||
if (!J.db) J.load();
|
||||
@@ -162,7 +173,7 @@ async function newestUnread(email) {
|
||||
return { id: r.id, fromMember: r.from_member, subject: r.subject, body: r.body, sent: Number(r.sent) };
|
||||
}
|
||||
if (!J.db) J.load();
|
||||
const u = J.db.items.filter(i => i.toEmail === e && isBroadcast(i) && !i.readTs).sort((a, b) => b.sent - a.sent)[0];
|
||||
const u = J.db.items.filter(i => i.toEmail === e && isHuman(i) && !i.readTs).sort((a, b) => b.sent - a.sent)[0];
|
||||
return u ? { id: u.id, fromMember: u.fromMember, subject: u.subject, body: u.body, sent: u.sent } : null;
|
||||
}
|
||||
async function markRead(email, id) {
|
||||
|
||||
Reference in New Issue
Block a user