Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not mark as read on search narrows #723

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test_read_message(self, mocker, msg_box):
mocker.patch(VIEWS + ".MessageView.set_focus")
mocker.patch(VIEWS + ".MessageView.update_search_box_narrow")
msg_view = MessageView(self.model)
msg_view.model.is_search_narrow = lambda: False
msg_view.log = mocker.Mock()
msg_view.body = mocker.Mock()
msg_w = mocker.MagicMock()
Expand Down Expand Up @@ -368,12 +369,29 @@ def test_read_message_no_msgw(self, mocker, msg_view):

self.model.mark_message_ids_as_read.assert_not_called()

def test_read_message_search_narrow(self, mocker, msg_box):
mocker.patch(VIEWS + ".MessageView.main_view", return_value=[msg_box])
mocker.patch(VIEWS + ".MessageView.set_focus")
mocker.patch(VIEWS + ".MessageView.update_search_box_narrow")
msg_view = MessageView(self.model)
msg_view.model.controller.view = mocker.Mock()
msg_w = mocker.Mock()
msg_view.body = mocker.Mock()
msg_view.body.get_focus.return_value = (msg_w, 0)
msg_view.model.is_search_narrow = lambda: True

msg_view.read_message()

assert msg_view.update_search_box_narrow.called
assert not self.model.mark_message_ids_as_read.called

def test_read_message_last_unread_message_focused(self, mocker,
message_fixture,
empty_index, msg_box):
mocker.patch(VIEWS + ".MessageView.main_view", return_value=[msg_box])
mocker.patch(VIEWS + ".MessageView.set_focus")
msg_view = MessageView(self.model)
msg_view.model.is_search_narrow = lambda: False
msg_view.log = [0, 1]
msg_view.body = mocker.Mock()
msg_view.update_search_box_narrow = mocker.Mock()
Expand Down
5 changes: 5 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ def read_message(self, index: int=-1) -> None:
if msg_w is None:
return
self.update_search_box_narrow(msg_w.original_widget)

# Do not read messages in any search narrow.
if self.model.is_search_narrow():
return

# If this the last message in the view and focus is set on this message
# then read the message.
last_message_focused = (curr_pos == len(self.log) - 1)
Expand Down