Skip to content

Commit 01fc24a

Browse files
committed
bugfix: model: Improve handling of _have_last_message.
This dict tracks whether the app has the last message in a narrow; this commit fixes the following issues: * There are too many narrows to pre-populate the dict, so ensure we use `.get` when checking it upon receiving a message event. * The value for a narrow was set on each get_message call, but the value from a call is whether the returned messages contain the last message, so use both the previous state (if any) as well as the new state.
1 parent 1be52c5 commit 01fc24a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

zulipterminal/model.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,18 @@ def get_messages(self, *,
461461
if first_anchor and response['anchor'] != 10000000000000000:
462462
self.index['pointer'][narrow_str] = response['anchor']
463463
if 'found_newest' in response:
464-
self._have_last_message[narrow_str] = response['found_newest']
464+
just_found_last_msg = response['found_newest']
465465
else:
466466
# Older versions of the server does not contain the
467467
# 'found_newest' flag. Instead, we use this logic:
468468
query_range = num_after + num_before + 1
469-
self._have_last_message[narrow_str] = (
470-
len(response['messages']) < query_range)
469+
just_found_last_msg = len(response['messages']) < query_range
470+
471+
had_last_msg = self._have_last_message.get(narrow_str, False)
472+
self._have_last_message[narrow_str] = (
473+
had_last_msg or just_found_last_msg
474+
)
475+
471476
return ""
472477
display_error_if_present(response, self.controller)
473478
return response['msg']
@@ -980,7 +985,7 @@ def _handle_message_event(self, event: Event) -> None:
980985
set_count([message['id']], self.controller, 1)
981986

982987
if (hasattr(self.controller, 'view')
983-
and self._have_last_message[repr(self.narrow)]):
988+
and self._have_last_message.get(repr(self.narrow), False)):
984989
msg_log = self.controller.view.message_view.log
985990
if msg_log:
986991
last_message = msg_log[-1].original_widget.message

0 commit comments

Comments
 (0)