summaryrefslogtreecommitdiff
path: root/ui/lib
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-05-15 19:58:35 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-05-15 19:58:35 -0400
commitaf8dc0198c6a22996ce54690cf7141694dd11eaf (patch)
treec58a037501f53047157e6dea0bc873334897e035 /ui/lib
parenta38a449ab78a4e8ab56705922f5c13f9365a92a4 (diff)
Fix up spots where we still tried to treat `remote.channels.all` as a map.
In ae93188f0f4f36086622636ba9ae4810cbd1f8c9, `remote.channels.all` became a flat array of channels, instead of a map, in order to simplify some of the reasoning around how state changes propagate. However, I neglected to remove all Map-shaped calls referring to it. This lead to some pretty interesting behaviour: * The client could not track unread state, because reconciling local state against the remote state would find no remote state, then throw away local state entirely as a result. * The client would not actually update when a new channel appeared. * The client would not actually update when a channel disappeared.
Diffstat (limited to 'ui/lib')
-rw-r--r--ui/lib/session.svelte.js2
-rw-r--r--ui/lib/state/local/channels.svelte.js3
-rw-r--r--ui/lib/state/remote/channels.svelte.js4
3 files changed, 5 insertions, 4 deletions
diff --git a/ui/lib/session.svelte.js b/ui/lib/session.svelte.js
index 2dae3c4..0b754e5 100644
--- a/ui/lib/session.svelte.js
+++ b/ui/lib/session.svelte.js
@@ -114,7 +114,7 @@ class Session {
onMessage(message) {
const event = JSON.parse(message.data);
this.remote.onEvent(event);
- this.local.retainChannels(this.remote.channels.all.keys());
+ this.local.retainChannels(this.remote.channels.all);
this.watchdog.reset(this.heartbeatMillis());
}
diff --git a/ui/lib/state/local/channels.svelte.js b/ui/lib/state/local/channels.svelte.js
index d86d028..e3ee8df 100644
--- a/ui/lib/state/local/channels.svelte.js
+++ b/ui/lib/state/local/channels.svelte.js
@@ -82,7 +82,8 @@ export class Channels {
}
}
- retainChannels(channelIds) {
+ retainChannels(channels) {
+ const channelIds = channels.map((channel) => channel.id);
const retain = new Set(channelIds);
for (const channelId of Array.from(this.all.keys())) {
if (!retain.has(channelId)) {
diff --git a/ui/lib/state/remote/channels.svelte.js b/ui/lib/state/remote/channels.svelte.js
index 8b190dd..19946f2 100644
--- a/ui/lib/state/remote/channels.svelte.js
+++ b/ui/lib/state/remote/channels.svelte.js
@@ -29,10 +29,10 @@ export class Channels {
}
add({ at, id, name }) {
- this.all.set(id, Channel.boot({ at, id, name }));
+ this.all.push(Channel.boot({ at, id, name }));
}
remove(id) {
- this.all.delete(id);
+ this.all = this.all.filter((channel) => channel.id !== id);
}
}