aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/dashboard/dashboard.html22
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();