From 8e440b8f0fa74bdb0e41f0db06bb057eaced3309 Mon Sep 17 00:00:00 2001
From: Kristina <kristin.fefelova@gmail.com>
Date: Tue, 11 Jun 2024 18:30:54 +0400
Subject: [PATCH] Fix scroll to new messages (#5782)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
---
 plugins/chunter-resources/src/components/Channel.svelte       | 2 +-
 .../chunter-resources/src/components/ChannelScrollView.svelte | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/plugins/chunter-resources/src/components/Channel.svelte b/plugins/chunter-resources/src/components/Channel.svelte
index b6555074ac..8820054676 100644
--- a/plugins/chunter-resources/src/components/Channel.svelte
+++ b/plugins/chunter-resources/src/components/Channel.svelte
@@ -71,7 +71,7 @@
       // For now loading all messages for documents with activity. Need to correct handle aggregation with pagination.
       // Perhaps we should load all activity messages once, and keep loading in chunks only for ChatMessages then merge them correctly with activity messages
       const loadAll = isDocChannel
-      dataProvider = new ChannelDataProvider(attachedTo, _class, lastViewedTimestamp, selectedMessageId, loadAll)
+      dataProvider = new ChannelDataProvider(attachedTo, _class, lastViewedTimestamp ?? 0, selectedMessageId, loadAll)
     }
   }
 </script>
diff --git a/plugins/chunter-resources/src/components/ChannelScrollView.svelte b/plugins/chunter-resources/src/components/ChannelScrollView.svelte
index 5763ea9adf..8e4b92eaac 100644
--- a/plugins/chunter-resources/src/components/ChannelScrollView.svelte
+++ b/plugins/chunter-resources/src/components/ChannelScrollView.svelte
@@ -425,9 +425,9 @@
         autoscroll = false
       })
     } else if (separatorElement) {
-      isScrollInitialized = true
       await wait()
       scrollToSeparator()
+      isScrollInitialized = true
       isInitialScrolling = false
     }
   }
@@ -554,7 +554,7 @@
   beforeUpdate(() => {
     if (!scrollElement) return
 
-    if (scrollElement.scrollHeight === scrollElement.clientHeight) {
+    if (isScrollInitialized && scrollElement.scrollHeight === scrollElement.clientHeight) {
       isScrollAtBottom = true
     }
   })