Alerts overlay: show messages approved after later donations (recent mode with client-side dedupe)
Test and Release / test (push) Successful in 1m10s
Test and Release / release (push) Successful in 5s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-15 12:26:03 -08:00
1 parent 875ca42054
commit f7ff1dc717
7 files changed
+170 -24

No files matched your search

+20 -4
View File
@@ -5,7 +5,7 @@
var endpoint = body.getAttribute('data-endpoint');
var poll = Math.max(1000, parseInt(body.getAttribute('data-poll'), 10) || 2500);
var root = document.getElementById('sg-root');
var etag = null, failures = 0, since = null, skew = 0, timerState = null;
var etag = null, failures = 0, skew = 0, timerState = null;
var queue = [], showing = false;
function el(tag, cls, text) {
@@ -92,9 +92,25 @@
}
// ---- alerts ----
// Why not a `since` cursor: with moderation, a held donation keeps a low id. If a newer donation is shown
// first, the cursor moves past it and the later approval would never be returned. So we poll ?recent=1
// (newest 20 approved alerts) and dedupe by id here. First successful poll only seeds seenIds, so
// refreshing OBS never replays old alerts. Limit: a message approved after 20+ newer donations is
// no longer in the window and is not shown.
var seenIds = {}, seenOrder = [], firstAlertPoll = true, SEEN_MAX = 200;
function markSeen(id) {
seenIds[id] = true; seenOrder.push(id);
while (seenOrder.length > SEEN_MAX) delete seenIds[seenOrder.shift()];
}
function renderAlerts(d) {
since = d.last_id;
for (var i = 0; i < d.alerts.length; i++) queue.push(d.alerts[i]);
var list = (d.alerts || []).slice().sort(function (a, b) { return a.id - b.id; });
for (var i = 0; i < list.length; i++) {
var a = list[i];
if (seenIds[a.id]) continue;
markSeen(a.id);
if (!firstAlertPoll) queue.push(a);
}
firstAlertPoll = false;
next();
}
function next() {
@@ -126,7 +142,7 @@
// ---- polling ----
function url() {
var u = endpoint;
if (widget === 'alerts' && since !== null) u += (u.indexOf('?') < 0 ? '?' : '&') + 'since=' + encodeURIComponent(since);
if (widget === 'alerts') u += (u.indexOf('?') < 0 ? '?' : '&') + 'recent=1';
return u;
}
function schedule() {