From ba943ec58fa256cb2892bece64b62efe93b0dbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Wed, 11 Sep 2019 21:05:59 +0200 Subject: [PATCH] commans: Fix the page up command on an empty buffer. --- main.py | 3 +-- matrix/commands.py | 4 +++- matrix/server.py | 9 ++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 2b5cf07..67a31be 100644 --- a/main.py +++ b/main.py @@ -586,8 +586,7 @@ def buffer_switch_cb(_, _signal, buffer_ptr): if room_buffer.first_view and room_buffer.weechat_buffer.num_lines < 10: # TODO we may want to fetch 10 - num_lines messages here for # consistency reasons. - if server.room_get_messages(room_buffer.room.room_id): - room_buffer.first_view = True + server.room_get_messages(room_buffer.room.room_id): break diff --git a/matrix/commands.py b/matrix/commands.py index f2f15fd..c73a688 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -1053,7 +1053,9 @@ def matrix_command_pgup_cb(data, buffer, command): W.window_get_integer(window, "first_line_displayed") ) - if first_line_displayed: + room_buffer = server.find_room_from_ptr(buffer) + + if first_line_displayed or room_buffer.weechat_buffer.num_lines == 0: room_id = key_from_value(server.buffers, buffer) server.room_get_messages(room_id) diff --git a/matrix/server.py b/matrix/server.py index a78cc73..57bd4dc 100644 --- a/matrix/server.py +++ b/matrix/server.py @@ -907,16 +907,16 @@ class MatrixServer(object): def room_get_messages(self, room_id): if not self.connected or not self.client.logged_in: - return + return False room_buffer = self.find_room_from_id(room_id) # We're already fetching old messages if room_buffer.backlog_pending: - return + return False if not room_buffer.prev_batch: - return + return False uuid, request = self.client.room_messages( room_id, @@ -927,6 +927,8 @@ class MatrixServer(object): self.backlog_queue[uuid] = room_id self.send_or_queue(request) + return True + def room_send_read_marker(self, room_id, event_id): """Send read markers for the provided room. @@ -1248,6 +1250,7 @@ class MatrixServer(object): def handle_backlog_response(self, response): room_id = self.backlog_queue.pop(response.uuid) room_buffer = self.find_room_from_id(room_id) + room_buffer.first_view = False room_buffer.handle_backlog(response)