From ba616be126f41f50e8bc09bee06d7343ed935e73 Mon Sep 17 00:00:00 2001
From: Ramon Souza <contato@ramonsouza.com>
Date: Tue, 11 May 2021 17:30:06 -0300
Subject: [PATCH] handle new message auto-scroll in chat

---
 .../components/chat/time-window-list/component.jsx | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/bigbluebutton-html5/imports/ui/components/chat/time-window-list/component.jsx b/bigbluebutton-html5/imports/ui/components/chat/time-window-list/component.jsx
index 2e2e54d000..1cb7e7eeb7 100644
--- a/bigbluebutton-html5/imports/ui/components/chat/time-window-list/component.jsx
+++ b/bigbluebutton-html5/imports/ui/components/chat/time-window-list/component.jsx
@@ -104,8 +104,19 @@ class TimeWindowList extends PureComponent {
       syncedPercent,
       lastTimeWindowValuesBuild,
       scrollPosition: scrollProps,
+      count
     } = this.props;
 
+    const { userScrolledBack } = this.state;
+
+    if((count > 0 && !userScrolledBack) || userSentMessage){
+      const lastItemIndex = timeWindowsValues.length - 1;
+
+      this.setState({
+        scrollPosition: lastItemIndex,
+      }, ()=> this.handleScrollUpdate(lastItemIndex));
+    }
+
     const {
       timeWindowsValues: prevTimeWindowsValues,
       chatId: prevChatId,
@@ -304,10 +315,11 @@ class TimeWindowList extends PureComponent {
     const {
       scrollArea,
       scrollPosition,
+      userScrolledBack,
     } = this.state;
     ChatLogger.debug('TimeWindowList::render', {...this.props},  {...this.state}, new Date());
 
-    const shouldAutoScroll = !!(scrollPosition && timeWindowsValues.length >= scrollPosition);
+    const shouldAutoScroll = !!(scrollPosition && timeWindowsValues.length >= scrollPosition && !userScrolledBack);
 
     return (
       [<div 
-- 
GitLab