primitivus(chat): fixed scroll down (was broken when Primitivus had not the focus and was receiving messages)

This commit is contained in:
Goffi 2017-07-17 16:20:55 +02:00
commit 4dea715ec5

View file

@ -405,6 +405,14 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
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 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
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 @@ class Chat(PrimitivusWidget, quick_chat.QuickChat):
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