From daaf37a1ed3760f03fceb1123ebe80de3a2f280c Mon Sep 17 00:00:00 2001
From: Kit La Touche <kit@transneptune.net>
Date: Sun, 16 Feb 2025 22:00:57 -0500
Subject: Separate channel metadata out into its own store

This is stored locally, and, while parallel to channel info, is not the
same as.

Eventually, this may hold info about moot/decayed channels, and grow
unbounded. That'll need to be addressed.
---
 ui/routes/(app)/+layout.svelte | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

(limited to 'ui/routes/(app)/+layout.svelte')

diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte
index cbfef54..9ade399 100644
--- a/ui/routes/(app)/+layout.svelte
+++ b/ui/routes/(app)/+layout.svelte
@@ -6,7 +6,7 @@
   import TinyGesture from 'tinygesture';
 
   import { boot, subscribeToEvents } from '$lib/apiServer';
-  import { currentUser, logins, channelsList, messages } from '$lib/store';
+  import { currentUser, logins, channelsList, channelsMetaList, messages } from '$lib/store';
 
   import ChannelList from '$lib/components/ChannelList.svelte';
   import CreateChannelForm from '$lib/components/CreateChannelForm.svelte';
@@ -23,6 +23,10 @@
   channelsList.subscribe((val) => {
     rawChannels = val.channels;
   });
+  let rawChannelsMeta;
+  channelsMetaList.subscribe((val) => {
+    rawChannelsMeta = val.channelsMeta;
+  });
   let rawMessages;
   messages.subscribe((val) => {
     rawMessages = val;
@@ -30,7 +34,9 @@
 
   let enrichedChannels = $derived.by(() => {
     const channels = rawChannels;
+    const channelsMeta = rawChannelsMeta;
     const messages = rawMessages;
+
     const enrichedChannels = [];
     if (channels && messages) {
       for (let ch of channels) {
@@ -38,7 +44,7 @@
         let lastRun = runs?.slice(-1)[0];
         let lastMessage = lastRun?.messages.slice(-1)[0];
         let lastMessageAt = lastMessage?.at;
-        let hasUnreads = lastMessageAt > ch.lastReadAt;
+        let hasUnreads = lastMessageAt > channelsMeta[ch.id]?.lastReadAt;
         enrichedChannels.push({
           ...ch,
           hasUnreads
-- 
cgit v1.2.3

