From a60905a9fbb195e437ec885d0d1432828bcc3980 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 29 Sep 2026 09:25:55 -0500 Subject: [PATCH] Tank, roster and downline: sortable/filterable lists with last seen, surf earnings and wallet/payout state; admin Members table loads 5000 accounts Co-Authored-By: Claude Fable 5.1 --- ads.js | Bin 116504 -> 118027 bytes public/assets/my.js | 115 ++++++++++++++++++++++++++++++++--------- public/assets/site.css | 13 +++++ public/my.html | 7 +-- server.js | 14 +++-- tank.js | 12 +++-- 6 files changed, 129 insertions(+), 32 deletions(-) diff --git a/ads.js b/ads.js index c1cecc457ad39b9b1185e30b5bdb388bc7cd015b..cebbc0073107893dec0e33af6b66ce2aab95cfdb 100644 GIT binary patch delta 1268 zcma)5&5IOA6lYJuf_T{IK?Hw(PPfkX4nq)hm_>ITKZ3h%_9G$4pf%lZW(vEj#;O|E zVO>V>Xvn3BBVsPO3%P{cbI3jaK`y!GZ^*0eUb8|F>(X8IUcLAGc=hIoBd^{b`Q_Yf zy0nB5nZ=B<9vRrN>4St(QVlHn+Q1D7PN>HaDuE-BA(hry1Z%>$Ngd5b^U7l5>SFV1 zc#T7Saxx>th7!qH!WXw%&2t-HmJ;+PNHmv6AQC*CO4_w`BtoVW#Ho-O@1Dwpbn&%Z zqzO7YbR10 zP{u^;?EUdMoG$)`EmmCqg*f+PuG3&B{ae72n?JY<5tD zmm9dTeiM%+J92j&LCud(tzIkauZ2E1Eo&Cx^LwM=eu&$f_jfk1@?9Bu#O5-oFof(Q z@ba0cfYA*LF%Nc8HJWX#kNqR0K zEdTp8E|u1l&#P7knJ6P`#ehN{b{6745%L?W3oo0q- { const d = new Date(); d.setHours(0, 0, 0, 0); return d.getTime(); }; + const activeToday = m => (m.lastSeen || 0) >= dayStart(); + const LIST_SORTS = [ + { k: 'seen', label: 'Last seen', v: m => m.lastSeen || 0 }, + { k: 'joined', label: 'Joined', v: m => m.joined || 0 }, + { k: 'earned', label: 'Surf earnings', v: m => m.earned || 0 }, + { k: 'balance', label: 'Earned balance', v: m => m.balance || 0 }, + { k: 'name', label: 'Name', v: m => String(m.name || '').toLowerCase(), str: true }, + ]; + const LIST_FILTERS = [ + { k: 'today', label: 'Active today', t: m => activeToday(m) }, + { k: 'earning', label: 'Earning', t: m => (m.earned || 0) > 0 }, + { k: 'wallet', label: 'Wallet linked', t: m => !!m.wallet }, + { k: 'nopay', label: 'Wallet, payouts off', t: m => !!m.wallet && !m.activated }, + { k: 'payouts', label: 'Payouts on', t: m => !!m.activated }, + { k: 'nowallet', label: 'No wallet', t: m => !m.wallet }, + ]; + const listState = key => LIST_UI[key] || (LIST_UI[key] = { sort: 'seen', dir: -1, on: new Set() }); + function listApply(key, rows) { + const st = listState(key); const s = LIST_SORTS.find(x => x.k === st.sort) || LIST_SORTS[0]; + const out = (rows || []).filter(m => m.own || [...st.on].every(k => { const f = LIST_FILTERS.find(x => x.k === k); return !f || f.t(m); })); + out.sort((a, b) => { const x = s.v(a), y = s.v(b); return (s.str ? String(x).localeCompare(String(y)) : x - y) * st.dir; }); + return out; + } + function listBar(key, total, shown, rerender, opts) { + const st = listState(key); const hide = (opts && opts.hide) || []; + const bar = document.createElement('div'); bar.className = 'lst-bar'; + bar.innerHTML = '' + + '' + + '' + LIST_FILTERS.filter(f => !hide.includes(f.k)).map(f => '').join('') + '' + + '' + (shown === total ? total + (total === 1 ? ' person' : ' people') : shown + ' of ' + total) + ''; + bar.querySelector('select').addEventListener('change', e => { st.sort = e.target.value; st.dir = st.sort === 'name' ? 1 : -1; rerender(); }); + bar.querySelector('.lst-dir').addEventListener('click', () => { st.dir = -st.dir; rerender(); }); + bar.querySelectorAll('[data-f]').forEach(b => b.addEventListener('click', () => { const k = b.dataset.f; if (st.on.has(k)) st.on.delete(k); else st.on.add(k); rerender(); })); + return bar; + } + const seenAgo = t => { if (!t) return 'never'; const d = Date.now() - t; if (d < 3600e3) return Math.max(1, Math.round(d / 60e3)) + ' min ago'; if (d < 86400e3) return Math.round(d / 3600e3) + 'h ago'; const days = Math.floor(d / 86400e3); return days === 1 ? 'yesterday' : days + ' days ago'; }; + const seenChip = m => m.lastSeen ? '' + (activeToday(m) ? 'active today' : 'seen ' + seenAgo(m.lastSeen)) + '' : 'never signed in'; + const earnChip = m => '' + (m.earned || 0).toLocaleString() + ' cr earned'; + const walletChip = m => m.activated ? 'wallet · payouts on' : m.wallet ? 'wallet · payouts off' : 'no wallet'; + const memberChips = m => seenChip(m) + ' ' + earnChip(m) + ' ' + walletChip(m); // Section pills at the top of My line: one per visible card marked data-jump, the one in view lit up. // Cards that show or hide themselves (sponsor, upline messages) rebuild the row when they change. let lineJumpObs = null; @@ -491,6 +536,19 @@ } catch (e) {} } // visual line tree on the Overview: YOU + three levels, qualified directs in gold + function renderRoster(wrap, all) { + const rows = listApply('roster', all); + wrap.querySelectorAll(':scope > .lst-bar, :scope > table, :scope > .pgr, :scope > .lst-none').forEach(n => n.remove()); + wrap.appendChild(listBar('roster', all.length, rows.length, () => renderRoster(wrap, all))); + if (!rows.length) { wrap.insertAdjacentHTML('beforeend', '

Nobody in your line matches those filters.

'); return; } + const t = document.createElement('table'); t.className = 'roster'; + t.innerHTML = rows.map(r => '' + esc(r.name || r.email || '') + '' + + 'joined ' + new Date(r.joined).toLocaleDateString() + '' + + '' + memberChips(r) + '' + + '' + esc(r.status) + '').join(''); + wrap.appendChild(t); + pageList('roster', wrap, 'table.roster tr', { per: LINE_PER }); + } async function loadLineTree(buyerCount) { try { const r = await (await fetch('/api/my/line')).json(); @@ -624,15 +682,7 @@ const wrap = $('rosterWrap'); if ((d.referrals || []).length) { $('rosterEmpty').hidden = true; - let t = wrap.querySelector('table'); - if (t) t.remove(); - t = document.createElement('table'); - t.className = 'roster'; - t.innerHTML = d.referrals.map(r => '' + String(r.name || r.email || '').replace(/[&<>]/g, '') + '' - + '' + new Date(r.joined).toLocaleDateString() + '' - + '' + r.status + '').join(''); - wrap.appendChild(t); - pageList('roster', wrap, 'table.roster tr', { per: LINE_PER }); + renderRoster(wrap, d.referrals); } // overview recent-activity widget: chain events + line joins, newest first try { @@ -1494,19 +1544,26 @@ $('tankMine').querySelectorAll('[data-tchat]').forEach(b => b.addEventListener('click', () => openConvo(b.dataset.tchat, b.dataset.tname))); $('tankMine').querySelectorAll('[data-pif]').forEach(b => b.addEventListener('click', () => pif(b.dataset.pif, b.dataset.pname, b.dataset.paddr))); if (!r.waiting.length) { el.innerHTML = '

The tank is empty. Anyone who joins from the public site without a sponsor lands here.

'; return; } - el.innerHTML = r.waiting.map(w => '
' + esc(w.name) + '' - + 'joined ' + ago(w.joined) + '' - + 'last sign-in: ' + ago(w.lastSeen) + '' - + (r.eligible ? '' : '') + '
').join(''); - pageList('tank', el, ':scope > .lin-row', { per: LINE_PER }); - el.querySelectorAll('[data-adopt]').forEach(b => b.addEventListener('click', async () => { - const note = await IAP.ask({ title: 'Adopt ' + b.dataset.aname, text: 'Your first message to ' + b.dataset.aname + ' (sent as a chat and an email):', type: 'textarea', ok: 'Adopt and send', value: 'Hi, I picked you up from the InstantAdPay holding tank so you have a sponsor who will actually help. Reply here and I will walk you through the first three steps.' }); - if (note === null) return; - try { const rr = await api('/api/my/tank/adopt', { who: b.dataset.adopt, note }); IAP.status('You are now the sponsor for ' + rr.name + '. Chat and email sent.', 'ok'); loadTank(); loadCoach(); } - catch (e) { IAP.status(e.message, 'bad'); } - })); + renderTank(el, r); } catch (e) {} } + function renderTank(el, r) { + const rows = listApply('tank', r.waiting); + el.innerHTML = ''; + el.appendChild(listBar('tank', r.waiting.length, rows.length, () => renderTank(el, r), { hide: ['payouts'] })); // nobody in the tank has payouts on + el.insertAdjacentHTML('beforeend', rows.length ? rows.map(w => '
' + esc(w.name) + '' + + 'joined ' + ago(w.joined) + '' + memberChips(w) + '' + + 'last sign-in: ' + ago(w.lastSeen) + '' + + (r.eligible ? '' : '') + '
').join('') + : '

Nobody in the tank matches those filters.

'); + pageList('tank', el, ':scope > .lin-row', { per: LINE_PER }); + el.querySelectorAll('[data-adopt]').forEach(b => b.addEventListener('click', async () => { + const note = await IAP.ask({ title: 'Adopt ' + b.dataset.aname, text: 'Your first message to ' + b.dataset.aname + ' (sent as a chat and an email):', type: 'textarea', ok: 'Adopt and send', value: 'Hi, I picked you up from the InstantAdPay holding tank so you have a sponsor who will actually help. Reply here and I will walk you through the first three steps.' }); + if (note === null) return; + try { const rr = await api('/api/my/tank/adopt', { who: b.dataset.adopt, note }); IAP.status('You are now the sponsor for ' + rr.name + '. Chat and email sent.', 'ok'); loadTank(); loadCoach(); } + catch (e) { IAP.status(e.message, 'bad'); } + })); + } // The announcement cards at the top of the Overview are repeated on a timer, so a member who has read // one can put it away: dismissed for the rest of this browser session, back at the next sign-in // (Marty, 2026-09-22) so a message nobody has acted on is never gone for good. @@ -1817,17 +1874,29 @@ el.innerHTML = '

No one in your downline yet. Share your link and it fills in here.

'; return; } - el.innerHTML = r.levels.map(L => !L.members.length ? '' : + LINE_DATA = r; renderLineage(el); + } catch (e) {} + } + let LINE_DATA = null; + function renderLineage(el) { + const r = LINE_DATA; if (!r) return; + try { + const all = r.levels.reduce((n, L) => n + L.members.length, 0); + const shown = r.levels.map(L => ({ level: L.level, members: listApply('line', L.members) })); + const kept = shown.reduce((n, L) => n + L.members.length, 0); + el.innerHTML = ''; + el.appendChild(listBar('line', all, kept, () => renderLineage(el))); + el.insertAdjacentHTML('beforeend', !kept ? '

Nobody in your downline matches those filters.

' : shown.map(L => !L.members.length ? '' : '
Level ' + L.level + ' · ' + L.members.length + (L.level === 1 ? ' direct' : '') + '
' + L.members.map(m => '
' + esc(m.name) + (m.own ? ' yours' : '') + '' - + '' + (m.email ? esc(m.email) : (m.memberId ? '#' + m.memberId + '' : '')) + (m.sponsor ? 'sponsored by ' + esc(m.sponsor) + '' : '') + (m.own ? '' : '' + (m.bought ? '$20+ buy ✓' : 'no $20+ buy yet') + (m.buyers ? ' · ' + m.buyers + ' qualifying buyer' + (m.buyers === 1 ? '' : 's') + ' of their own' : '') + '') + '' + + '' + (m.email ? esc(m.email) : (m.memberId ? '#' + m.memberId + '' : '')) + (m.sponsor ? 'sponsored by ' + esc(m.sponsor) + '' : '') + (m.own ? '' : '' + (m.bought ? '$20+ buy ✓' : 'no $20+ buy yet') + (m.buyers ? ' · ' + m.buyers + ' qualifying buyer' + (m.buyers === 1 ? '' : 's') + ' of their own' : '') + '' + memberChips(m) + '') + '' + '' + (m.earnedWei && m.earnedWei !== '0' ? '+' + IAP.fmtPol(m.earnedWei) + ' POL' : '0.00 POL') + '' + '' + new Date(m.joined).toLocaleDateString() + '' + (m.email ? '' : '') + (m.ref && !m.own ? '' : '') + '
' + (m.ref && !m.own ? '' : '')).join('') - + '
').join(''); + + '').join('')); el.querySelectorAll('[data-cemail]').forEach(b => b.addEventListener('click', () => openConvo(b.dataset.cemail, b.dataset.cname))); el.querySelectorAll('[data-act]').forEach(b => b.addEventListener('click', () => toggleLineActivity(b))); diff --git a/public/assets/site.css b/public/assets/site.css index 2596b65..bf7bd47 100644 --- a/public/assets/site.css +++ b/public/assets/site.css @@ -485,6 +485,19 @@ textarea{resize:vertical;font:inherit} .lin-row .sp{display:block;font-size:11.5px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .lin-row .em{min-width:0} .lin-row .dt{font-size:12px;color:var(--muted);text-align:right;font-variant-numeric:tabular-nums;white-space:nowrap} .lin-row .chat-msg-btn{justify-self:end} +.lin-row .sp.wrap{white-space:normal;line-height:1.7} +/* list toolbar: sort + filter chips shared by the tank, roster and downline (2026-09-29) */ +.lst-bar{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin:4px 0 10px;padding:8px 10px;border:1px solid var(--line);border-radius:12px;background:rgba(255,255,255,.025)} +.lst-sort{font-size:12px;color:var(--muted);display:inline-flex;align-items:center;gap:6px} +.lst-sort select{background:var(--panel);color:var(--ink);border:1px solid var(--line-strong);border-radius:8px;padding:4px 8px;font-size:12.5px} +.lst-dir{background:transparent;color:var(--ink);border:1px solid var(--line-strong);border-radius:8px;padding:4px 9px;font-size:12px;cursor:pointer;white-space:nowrap} +.lst-chips{display:flex;flex-wrap:wrap;gap:6px} +.lst-chip{font-size:12px;color:var(--muted);background:transparent;border:1px solid var(--line);border-radius:999px;padding:3px 10px;cursor:pointer;white-space:nowrap} +.lst-chip.on{border-color:var(--mint);color:var(--ink);background:var(--mint-soft)} +.lst-n{margin-left:auto;font-size:12px;color:var(--muted);font-variant-numeric:tabular-nums} +.lchip{display:inline-block;font-size:11.5px;color:var(--muted);border:1px solid var(--line);border-radius:999px;padding:1px 8px;white-space:nowrap;vertical-align:middle} +.lchip.on{border-color:rgba(67,232,195,.45);color:var(--ink)} .lchip.warn{border-color:rgba(255,209,92,.55);color:#ffd15c} +.roster td:nth-child(3){white-space:normal;line-height:1.8} .lin-row .lin-act-btn{justify-self:end;white-space:nowrap} .lin-act{display:flex;flex-wrap:wrap;gap:6px;align-items:center;padding:8px 10px 10px;margin:-1px 0 6px;border-bottom:1px solid var(--line);background:rgba(255,255,255,.025);border-radius:0 0 10px 10px} .lin-chip{font-size:12px;color:var(--muted);border:1px solid var(--line);border-radius:999px;padding:3px 10px;white-space:nowrap} .lin-chip b{font-weight:600;color:var(--ink);margin-right:5px} .lin-chip.on{border-color:rgba(67,232,195,.45);color:var(--ink)} .lin-chip.warn{border-color:rgba(255,209,92,.5)} diff --git a/public/my.html b/public/my.html index 7028dee..03036fa 100644 --- a/public/my.html +++ b/public/my.html @@ -5,7 +5,7 @@ Member area | InstantAdPay - + @@ -319,7 +319,8 @@

Your line

-

Everyone who joined through your link, newest first. When they buy their +

Everyone who joined through your link. Sort or filter the list to spot who signed in today, who is earning + credits on their own, and who has a wallet linked but payouts still off. When they buy their first package of $20 or more, they count toward your qualification.

Nobody yet. Your link is ready above; share it and this list starts filling.

@@ -1084,7 +1085,7 @@ - + diff --git a/server.js b/server.js index d7d67a2..38a585d 100644 --- a/server.js +++ b/server.js @@ -494,7 +494,7 @@ async function boot() { notify: async (memberId, subject, text, kind) => { const a = await accounts.byMemberId(memberId); if (!a || !a.email) return; const html = '

' + String(text).replace(/&/g, '&').replace(//g, '>').replace(/(https:\/\/[^\s]+)/g, '$1').split('\n\n').join('

').replace(/\n/g, '
') + '

'; await messages.deliver(1, ADMIN_EMAIL || 'house@instantadpay.com', [a.email], subject, html, kind || 'notice'); } }); setInterval(() => wednesday.tick().catch(e => console.error('wednesday', e.message)), 5 * 60 * 1000); setInterval(() => snapshot.tick().catch(e => console.error('snapshot', e.message)), 10 * 60 * 1000); - tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, site: 'https://instantadpay.com' }); + tank.init({ dataDir: DATA_DIR, chain, accounts, messages, mailer, ads, site: 'https://instantadpay.com' }); await fraud.init({ dataDir: DATA_DIR }); { // a suspended account is signed out everywhere: every member route sees no session const realFrom = auth.fromRequest.bind(auth); @@ -1752,10 +1752,14 @@ const server = http.createServer(async (req, res) => { if (acct && acct.username) refs.push(acct.username); if (memberId) refs.push(String(memberId)); const joined = await accounts.listByReferrer(refs); + const rTot = await ads.earnedTotals(joined.map(r => r.email)); // surf earnings per referral (Marty, 2026-09-29) out.referrals = joined.map(r => ({ name: r.username || r.email.replace(/^(.).*(@.*)$/, '$1***$2'), // username, else privacy mask joined: r.created, - status: r.address ? 'wallet linked' : 'joined free' + lastSeen: r.lastSeen || 0, + wallet: !!r.address, activated: !!r.memberId, + earned: (rTot[r.email] || {}).earned || 0, balance: (rTot[r.email] || {}).balance || 0, + status: r.memberId ? 'payouts on' : r.address ? 'wallet linked' : 'joined free' })); out.isAdmin = !!(ADMIN_EMAIL && out.email && String(out.email).toLowerCase() === ADMIN_EMAIL); // shows the Admin link out.wallUnlocked = wallUnlockedFor(out.buyerCount || 0); // how many wall positions are the member's own @@ -2404,6 +2408,7 @@ const server = http.createServer(async (req, res) => { const idsOf = m => [m.memberId, ...(posIds[m.email] || [])].filter(Boolean); // Clinton's ask (2026-09-14): on levels 2 and 3 show who has made their $20+ buy (counted for their own // sponsor) and how many qualifying buyers of their own they have, so a leader can see who is one short + const lTot = await ads.earnedTotals(levels.flatMap(L => L.members.map(m => m.email))); // surf earnings per person (Marty, 2026-09-29) const onchain = {}; for (const m of levels.flatMap(L => L.members)) { let bought = false, buyers = 0; for (const id of idsOf(m)) { const mm = await cachedMember(id); if (mm) { if (mm.countedAsBuyer) bought = true; buyers += mm.buyerCount || 0; } } onchain[m.email] = { bought, buyers }; } const out = levels.map(L => ({ level: L.level, members: L.members.map(m => ({ @@ -2414,6 +2419,9 @@ const server = http.createServer(async (req, res) => { ref: m.code || null, // opens the activity drop-down (Clinton's ask, 2026-09-14): any of the three levels email: L.level === 1 ? m.email : null, // directs only joined: m.created, + lastSeen: m.lastSeen || 0, + wallet: !!m.address, activated: !!m.memberId, + earned: (lTot[m.email] || {}).earned || 0, balance: (lTot[m.email] || {}).balance || 0, qualified: idsOf(m).some(id => qualified.has(id)), earnedWei: idsOf(m).reduce((n, id) => n + BigInt(earnedBy[id] || '0'), 0n).toString() })) })); // the member's own linked positions sit on level 1 too, labelled as theirs @@ -3117,7 +3125,7 @@ const server = http.createServer(async (req, res) => { } if (p === '/api/admin/members' && req.method === 'GET') { if (!isAdmin(req)) return json(res, 401, { error: 'auth' }); - const members = await accounts.listAll(500); + const members = await accounts.listAll(5000); // was 500: older members (igor147, joined 09-12) vanished from the table and its search once the site passed 500 accounts (Marty, 2026-09-29) // resolve each sponsor token (username, share code or member #) to the sponsor's name // the lookup covers EVERY account, not the page's slice: built from `members` it called every // sponsor who joined before the newest 500 a dead link (144 of them, Marty 2026-09-23) diff --git a/tank.js b/tank.js index c68acee..9b02c63 100644 --- a/tank.js +++ b/tank.js @@ -57,7 +57,8 @@ const D = { const rowA = r => ({ id: r.id, adoptee: r.adoptee, adopter: r.adopter, ts: Number(r.ts), expires: Number(r.expires), status: r.status, note: r.note || null, closed: r.closed ? Number(r.closed) : null }); const impl = () => db.enabled() ? D : J; -function init(opts) { DATA_DIR = opts.dataDir; accounts = opts.accounts; chain = opts.chain; messages = opts.messages; mailer = opts.mailer; if (opts.site) siteUrl = opts.site; J.load(); } +let ads = null; +function init(opts) { DATA_DIR = opts.dataDir; accounts = opts.accounts; chain = opts.chain; messages = opts.messages; mailer = opts.mailer; ads = opts.ads || null; if (opts.site) siteUrl = opts.site; J.load(); } const mask = e => String(e || '').replace(/^(.).*(@.*)$/, '$1***$2'); const nameOf = a => a.username ? '@' + a.username : (a.memberId ? 'member #' + a.memberId : mask(a.email)); @@ -65,8 +66,13 @@ const inTank = a => !a.sponsorRef && !a.memberId; // arrived with no sponsor (or // waiting list: newest sign-in first so a live one is easy to spot async function waiting() { - const all = await accounts.listAll(2000); - return all.filter(inTank).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: false })) + const all = await accounts.listAll(5000); + const rows = all.filter(inTank); + // what each of them has earned by surfing on their own, no sponsor (Marty, 2026-09-29), so an adopter can spot the workers + const tot = ads && ads.earnedTotals ? await ads.earnedTotals(rows.map(a => a.email)) : {}; + return rows.map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, + wallet: !!a.address, activated: !!a.memberId, // in the tank "activated" is always false (payouts on = out of the tank); wallet can still be linked + earned: (tot[a.email] || {}).earned || 0, balance: (tot[a.email] || {}).balance || 0 })) .sort((a, b) => (b.lastSeen || b.joined) - (a.lastSeen || a.joined)); }