changeset 2335:b226f545f67e

primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)
author Goffi <goffi@goffi.org>
date Mon, 17 Jul 2017 16:20:55 +0200 (2017-07-17)
parents ca14e1ced3b5
children a7438fe4e24d
files frontends/src/primitivus/chat.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/src/primitivus/chat.py	Fri Jul 14 09:06:03 2017 +0200
+++ b/frontends/src/primitivus/chat.py	Mon Jul 17 16:20:55 2017 +0200
@@ -405,6 +405,14 @@
         else:
             return info_type in quick_chat.ROOM_USER_MOVED
 
+    def _scrollDown(self):
+        """scroll down message only if we are already at the bottom (minus 1)"""
+        current_focus = self.mess_widgets.focus_position
+        bottom = len(self.mess_walker) - 1
+        if current_focus == bottom - 1:
+            self.mess_widgets.focus_position = bottom  # scroll down
+        self.host.redraw()  # FIXME: should not be necessary
+
     def appendMessage(self, message):
         """Create a MessageWidget and append it
 
@@ -442,6 +450,7 @@
                 self.focus_marker = urwid.Divider('—')
                 self.mess_walker.append(self.focus_marker)
                 self.focus_marker_set = True
+                self._scrollDown()
         else:
             if self.focus_marker_set:
                 self.focus_marker_set = False
@@ -451,11 +460,7 @@
         else:
             wid = MessageWidget(message)
             self.mess_walker.append(wid)
-            current_focus = self.mess_widgets.focus_position
-            bottom = len(self.mess_walker) - 1
-            if current_focus == bottom - 1:
-                self.mess_widgets.focus_position = bottom  # scroll down
-            self.host.redraw()  # FIXME: should not be necessary
+            self._scrollDown()
             if self._user_moved(message):
                 return  # no notification for moved messages