From 43af74832f9a2fa7f40dc71985eec9b0ada087dd Mon Sep 17 00:00:00 2001 From: Kit La Touche Date: Tue, 11 Feb 2025 23:16:16 -0500 Subject: Merge local channel data and remote to maintain state When we hit the boot endpoint, we get the server's view of things. If we just setChannels with that, we overwrite all our locally-stored info in on things like lastReadAt. So we need to merge data. Eventually, this might militate for a `meta` key containing an object of locally stored data, rather than having to handle each key specially. --- ui/routes/(app)/ch/[channel]/+page.svelte | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'ui/routes') diff --git a/ui/routes/(app)/ch/[channel]/+page.svelte b/ui/routes/(app)/ch/[channel]/+page.svelte index dbdb507..d64a8c9 100644 --- a/ui/routes/(app)/ch/[channel]/+page.svelte +++ b/ui/routes/(app)/ch/[channel]/+page.svelte @@ -33,16 +33,10 @@ } function setLastRead() { - const channelObject = $channelsList.getChannel(channel); const lastInView = getLastVisibleMessage(); - if (!channelObject || !lastInView) { - return; - } - const at = DateTime.fromISO(lastInView.dataset.at); - // Do it this way, rather than with Math.max tricks, to avoid assignment - // when we don't need it, to minimize reactive changes: - if (at > channelObject.lastReadAt) { - channelObject.lastReadAt = at; + if (lastInView) { + const at = DateTime.fromISO(lastInView.dataset.at); + $channelsList.updateLastReadAt(channel, at); } } -- cgit v1.2.3