From ae93188f0f4f36086622636ba9ae4810cbd1f8c9 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Wed, 14 May 2025 00:46:13 -0400
Subject: Move derivation of the synthesized view of channels (and messages)
 into `session`.

---
 ui/routes/(app)/+layout.svelte | 26 ++------------------------
 1 file changed, 2 insertions(+), 24 deletions(-)

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

diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte
index 90fa82e..c7e1f22 100644
--- a/ui/routes/(app)/+layout.svelte
+++ b/ui/routes/(app)/+layout.svelte
@@ -22,29 +22,7 @@
   let pageContext = getContext('page');
   let channel = $derived(page.params.channel);
 
-  let rawChannels = $derived(session.channels);
-  let rawChannelsMeta = $derived(session.local.all);
-  let rawMessages = $derived(session.messages);
-
-  function enrichChannels(channels, channelsMeta, messages) {
-    const enrichedChannels = [];
-    for (const ch of channels.values()) {
-      const createdAt = ch.at;
-      const channelMessages = messages.filter((message) => message.channel === ch.id);
-      const sentAt = channelMessages.map((message) => message.at);
-      const lastEventAt = Math.max(createdAt, ...sentAt);
-
-      const lastReadAt = channelsMeta.get(ch.id)?.lastReadAt;
-      const hasUnreads = lastReadAt === undefined || lastEventAt > lastReadAt;
-      enrichedChannels.push({
-        ...ch,
-        hasUnreads
-      });
-    }
-    return enrichedChannels;
-  }
-
-  const enrichedChannels = $derived(enrichChannels(rawChannels, rawChannelsMeta, rawMessages));
+  let channels = $derived(session.channels);
 
   function setUpGestures() {
     if (!browser) {
@@ -136,7 +114,7 @@
 
 <div id="interface">
   <nav id="sidebar" data-expanded={pageContext.showMenu}>
-    <ChannelList active={channel} channels={enrichedChannels} />
+    <ChannelList active={channel} {channels} />
     <div class="create-channel">
       <CreateChannelForm {createChannel} />
     </div>
-- 
cgit v1.2.3

