From af8dc0198c6a22996ce54690cf7141694dd11eaf Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 15 May 2025 19:58:35 -0400 Subject: 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. --- ui/lib/session.svelte.js | 2 +- ui/lib/state/local/channels.svelte.js | 3 ++- ui/lib/state/remote/channels.svelte.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'ui') 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); } } -- cgit v1.2.3 From 666321324bf8fc7313a5ba73234fc40712fdeaa0 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Thu, 15 May 2025 20:11:16 -0400 Subject: Avoid converting DateTime values into numbers --- ui/lib/session.svelte.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'ui') diff --git a/ui/lib/session.svelte.js b/ui/lib/session.svelte.js index 0b754e5..432fad2 100644 --- a/ui/lib/session.svelte.js +++ b/ui/lib/session.svelte.js @@ -7,14 +7,13 @@ import * as r from './state/remote/state.svelte.js'; import * as l from './state/local/channels.svelte.js'; import { Watchdog } from './watchdog.js'; import { DateTime } from 'luxon'; -import { render } from '$lib/markdown.js'; class Channel { static fromRemote({ at, id, name }, messages, meta) { const sentAt = messages .filter((message) => message.channel === id) .map((message) => message.at); - const lastEventAt = Math.max(at, ...sentAt); + const lastEventAt = DateTime.max(at, ...sentAt); const lastReadAt = meta.get(id)?.lastReadAt; const hasUnreads = lastReadAt === undefined || lastEventAt > lastReadAt; -- cgit v1.2.3