diff --git a/server.js b/server.js index e9f3ea3..e72fb8e 100644 --- a/server.js +++ b/server.js @@ -148,7 +148,22 @@ async function handleSubmitId(req, res) { firePostback(clickid, `purchase-${clickid}`, source); let msg; if (joinPath === 'rotation') { - msg = `šŸ”” RM Circle: ROTATION JOIN CONFIRMED āœ…\nName: ${memberName}\nNew ID: ${newId} (${onchain.tierName}, verified on-chain)\nJoined under rotation sponsor: #${onchain.referrerId}\nSource: ${source||'(direct)'}\n→ +1 direct for ID ${active.id}; add ${memberName} (ID ${newId}) to the rotation queue.`; + // rotation joins go straight into the queue as waiting positions — no manual step + let queueNote = ''; + try { + let sponsors = getSponsors(); + if (sponsors.some(s => String(s.id) === String(newId))) { + queueNote = 'Already in the rotation queue.'; + } else { + const maxOrder = sponsors.reduce((m, s) => Math.max(m, s.sortOrder || 0), 0); + sponsors.push({ id: String(newId), name: memberName, parentId: String(active.id), directs: 0, level: onchain.levelName || 'Scintilla', status: sponsors.some(s => s.status === 'active') ? 'waiting' : 'active', sortOrder: maxOrder + 10, clicks: 0, notes: `auto-added: rotation join ${new Date().toISOString().slice(0, 10)}` }); + sponsors = normalizeStatuses(sponsors); + saveSponsors(sponsors); + const waitingAhead = sponsors.filter(s => s.status === 'waiting' && (s.sortOrder || 0) < maxOrder + 10).length; + queueNote = `Auto-added to the rotation queue (${waitingAhead} waiting ahead of them).`; + } + } catch (e) { queueNote = `⚠ Auto-add to queue failed (${e.message}) — add manually.`; console.error('queue auto-add', e.message); } + msg = `šŸ”” RM Circle: ROTATION JOIN CONFIRMED āœ…\nName: ${memberName}\nNew ID: ${newId} (${onchain.tierName}, verified on-chain)\nJoined under rotation sponsor: #${onchain.referrerId}\nSource: ${source||'(direct)'}\nāœ… ${queueNote}\n(+1 direct for ID ${active.id} syncs from the chain automatically.)`; } else if (joinPath === 'leg') { msg = `🌱 RM Circle: TEAM-BUILD JOIN (not rotation)\nName: ${memberName}\nNew ID: ${newId} (${onchain.tierName}, verified on-chain)\nActual sponsor on-chain: #${onchain.referrerId}${sponsorId!=='?'&&String(onchain.referrerId)!==sponsorId?` (form said ${sponsorId})`:''}\nSource: ${source||'(direct)'}\n→ Leg growth under #${onchain.referrerId} — no rotation action needed. Add them to the rotation queue only if they want the team effort.`; } else if (joinPath === 'notfound') {