Skip to content

Commit

Permalink
core/run/views: Add an option to run the app without marking as read.
Browse files Browse the repository at this point in the history
This introduces an optional argument, --explore/-e, to run the app in an
explore mode where messages are not marked as read intentionally.

Tests amended and added.

Fixes zulip#585.
  • Loading branch information
preetmishra committed Aug 25, 2020
1 parent da539ce commit 2acd8ed
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/cli/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_main_help(capsys, options):
'--autohide',
'--no-autohide',
'-v, --version',
'-e, --explore',
'--color-depth'
}
optional_argument_lines = {line[2:] for line in lines
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ def controller(self, mocker) -> None:

self.config_file = 'path/to/zuliprc'
self.theme = 'default'
self.explore_mode = False
self.autohide = True # FIXME Add tests for no-autohide
self.notify_enabled = False
self.footlinks_enabled = True
result = Controller(self.config_file, self.theme, 256, self.autohide,
result = Controller(self.config_file, self.theme, 256,
self.explore_mode, self.autohide,
self.notify_enabled, self.footlinks_enabled)
result.view.message_view = mocker.Mock() # set in View.__init__
return result
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ def test_read_message(self, mocker, msg_box):
mocker.patch(VIEWS + ".MessageView.update_search_box_narrow")
msg_view = MessageView(self.model, self.view)
msg_view.model.is_search_narrow = lambda: False
msg_view.model.controller.explore_mode = False
msg_view.log = mocker.Mock()
msg_view.body = mocker.Mock()
msg_w = mocker.MagicMock()
Expand Down Expand Up @@ -384,6 +385,22 @@ def test_read_message_no_msgw(self, mocker, msg_view):

self.model.mark_message_ids_as_read.assert_not_called()

def test_read_message_explore_mode(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, self.view)
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: False
msg_view.model.controller.explore_mode = 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_search_narrow(self, mocker, msg_box):
mocker.patch(VIEWS + ".MessageView.main_view", return_value=[msg_box])
mocker.patch(VIEWS + ".MessageView.set_focus")
Expand All @@ -394,6 +411,7 @@ def test_read_message_search_narrow(self, mocker, msg_box):
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.model.controller.explore_mode = False

msg_view.read_message()

Expand All @@ -407,6 +425,7 @@ def test_read_message_last_unread_message_focused(self, mocker,
mocker.patch(VIEWS + ".MessageView.set_focus")
msg_view = MessageView(self.model, self.view)
msg_view.model.is_search_narrow = lambda: False
msg_view.model.controller.explore_mode = False
msg_view.log = [0, 1]
msg_view.body = mocker.Mock()
msg_view.update_search_box_narrow = mocker.Mock()
Expand Down
4 changes: 4 additions & 0 deletions zulipterminal/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def parse_args(argv: List[str]) -> argparse.Namespace:
help='Don\'t autohide list of '
'users and streams.')

parser.add_argument('-e', '--explore', action='store_true',
help='Do not mark messages as read in the session.')

parser.add_argument('-v',
'--version',
action='store_true',
Expand Down Expand Up @@ -321,6 +324,7 @@ def main(options: Optional[List[str]]=None) -> None:
Controller(zuliprc_path,
theme_data,
int(args.color_depth),
args.explore,
**boolean_settings).main()
except ServerConnectionFailure as e:
print(in_color('red',
Expand Down
3 changes: 2 additions & 1 deletion zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class Controller:
"""

def __init__(self, config_file: str, theme: ThemeSpec,
color_depth: int,
color_depth: int, explore_mode: bool,
autohide: bool, notify: bool, footlinks: bool) -> None:
self.theme = theme
self.color_depth = color_depth
self.explore_mode = explore_mode
self.autohide = autohide
self.notify_enabled = notify
self.footlinks_enabled = footlinks
Expand Down
4 changes: 4 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ def read_message(self, index: int=-1) -> None:
return
self.update_search_box_narrow(msg_w.original_widget)

# Do not read messages in explore mode.
if self.model.controller.explore_mode:
return

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

0 comments on commit 2acd8ed

Please sign in to comment.