Skip to content

Commit 9b237b3

Browse files
committed
bugfix: core: Fix message not focused in all_msg narrow if anchored.
This bugfix allows messages to be focused when narrowing to the "all_messages" narrow from other narrows. The primary bug was if the message from which we press 'a' was not present in model.index['all_msg_ids'], then we were not fetching that from the server. The reason we were not fetching those messages was we only checked if the final narrow is not empty, which in this case will never be, and not if it contains the message we are focusing to. This made the focus to move elsewhere in the "all_messages" narrow. This also fixes part of #934 as a side-effect. Tests added.
1 parent d474ea0 commit 9b237b3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

tests/core/test_core.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,11 @@ def test_narrow_to_user(self, mocker, controller, user_button, index_user):
205205
id_list = index_user["private_msg_ids_by_user_ids"][recipients]
206206
assert {widget.original_widget.message["id"]} == id_list
207207

208-
def test_narrow_to_all_messages(self, mocker, controller, index_all_messages):
208+
@pytest.mark.parametrize("anchor", [None, 537286])
209+
def test_narrow_to_all_messages(
210+
self, mocker, controller, index_all_messages, anchor
211+
):
212+
expected_final_focus_msg_id = 537288 if anchor is None else anchor
209213
controller.model.narrow = [["stream", "PTEST"]]
210214
controller.model.index = index_all_messages
211215
controller.view.message_view = mocker.patch("urwid.ListBox")
@@ -219,15 +223,17 @@ def test_narrow_to_all_messages(self, mocker, controller, index_all_messages):
219223
controller.model.muted_streams = []
220224
controller.model.is_muted_topic = mocker.Mock(return_value=False)
221225

222-
controller.narrow_to_all_messages() # FIXME: Add id narrowing test
226+
controller.narrow_to_all_messages(contextual_message_id=anchor)
223227

224228
assert controller.model.narrow == []
225229
controller.view.message_view.log.clear.assert_called_once_with()
226230

227-
widgets = controller.view.message_view.log.extend.call_args_list[0][0][0]
231+
widgets, focus = controller.view.message_view.log.extend.call_args_list[0][0]
228232
id_list = index_all_messages["all_msg_ids"]
229233
msg_ids = {widget.original_widget.message["id"] for widget in widgets}
234+
final_focus_msg_id = widgets[focus].original_widget.message["id"]
230235
assert msg_ids == id_list
236+
assert final_focus_msg_id == expected_final_focus_msg_id
231237

232238
def test_narrow_to_all_pm(self, mocker, controller, index_user):
233239
controller.model.narrow = []

zulipterminal/core.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,11 @@ def _narrow_to(self, anchor: Optional[int], **narrow: Any) -> None:
392392

393393
msg_id_list = self.model.get_message_ids_in_current_narrow()
394394

395-
# if no messages are found get more messages
396-
if len(msg_id_list) == 0:
395+
# If no messages are found in the current narrow
396+
# OR, given anchor is not present in msg_id_list
397+
# then, get more messages.
398+
# Refer commit 07faeb04ccca7d32f7580e39536cdbb5a190a460 for related bugfix
399+
if len(msg_id_list) == 0 or (anchor is not None and anchor not in msg_id_list):
397400
self.model.get_messages(num_before=30, num_after=10, anchor=anchor)
398401
msg_id_list = self.model.get_message_ids_in_current_narrow()
399402

0 commit comments

Comments
 (0)