From e4af01e3d4e49ebf4808e9b741a4e012a27465db Mon Sep 17 00:00:00 2001 From: Preet Mishra Date: Wed, 26 Aug 2020 22:10:08 +0530 Subject: [PATCH] README/core/run/views: Add an option to run ZT without marking as read. This introduces an optional argument, --explore/-e, to run the app in an explore mode where messages are not marked as read intentionally. A related suggestion note added in the README. Tests amended and added. Fixes #585. --- README.md | 2 ++ tests/cli/test_run.py | 1 + tests/core/test_core.py | 4 +++- tests/ui/test_ui_tools.py | 19 +++++++++++++++++++ zulipterminal/cli/run.py | 4 ++++ zulipterminal/core.py | 3 ++- zulipterminal/ui_tools/views.py | 4 ++++ 7 files changed, 35 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c9d75f305b..8f70bae6e7 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ If it doesn't find this file, you have two options: Your personal zuliprc file can be obtained from Zulip servers in your account settings in the web application, which gives you all the permissions you have there. Bot zuliprc files can be downloaded from a similar area for each bot, and will have more limited permissions. +We suggest running `zulip-term` using the `-e` or `--explore` option (in explore mode) when you are trying Zulip Terminal for the first time, where we intentionally do not mark messages as read. + ## Configuration The `zuliprc` file contains information to connect to your chat server in the `[api]` section, but also optional configuration for `zulip-term` in the `[zterm]` section: diff --git a/tests/cli/test_run.py b/tests/cli/test_run.py index 436ec851a5..459aa8272f 100644 --- a/tests/cli/test_run.py +++ b/tests/cli/test_run.py @@ -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 diff --git a/tests/core/test_core.py b/tests/core/test_core.py index 4404983026..a7f4ccb503 100644 --- a/tests/core/test_core.py +++ b/tests/core/test_core.py @@ -29,10 +29,12 @@ def controller(self, mocker) -> None: self.config_file = 'path/to/zuliprc' self.theme = 'default' + self.in_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.in_explore_mode, self.autohide, self.notify_enabled, self.footlinks_enabled) result.view.message_view = mocker.Mock() # set in View.__init__ return result diff --git a/tests/ui/test_ui_tools.py b/tests/ui/test_ui_tools.py index 9172eadf5b..f349ffacd7 100644 --- a/tests/ui/test_ui_tools.py +++ b/tests/ui/test_ui_tools.py @@ -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.in_explore_mode = False msg_view.log = mocker.Mock() msg_view.body = mocker.Mock() msg_w = mocker.MagicMock() @@ -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_in_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.in_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") @@ -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.in_explore_mode = False msg_view.read_message() @@ -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.in_explore_mode = False msg_view.log = [0, 1] msg_view.body = mocker.Mock() msg_view.update_search_box_narrow = mocker.Mock() diff --git a/zulipterminal/cli/run.py b/zulipterminal/cli/run.py index 9ce24a5dfe..f45701c77d 100755 --- a/zulipterminal/cli/run.py +++ b/zulipterminal/cli/run.py @@ -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', @@ -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', diff --git a/zulipterminal/core.py b/zulipterminal/core.py index 840d0491c8..2f94774ab3 100644 --- a/zulipterminal/core.py +++ b/zulipterminal/core.py @@ -29,10 +29,11 @@ class Controller: """ def __init__(self, config_file: str, theme: ThemeSpec, - color_depth: int, + color_depth: int, in_explore_mode: bool, autohide: bool, notify: bool, footlinks: bool) -> None: self.theme = theme self.color_depth = color_depth + self.in_explore_mode = in_explore_mode self.autohide = autohide self.notify_enabled = notify self.footlinks_enabled = footlinks diff --git a/zulipterminal/ui_tools/views.py b/zulipterminal/ui_tools/views.py index 97937a9d28..885a84ce0a 100644 --- a/zulipterminal/ui_tools/views.py +++ b/zulipterminal/ui_tools/views.py @@ -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.in_explore_mode: + return + # Do not read messages in any search narrow. if self.model.is_search_narrow(): return