Skip to content

Commit 2b8a305

Browse files
mkp6781neiljp
authored andcommitted
ui/boxes: Improve consistency of non-reply compose key behaviour.
Previously, `x` started a new message as expected from all locations, with no pre-filled recipient. In contrast, `c` would act as per the reply key on a private message, would pre-fill the private recipients or stream, and was configured for use only when focus was on the `MiddleColumnView`. Now keypresses `x` and `c` always open up `private_box_view` and `stream_box_view` respectively, with no boxes pre-filled. The scope of `c` is expanded to enable its use even when focus is on the users list, stream list, topics list, or top buttons. Note that this behavior is slightly different from the webapp, where in a stream narrow, `c` pre-fills the stream and prompts for a topic. This is a slight change in behavior to before within the application too. Tests added, and adjusted slightly by neiljp. Fixes #871.
1 parent 96b3637 commit 2b8a305

File tree

4 files changed

+51
-6
lines changed

4 files changed

+51
-6
lines changed

tests/ui/test_ui.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@ def test_keypress_ALL_MENTIONS(self, view, mocker, key, widget_size):
243243
view.model.controller.show_all_mentions.assert_called_once_with(view)
244244
assert view.body.focus_col == 1
245245

246+
@pytest.mark.parametrize('key', keys_for_command('STREAM_MESSAGE'))
247+
def test_keypress_STREAM_MESSAGE(self, view, mocker, key, widget_size):
248+
view.middle_column = mocker.Mock()
249+
view.body = mocker.Mock()
250+
view.controller.is_in_editor_mode = lambda: False
251+
size = widget_size(view)
252+
253+
returned_key = view.keypress(size, key)
254+
255+
view.middle_column.keypress.assert_called_once_with(size, key)
256+
assert returned_key == key
257+
assert view.body.focus_col == 1
258+
246259
@pytest.mark.parametrize('key', keys_for_command('SEARCH_PEOPLE'))
247260
@pytest.mark.parametrize('autohide', [True, False], ids=[
248261
'autohide', 'no_autohide'])

tests/ui/test_ui_tools.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,40 @@ def test_main_view_generates_EDITED_label(self, mocker,
18581858
assert label[0].text == 'EDITED'
18591859
assert label[1][1] == 7
18601860

1861+
@pytest.mark.parametrize('key', keys_for_command('STREAM_MESSAGE'))
1862+
@pytest.mark.parametrize('narrow, expect_to_prefill', [
1863+
([], False),
1864+
([['stream', 'general']], False),
1865+
([['stream', 'general'], ['topic', 'Test']], True),
1866+
([['is', 'starred']], False),
1867+
([['is', 'mentioned']], False),
1868+
([['is', 'private']], False),
1869+
([['pm_with', '[email protected]']], False),
1870+
], ids=[
1871+
'all_messages_narrow',
1872+
'stream_narrow',
1873+
'topic_narrow',
1874+
'private_conversation_narrow',
1875+
'starred_messages_narrow',
1876+
'mentions_narrow',
1877+
'private_messages_narrow',
1878+
])
1879+
def test_keypress_STREAM_MESSAGE(self, mocker, msg_box, widget_size,
1880+
narrow, expect_to_prefill, key):
1881+
write_box = msg_box.model.controller.view.write_box
1882+
msg_box.model.narrow = narrow
1883+
size = widget_size(msg_box)
1884+
1885+
msg_box.keypress(size, key)
1886+
1887+
if expect_to_prefill:
1888+
write_box.stream_box_view.assert_called_once_with(
1889+
caption='PTEST',
1890+
stream_id=205,
1891+
)
1892+
else:
1893+
write_box.stream_box_view.assert_called_once_with(0)
1894+
18611895
@pytest.mark.parametrize('key', keys_for_command('EDIT_MESSAGE'))
18621896
@pytest.mark.parametrize(['to_vary_in_each_message',
18631897
'realm_editing_allowed',

zulipterminal/ui.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def keypress(self, size: Tuple[int, int], key: str) -> Optional[str]:
183183
elif (is_command_key('SEARCH_MESSAGES', key)
184184
or is_command_key('NEXT_UNREAD_TOPIC', key)
185185
or is_command_key('NEXT_UNREAD_PM', key)
186+
or is_command_key('STREAM_MESSAGE', key)
186187
or is_command_key('PRIVATE_MESSAGE', key)):
187188
self.body.focus_col = 1
188189
self.middle_column.keypress(size, key)

zulipterminal/ui_tools/boxes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,16 +1388,13 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
13881388
stream_id=self.stream_id,
13891389
)
13901390
elif is_command_key('STREAM_MESSAGE', key):
1391-
if self.message['type'] == 'private':
1392-
self.model.controller.view.write_box.private_box_view(
1393-
emails=self.recipient_emails,
1394-
recipient_user_ids=self.recipient_ids,
1395-
)
1396-
elif self.message['type'] == 'stream':
1391+
if len(self.model.narrow) == 2:
13971392
self.model.controller.view.write_box.stream_box_view(
13981393
caption=self.message['display_recipient'],
13991394
stream_id=self.stream_id,
14001395
)
1396+
else:
1397+
self.model.controller.view.write_box.stream_box_view(0)
14011398
elif is_command_key('STREAM_NARROW', key):
14021399
if self.message['type'] == 'private':
14031400
self.model.controller.narrow_to_user(self)

0 commit comments

Comments
 (0)