Admin member card: Message (inbox + email) button (Marty 2026-11-12). POST /api/admin/member/message puts a broadcast in the member's inbox and emails it through the site mailer (opt-outs and unsubscribe link kept); reports when email is skipped. admin.js?v=20261112msg; qa member passed; local route test passed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-12 06:47:52 -06:00
parent 3eae242dc3
commit db1ab8359c
3 changed files with 31 additions and 1 deletions
+2 -1
View File
@@ -270,6 +270,7 @@
<button type="button" class="btn small sec" data-mcact="sponsor">Set sponsor</button>
<button type="button" class="btn small sec" data-mcact="wallet">Swap main wallet</button>
<button type="button" class="btn small sec" data-mcact="credits">Grant credits</button>
<button type="button" class="btn small sec" data-mcact="message">Message (inbox + email)</button>
<a class="btn small sec" id="mcWall" href="#" target="_blank" rel="noopener">Public wall</a>
<button type="button" class="btn small sec" data-mcact="delete" style="margin-left:auto">Delete account</button>
</div>
@@ -653,6 +654,6 @@
<script src="/assets/common.js?v=20261107nc"></script><script src="/assets/welcome.js?v=20261101th"></script>
<script src="/assets/admin-kb.js?v=20261020kb"></script>
<script src="/assets/admin.js?v=20261107tg"></script><script src="/assets/admin-sponsorcheck.js?v=20261107tg"></script><script src="/assets/admin-kits.js?v=20261101th"></script>
<script src="/assets/admin.js?v=20261112msg"></script><script src="/assets/admin-sponsorcheck.js?v=20261107tg"></script><script src="/assets/admin-kits.js?v=20261101th"></script>
</body>
</html>
+8
View File
@@ -544,6 +544,14 @@
if (act === 'sponsor') { const v = await IAP.ask({ title: 'Sponsor for ' + (a.username ? '@' + a.username : a.email), text: 'Username, share code or member #. Blank = no sponsor (company). Re-points free referrals and future purchases; on-chain sponsorship never changes.', value: a.sponsorRef || '', ok: 'Save' }); if (v === null || v === undefined) return; body = { sponsorRef: v }; }
if (act === 'wallet') { const v = await IAP.ask({ title: 'Main wallet for ' + a.email, text: 'Paste the 0x address that should be their main wallet (the one that paid, if a purchase came from an unlinked account). The member number is re-read from the chain. Blank = unlink.', value: a.address || '', ok: 'Swap' }); if (v === null || v === undefined) return; if (!await IAP.confirmBox('Swap the main wallet for ' + a.email + ' to ' + (v.trim() || 'nothing') + '?', { title: 'Sure?', ok: 'Swap it', cancel: 'Cancel' })) return; body = { address: v }; }
if (act === 'credits') { const v = await IAP.ask({ title: 'Grant credits to ' + (a.username ? '@' + a.username : a.email), text: 'Whole number of earned-pool credits (1 credit = 1 cent of delivery). They can spend them on campaigns right away.', type: 'number', value: '', placeholder: '250', ok: 'Grant' }); if (!v) return; const note = await IAP.ask({ title: 'Reason (kept in the server log)', value: '', placeholder: 'e.g. refund for broken banner', ok: 'Grant' }); body = { grantCredits: v, note: note || '' }; }
// message the member (Marty 2026-11-12): lands in their member inbox AND emails them (opt-outs honoured by the mailer)
if (act === 'message') {
const who = a.username ? '@' + a.username : a.email;
const subject = await IAP.ask({ title: 'Message ' + who, text: 'Subject line. The message goes to their member inbox and is emailed to them (unless they unsubscribed from email).', value: '', placeholder: 'A quick note from Marty', ok: 'Next' }); if (!subject) return;
const text = await IAP.ask({ title: subject, text: 'Your message. Plain text; blank lines start new paragraphs.', type: 'textarea', value: '', ok: 'Send' }); if (!text || !text.trim()) return;
const r = await api('/api/admin/member/message', { email: a.email, subject, text }, 'POST');
IAP.status('Sent to ' + who + "'s inbox" + (r.emailed ? ' and emailed.' : r.emailSkipped ? '. Email skipped: ' + r.emailSkipped + '.' : '.'), r.emailed ? 'ok' : 'warn'); return;
}
if (act === 'delete') {
if (a.memberId) { IAP.status('Registered members cannot be deleted; their position is on-chain.', 'bad'); return; }
if (!await IAP.confirmBox('Delete the free account ' + a.email + '? Their sign-in, referrals link and credits go away. There is no undo.', { title: 'Delete account', ok: 'Delete', cancel: 'Keep it' })) return;
+21
View File
@@ -3204,6 +3204,27 @@ const server = http.createServer(async (req, res) => {
// -- link-farm scan (2026-10-30): last result + allowlist, run now (no Telegram), allow / unallow an email
if (p === '/api/admin/spamscan' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); return json(res, 200, spamscan.view()); }
if (p === '/api/admin/spamscan/run' && req.method === 'POST') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); await spamscan.run({ manual: true, quiet: true }); return json(res, 200, spamscan.view()); }
// admin -> one member: inbox message + email (Marty 2026-11-12: "no way to send them an inbox message that would email them as well")
if (p === '/api/admin/member/message' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); const acct = e && await accounts.byEmail(e);
if (!acct) return json(res, 404, { error: 'No such member.' });
const subject = String(b.subject || '').trim().slice(0, 150), text = String(b.text || '').trim().slice(0, 8000);
if (!subject || !text) return json(res, 400, { error: 'Subject and message are both needed.' });
const escH = s => String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
const html = text.split(/\n{2,}/).map(par => '<p>' + escH(par).replace(/\n/g, '<br>') + '</p>').join('');
await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [e], subject, html, 'broadcast');
let emailed = false, emailSkipped = '';
if (!mailer.hasKey()) emailSkipped = 'mail is not set up on this server';
else {
const hello = acct.username ? 'Hi @' + acct.username + ',\n\n' : 'Hi,\n\n';
const tail = '\n\nYou can reply from your member inbox: https://instantadpay.com/my\n\nMarty Bostick, InstantAdPay';
try { emailed = (await mailer.send(e, subject, hello + text + tail, '<div style="font-family:Arial,sans-serif;font-size:15px;line-height:1.5">' + '<p>' + escH(hello.trim()) + '</p>' + html + '<p>You can reply from your member inbox: <a href="https://instantadpay.com/my">instantadpay.com/my</a></p><p>Marty Bostick, InstantAdPay</p></div>')) !== false; if (!emailed) emailSkipped = 'they unsubscribed from email'; }
catch (err) { emailSkipped = 'the mail service failed (' + String(err.message || err).slice(0, 80) + ')'; }
}
console.log('admin message', e.replace(/^(.).*(@.*)$/, '$1***$2'), 'inbox ok', emailed ? 'emailed' : 'email skipped: ' + emailSkipped);
return json(res, 200, { ok: true, inbox: true, emailed, emailSkipped });
}
if (p === '/api/admin/spamscan/allow' && req.method === 'POST') {
if (!isAdmin(req)) return json(res, 401, { error: 'auth' });
const b = await readBody(req); const e = String(b.email || '').trim().toLowerCase(); if (!e) return json(res, 400, { error: 'Which email?' });