Holding tank: 24-hour sign-up grace plus a Who invited you box, the same rules as InstantAdPay (Marty 2026-11-07: "24-hour grace plus the prompt"). One network tank, so both sites behave the same.
Grace: for 24 hours from an account's created time nobody can adopt the person by hand: an Opens in badge, no Adopt button, a plain refusal from adopt(). Auto-assign keeps its clock from the wallet link, so the 24-hour hold is not stretched. The wallet-ready post waits for the grace and says the time really left, is skipped when the rotation takes them in that tick, the arrivals post moves to when the grace ends (marks.claim per member), and the Overview note and weekly email count only people who are open. Prompt: LinkSpin members land on the Control Room, not the /tools Overview, so the box sits at the top of every Control Room screen, /tools included (cr-shell.js). Same checks as InstantAdPay, through setSponsor as a deliberate change with by 'invited', so it follows and clears the hold. With a wallet already linked the engine switches payouts on under the named sponsor right away, as an adoption does, and the confirm box says so first. Nobody invited me hides it everywhere and a small link on /tools brings it back. The named sponsor gets the referral email and an on-site notice (new hooks.notify). Chatbot canned + systemPrompt, KNOWLEDGE_DATE 2026-11-07. cr-shell.js, common.js, credits-screen.js, my.js, admin.js, admin-sponsorcheck.js ?v=20261107tg. qa/tank-hold.test.mjs and qa/sponsorfollow.test.cjs extended; qa/run.sh member now runs tank-hold. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -17,11 +17,15 @@ const TTL_MS = 7 * 86400000; // an adoption's window to convert
|
||||
const MAX_ADOPTIONS = 2; // per adoptee, lifetime (dropped adoptions count too, since 2026-09-13)
|
||||
const HOLD_MS = 3 * 24 * 3600 * 1000; // an adoption is a commitment: no releasing someone you picked up less than 3 days ago (Marty, 2026-09-13)
|
||||
// statuses that do not count toward a person's two adoptions: a release record, and the later side of a network race
|
||||
// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js)
|
||||
const NOT_COUNTED = ['released', 'conflict'];
|
||||
// (both sites adopted the same person within minutes; the earlier adoption won on both, sponsorfollow.js), and a record of a
|
||||
// member naming who invited them (nobody adopted them; nameSponsor below)
|
||||
const NOT_COUNTED = ['released', 'conflict', 'invited'];
|
||||
const MIN_OWN_BUY_CENTS = 2500; // adopter must have bought a qualifying ($25+) package themselves
|
||||
const WARN_DAYS = 10; // dormant lead: sponsor warned after this many days without contact
|
||||
const RESCUE_DAYS = 14; // ...and the lead moves to the tank after this many (warning at least 4 days old)
|
||||
const GRACE_MS = 24 * 3600 * 1000; // nobody adopts a new sign-up by hand for this long after `created`, so they can say who invited them (Marty 2026-11-07)
|
||||
const BRAND = 'LinkSpin';
|
||||
const LINE_URL = () => siteUrl + '/tools#line';
|
||||
|
||||
let DATA_DIR = '.', accounts, chain, messages, mailer, siteUrl = SITE_URL;
|
||||
|
||||
@@ -49,10 +53,10 @@ const D = {
|
||||
const rows = adopter ? await db.q("SELECT * FROM adoptions WHERE status='open' AND adopter=?", [adopter]) : await db.q("SELECT * FROM adoptions WHERE status='open'");
|
||||
return rows.map(rowA);
|
||||
},
|
||||
async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n); },
|
||||
async countFor(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n); },
|
||||
async setStatus(id, status) { await db.q('UPDATE adoptions SET status=?, closed=? WHERE id=?', [status, Date.now(), Number(id)]); },
|
||||
async recent(n) { return (await db.q('SELECT * FROM adoptions ORDER BY id DESC LIMIT ?', [Number(n) || 100])).map(rowA); },
|
||||
async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict')", [adoptee]); return Number(r[0].n) > 0; },
|
||||
async hasRecord(adoptee) { const r = await db.q("SELECT COUNT(*) n FROM adoptions WHERE adoptee=? AND status NOT IN ('released','conflict','invited')", [adoptee]); return Number(r[0].n) > 0; },
|
||||
async all() { return (await db.q('SELECT * FROM adoptions ORDER BY id')).map(rowA); },
|
||||
async mark(lead) { const r = await db.q('SELECT * FROM lead_marks WHERE `lead`=?', [lead]); return r[0] ? { sponsor: r[0].sponsor, contacted: Number(r[0].contacted_ts || 0), warned: Number(r[0].warned_ts || 0) } : null; },
|
||||
async setMark(lead, f) {
|
||||
@@ -83,9 +87,10 @@ async function waiting() {
|
||||
const all = await accounts.listAll(2000);
|
||||
return all.filter(a => inTank(a) && !remoteOpen(a.email)).map(a => ({ email: a.email, name: nameOf(a), username: a.username || null, joined: a.created, lastSeen: a.lastSeen || 0, wallet: !!a.address,
|
||||
// wallet linked = ready to switch on payouts, the plain activation held for an adopter (24-hour clock, autoAssign after that)
|
||||
opensAt: inGrace(a) ? graceEnd(a) : 0, // new sign-up: nobody can adopt them by hand before this (0 = open now)
|
||||
...(() => { const r = a.address ? readyRec(a.email) : null; return r ? { ready: true, readyAt: r.readyAt, holdUntil: r.readyAt + READY_MS } : { ready: false }; })() }))
|
||||
// ready members first (least time left first), then newest sign-in
|
||||
.sort((a, b) => (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined));
|
||||
// open before the sign-up grace ones, ready members first (least time left first), then newest sign-in
|
||||
.sort((a, b) => (a.opensAt ? 1 : 0) - (b.opensAt ? 1 : 0) || (b.ready ? 1 : 0) - (a.ready ? 1 : 0) || (a.ready && b.ready ? a.readyAt - b.readyAt : 0) || (b.lastSeen || b.joined) - (a.lastSeen || a.joined));
|
||||
}
|
||||
|
||||
// has this member bought a $25 or larger package themselves? (the qualifying-for-yourself buy)
|
||||
@@ -112,7 +117,7 @@ async function view(email) {
|
||||
const a = await accounts.byEmail(ad.adoptee);
|
||||
mine.push({ id: ad.id, name: a ? nameOf(a) : mask(ad.adoptee), email: ad.adoptee, ts: ad.ts, expires: ad.expires, lastSeen: a ? (a.lastSeen || 0) : 0, wallet: !!(a && a.address), address: (a && a.address) || null, bought: !!(a && a.memberId) });
|
||||
}
|
||||
return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, waiting: await waiting(), mine };
|
||||
return { eligible: el.ok, reason: el.ok ? '' : el.reason, cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, graceHours: GRACE_MS / 3600000, waiting: await waiting(), mine };
|
||||
}
|
||||
|
||||
async function adopt(adopterEmail, who, note, opts) {
|
||||
@@ -126,6 +131,7 @@ async function adopt(adopterEmail, who, note, opts) {
|
||||
const target = list.find(w => (w.username && w.username.toLowerCase() === key) || w.email === key);
|
||||
if (!target) return { error: 'That member is no longer in the tank.' };
|
||||
if (target.email === e) return { error: 'That is you.' };
|
||||
if (!auto && target.opensAt > clock()) return { error: 'That member joined less than 24 hours ago, so they still have time to tell us who invited them. You can adopt them in ' + leftText(target.opensAt - clock()) + '.' }; // the safety net is not held by this: it keeps its 24-hour clock from the wallet link
|
||||
if (remoteOpen(target.email)) return { error: 'That member was just picked up on ' + OTHER + ', so they are no longer in the tank.' };
|
||||
if (!auto && await countAll(target.email) >= MAX_ADOPTIONS) return { error: 'That member has been adopted twice already and stays where they are.' }; // the safety net never leaves anyone to the company
|
||||
const token = me.username || me.code || String(me.memberId);
|
||||
@@ -510,9 +516,11 @@ async function readyTick() {
|
||||
if (await alignToNetwork(a).catch(() => null)) { aligned++; continue; }
|
||||
if (remoteOpen(a.email)) continue;
|
||||
const rec = markReady(a);
|
||||
if (rec && !rec.notified) {
|
||||
// Sign-up grace (2026-11-07): no "adopt them" post for someone who cannot be adopted yet; announced when the grace ends,
|
||||
// and not at all when the safety net takes them in this same tick (nothing left for anyone to do)
|
||||
if (rec && !rec.notified && !inGrace(a)) {
|
||||
rec.notified = clock();
|
||||
const iap = hooks.iapOwns ? await Promise.resolve(hooks.iapOwns(a.email)).catch(() => false) : false;
|
||||
const iap = clock() < rec.readyAt + READY_MS - TICK_MS ? (hooks.iapOwns ? await Promise.resolve(hooks.iapOwns(a.email)).catch(() => false) : false) : true;
|
||||
if (!iap && await claimOnce('tankready:' + a.email + ':' + rec.readyAt)) fresh.push({ email: a.email, name: nameOf(a), username: a.username || null, until: rec.readyAt + READY_MS });
|
||||
}
|
||||
}
|
||||
@@ -567,6 +575,85 @@ async function liftPendingRun() {
|
||||
}
|
||||
function alignedRecent(n) { return RS.load().aligned.slice(-(n || 50)).reverse(); }
|
||||
|
||||
// ── sign-up grace + "Who invited you?" (Marty approved 2026-11-07: "24-hour grace plus the prompt") ──
|
||||
// Nov 2: @santoridaviss signed up with no referral at 10:35 PM, was adoptable at 2:24 AM and adopted at 3:36 AM, before he
|
||||
// could say who invited him. So:
|
||||
// GRACE: for 24 hours from the account's `created`, nobody can adopt the person BY HAND. They stay on the waiting list with
|
||||
// opensAt set (the card shows "Opens in ...", no Adopt button). The dates are each site's own account dates. Only sign-up
|
||||
// counts: someone back in the tank later (released, rescued, window ended) is past it.
|
||||
// The safety net does not wait for the grace (opts.auto skips it): Marty's rule is a wallet-linked member is held for no
|
||||
// longer than 24 hours, so autoAssign keeps its clock from the wallet link. Wallet linked in the first 15 minutes: the
|
||||
// rotation can fire up to 15 minutes before the grace ends, and hand adoption never opens for them. Wallet linked in the
|
||||
// first hour: hand adoption opens at 24 hours and the rotation takes them about an hour after that.
|
||||
// Notices: readyTick announces a ready member only once they can be adopted, and only when time is left (adoptableOf and
|
||||
// openedSince keep the Overview note, the arrivals post and the weekly email to people who are open too).
|
||||
// PROMPT: a tank member can name who invited them. nameSponsor() goes through setSponsor like adopt(), so it follows to the
|
||||
// other site and clears the hold the same way, but it is the member's own choice: only ever for the signed-in member,
|
||||
// never an open adoption (no 7-day window, no fall-back, no count toward the two), recorded as status 'invited'.
|
||||
function graceEnd(a) { return (Number(a && a.created) || 0) + GRACE_MS; }
|
||||
function inGrace(a) { return graceEnd(a) > clock(); }
|
||||
function leftText(ms) { const m = Math.max(1, Math.ceil(Number(ms) / 60000) || 1); const h = Math.floor(m / 60); return h ? h + ' h ' + (m % 60) + ' min' : m + ' min'; }
|
||||
const adoptableOf = list => (list || []).filter(w => !(w.opensAt > clock()));
|
||||
async function adoptable() { return adoptableOf(await waiting()); }
|
||||
// people whose grace ended after `since` (the arrivals post: announced when they can be adopted, not when they sign up)
|
||||
function openedSince(list, since) { const now = clock(); return (list || []).filter(w => { const t = (Number(w.joined) || 0) + GRACE_MS; return t > since && t <= now; }); }
|
||||
// what the dashboard needs: null = no card. dismissed = they tapped "Nobody invited me" (a small link brings the card back).
|
||||
function inviteAsk(a) {
|
||||
if (!a || !inTank(a) || remoteOpen(a.email)) return null;
|
||||
return { dismissed: !!(RS.load().noInvite || {})[String(a.email || '').toLowerCase()] };
|
||||
}
|
||||
function dismissInvite(email) { const st = RS.load(); st.noInvite = st.noInvite || {}; st.noInvite[String(email || '').toLowerCase()] = clock(); RS.save(); return { ok: true }; }
|
||||
// someone in the named person's line (them first) already has a contract position? Otherwise the member would be walked up to
|
||||
// the company at their first activation, the one thing the tank exists to stop
|
||||
async function firstOnContract(sp) {
|
||||
let cur = sp; const seen = new Set();
|
||||
for (let i = 0; cur && i < 60; i++) { if (Number(cur.memberId) > 0) return cur; if (seen.has(cur.email)) return null; seen.add(cur.email); cur = await accounts.sponsorOf(cur.email); }
|
||||
return null;
|
||||
}
|
||||
// opts.check: every refusal, nothing written (the card asks "is this them?" before the real call)
|
||||
async function nameSponsor(email, who, opts) {
|
||||
const e = String(email || '').toLowerCase(); const check = !!(opts && opts.check);
|
||||
const LOCKED = 'Your payouts are already on, so your sponsor is locked on the contract.';
|
||||
let a = await accounts.byEmail(e);
|
||||
if (!a) return { error: 'Sign in first.' };
|
||||
if (Number(a.memberId) > 0) return { error: LOCKED };
|
||||
if (a.sponsorRef) return { error: 'You already have a sponsor.' };
|
||||
if (a.address) { // wallet on the contract already, member number not saved yet
|
||||
if (hooks.bound) { const id = await Promise.resolve(hooks.bound(a)).catch(() => -1); if (id < 0) return { error: 'Could not check the contract just now. Try again in a minute.' }; if (id > 0) return { error: LOCKED }; }
|
||||
else if (hooks.activated && await Promise.resolve(hooks.activated(a)).catch(() => false)) return { error: LOCKED };
|
||||
}
|
||||
if (remoteOpen(e)) return { error: 'You were just picked up on ' + OTHER + ', so you already have a sponsor.' };
|
||||
const al = await alignToNetwork(a).catch(() => null); // one identity: the sponsor the network already knows comes first
|
||||
if (al) return { error: 'You already have a sponsor on the network: ' + al.toName + '.', aligned: true };
|
||||
const key = String(who || '').trim().toLowerCase().replace(/^@+/, '');
|
||||
if (!key) return { error: 'Type the username of the person who invited you.' };
|
||||
const sp = /^[a-z0-9_]{3,20}$/.test(key) ? await accounts.byUsername(key) : null;
|
||||
if (!sp || (accounts.isUnclaimedShell && accounts.isUnclaimedShell(sp))) return { error: 'No member here has the username ' + key + '. Check the spelling with the person who invited you.' };
|
||||
if (String(sp.email).toLowerCase() === e) return { error: 'That is you. Type the username of the person who invited you.' };
|
||||
const bar = hooks.excluded || hooks.isSuspended;
|
||||
if (bar && bar(sp.email)) return { error: nameOf(sp) + ' cannot take new members right now.' };
|
||||
if (await inDownlineOf(e, sp)) return { error: nameOf(sp) + ' is in your own line, so they cannot be your sponsor.' };
|
||||
const payee = await firstOnContract(sp);
|
||||
if (!payee) return { error: nameOf(sp) + ' has not switched on payouts yet, and nobody above them has either, so you cannot go under them yet. Ask them to switch on payouts, then come back here.' };
|
||||
if (hooks.payoutBlocked && await Promise.resolve(hooks.payoutBlocked(Number(payee.memberId))).catch(() => true)) return { error: nameOf(sp) + ' cannot take new members right now.' };
|
||||
if (check) return { ok: true, check: true, name: nameOf(sp) };
|
||||
a = await accounts.byEmail(e);
|
||||
if (!a || !inTank(a)) return { error: 'You already have a sponsor.' };
|
||||
const token = sp.username || sp.code || String(sp.memberId);
|
||||
const r = await setSponsor(e, token, 'invited', 'named by the member on the Who invited you card');
|
||||
if (r && r.error) return r;
|
||||
const now = clock();
|
||||
const ad = await impl().add({ adoptee: e, adopter: String(sp.email).toLowerCase(), ts: now, expires: now, status: 'invited', note: 'named by the member on the Who invited you card' });
|
||||
{ const rr = RS.load().ready[e]; if (rr && !rr.done) { rr.done = now; rr.namedSponsor = sp.email; RS.save(); } } // the hold lifts: their sponsor resolves now
|
||||
const name = nameOf(a);
|
||||
{ const tg = await accounts.byEmail(e); if (tg && tg.address && !(Number(tg.memberId) > 0) && hooks.lifted) { markLift(e); liftRun(e).catch(err => console.error('tank lift', err.message)); } } // wallet already linked: the engine switches payouts on under them, same as an adoption
|
||||
const subject = 'You have a new referral on ' + BRAND;
|
||||
const text = name + ' joined ' + BRAND + ' without a sponsor link and told us you invited them, so they are on your team from today. Say hello and help them with their first steps: ' + LINE_URL();
|
||||
if (mailer && mailer.hasKey()) { try { await mailer.send(sp.email, subject, text + '\n\n' + BRAND); } catch (err) {} }
|
||||
if (hooks.notify) { try { await hooks.notify(sp.email, subject, text); } catch (err) {} }
|
||||
return { ok: true, name: nameOf(sp), sponsorEmail: sp.email, member: name };
|
||||
}
|
||||
|
||||
async function adminView() {
|
||||
const recent = await impl().recent(200);
|
||||
const names = {};
|
||||
@@ -574,4 +661,4 @@ async function adminView() {
|
||||
return { waiting: await waiting(), adoptions: recent.map(ad => Object.assign({}, ad, { adopteeName: names[ad.adoptee], adopterName: names[ad.adopter] })), cap: CAP_OPEN, ttlDays: TTL_MS / 86400000, holdHours: READY_MS / 3600000, aligned: alignedRecent(30) };
|
||||
}
|
||||
|
||||
module.exports = { init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };
|
||||
module.exports = { init, view, adopt, holdFor, gate, markReady, readyRec, readyTick, autoAssign, alignToNetwork, alignedRecent, setClock, eligibility, inTank, READY_MS, release, sweep, rescueSweep, rescueInfo, markContacted, adminView, waiting, adoptable, adoptableOf, openedSince, leftText, inviteAsk, dismissInvite, nameSponsor, GRACE_MS, hasOwnBuy, recordGift, onFollow, summaryMap, summaryFor, historyMap, CAP_OPEN, TTL_MS, WARN_DAYS, RESCUE_DAYS, MAX_ADOPTIONS };
|
||||
|
||||
Reference in New Issue
Block a user