From 82cddbe9dd4cd2e231391d6b0c5355d78d88ce14 Mon Sep 17 00:00:00 2001
From: Owen Jacobson <owen@grimoire.ca>
Date: Wed, 14 May 2025 00:10:17 -0400
Subject: Consider when a channel was created as part of determining whether it
 has been read.

---
 ui/routes/(app)/+layout.svelte | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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

diff --git a/ui/routes/(app)/+layout.svelte b/ui/routes/(app)/+layout.svelte
index a4ae442..90fa82e 100644
--- a/ui/routes/(app)/+layout.svelte
+++ b/ui/routes/(app)/+layout.svelte
@@ -29,11 +29,13 @@
   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 lastMessage = channelMessages.slice(-1)[0];
-      const lastMessageAt = lastMessage?.at;
+      const sentAt = channelMessages.map((message) => message.at);
+      const lastEventAt = Math.max(createdAt, ...sentAt);
+
       const lastReadAt = channelsMeta.get(ch.id)?.lastReadAt;
-      const hasUnreads = lastReadAt === undefined || lastMessageAt > lastReadAt;
+      const hasUnreads = lastReadAt === undefined || lastEventAt > lastReadAt;
       enrichedChannels.push({
         ...ch,
         hasUnreads
-- 
cgit v1.2.3

