diff options
| author | tv <tv@krebsco.de> | 2026-11-07 22:35:10 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-07 22:35:10 +0100 |
| commit | 9296dc40640f1c3c039433ccae6e8b8f8c3eb8ae (patch) | |
| tree | 7323ddde2b75b7286db9c6de993ffd954dcbb203 /src/api | |
| parent | 0e03a77bcb1d39f1fbda23d8e704ac40302afb93 (diff) | |
dashboard: subscriptions under patches
Subscribed nodes' data merged into the state as the page patches it,
not overwritten by the next patch.
Auth plan M3 (fix).
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/dashboard/dashboard.html | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/api/dashboard/dashboard.html b/src/api/dashboard/dashboard.html index 57a3a0f..300f4fe 100644 --- a/src/api/dashboard/dashboard.html +++ b/src/api/dashboard/dashboard.html @@ -2242,10 +2242,8 @@ function toggleSubscription(id) { const entry = subscribed.get(id); if (entry) entry.stop(); subscribed.delete(id); - // Its report as this node has it, if any, at the next update. - if (state.graph.measured[id] && state.graph.measured[id].subscribed) { - delete state.graph.measured[id]; - } + // Its report as this node has it, if any. + unapplySubscriptions(); } else { subscriptions.add(id); follow(id); @@ -2254,9 +2252,15 @@ function toggleSubscription(id) { render(); } // The subscriptions' reports on the map, over what this node has of them: fresher. +// What they cover of the node's state is kept aside (`overlaid`: by node, the node's +// report, or undefined) and put back before a patch from the node applies +// (`unapplySubscriptions`): a patch is onto the node's state, and one onto a report +// the page put there, or took away, would leave half of one. +const overlaid = new Map(); function applySubscriptions() { for (const [id, entry] of subscribed) { if (!entry.report || !state.graph.members[id]) continue; + if (!overlaid.has(id)) overlaid.set(id, state.graph.measured[id]); state.graph.measured[id] = { secsAgo: Math.max(0, Math.floor((stateAt - entry.at) / 1000)), links: entry.report.links || [], @@ -2265,6 +2269,13 @@ function applySubscriptions() { }; } } +function unapplySubscriptions() { + for (const [id, report] of overlaid) { + if (report === undefined) delete state.graph.measured[id]; + else state.graph.measured[id] = report; + } + overlaid.clear(); +} // Tokens: this page's, from logging in on this node (the browser's password for it, or // the proxy's), and a narrower one, reading the member list only, to send to others. // Each refreshed half way through its life. @@ -3189,7 +3200,7 @@ function connect() { } // Changes while not connected went unseen: what is open is read again. if (state !== null) documentChanged({ all: true }); - state = snapshot; stateAt = Date.now(); live = true; + state = snapshot; stateAt = Date.now(); live = true; overlaid.clear(); status("live", true); pulse(); render(); trafficArrived(); epochsArrived(); remakesArrived(); if (treeShown && writerTree === null) loadTree(); @@ -3198,6 +3209,7 @@ function connect() { }); events.addEventListener("patch", event => { if (!state) return; + unapplySubscriptions(); state = mergePatch(state, JSON.parse(event.data)); stateAt = Date.now(); pulse(); render(); trafficArrived(); epochsArrived(); |
