Skip to content

Commit

Permalink
refactor: boxes/buttons/ui: Remove emails from private_box_view.
Browse files Browse the repository at this point in the history
Prior to this commit, everytime the private_box_view had to be initiated
with recipients, the emails of the recipients was also requested along
with their user_ids. This commit removes that parameter and hence
makes the private_box_view reliant on only the list of `user_id`s
received.

Tests updated.
  • Loading branch information
prah23 committed Jul 30, 2021
1 parent 9b357f9 commit 7361354
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 34 deletions.
1 change: 0 additions & 1 deletion tests/ui/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ def test_keypress_OPEN_DRAFT(
)
else:
mocked_private_box_view.assert_called_once_with(
emails=["[email protected]", "[email protected]"],
recipient_user_ids=draft["to"],
)

Expand Down
29 changes: 14 additions & 15 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_init(self, write_box):

def test_not_calling_typing_method_without_recipients(self, mocker, write_box):
write_box.model.send_typing_status_by_user_ids = mocker.Mock()
write_box.private_box_view(emails=[], recipient_user_ids=[])
write_box.private_box_view(recipient_user_ids=[])
# Set idle_status_tracking to True to avoid setting off the
# idleness tracker function.
write_box.idle_status_tracking = True
Expand All @@ -69,10 +69,10 @@ def test_not_calling_typing_method_without_recipients(self, mocker, write_box):
assert not write_box.model.send_typing_status_by_user_ids.called

@pytest.mark.parametrize(
"emails, user_ids, expect_method_called, typing_recipient_user_ids",
"user_ids, expect_method_called, typing_recipient_user_ids",
[
(["[email protected]"], [1001], False, []),
(["[email protected]", "[email protected]"], [1001, 11], True, [11]),
([1001], False, []),
([1001, 11], True, [11]),
],
ids=["pm_only_with_oneself", "group_pm"],
)
Expand All @@ -81,14 +81,15 @@ def test_not_calling_typing_method_to_oneself(
mocker,
write_box,
expect_method_called,
emails,
logged_on_user,
user_ids,
typing_recipient_user_ids,
user_id_email_dict,
):
write_box.model.send_typing_status_by_user_ids = mocker.Mock()
write_box.model.user_id_email_dict = user_id_email_dict
write_box.model.user_id = logged_on_user["user_id"]
write_box.private_box_view(emails=emails, recipient_user_ids=user_ids)
write_box.private_box_view(recipient_user_ids=user_ids)
# Set idle_status_tracking to True to avoid setting off the
# idleness tracker function.
write_box.idle_status_tracking = True
Expand All @@ -115,7 +116,7 @@ def test_not_calling_send_private_message_without_recipients(
self, key, mocker, write_box, widget_size
):
write_box.model.send_private_message = mocker.Mock()
write_box.private_box_view(emails=[], recipient_user_ids=[])
write_box.private_box_view(recipient_user_ids=[])
write_box.msg_write_box.edit_text = "random text"

size = widget_size(write_box)
Expand Down Expand Up @@ -725,11 +726,10 @@ def test__to_box_autocomplete(
],
)
def test__to_box_autocomplete_with_spaces(
self, write_box, text, expected_text, widget_size
self, write_box, text, expected_text, widget_size, user_id_email_dict
):
write_box.private_box_view(
emails=["[email protected]"], recipient_user_ids=[1]
)
write_box.model.user_id_email_dict = user_id_email_dict
write_box.private_box_view(recipient_user_ids=[1])
write_box.to_write_box.set_edit_text(text)
write_box.to_write_box.set_edit_pos(len(text))
write_box.focus_position = write_box.FOCUS_CONTAINER_HEADER
Expand Down Expand Up @@ -1310,18 +1310,17 @@ def test_keypress_MARKDOWN_HELP(self, mocker, write_box, key, widget_size):
],
)
def test_write_box_header_contents(
self, write_box, expected_box_size, mocker, msg_type
self, write_box, expected_box_size, mocker, msg_type, user_id_email_dict
):
mocker.patch(WRITEBOX + "._set_stream_write_box_style")
mocker.patch(WRITEBOX + ".set_editor_mode")
write_box.model.user_id_email_dict = user_id_email_dict
if msg_type == "stream":
write_box.stream_box_view(1000)
elif msg_type == "stream_edit":
write_box.stream_box_edit_view(1000)
else:
write_box.private_box_view(
emails=["[email protected]"], recipient_user_ids=[1]
)
write_box.private_box_view(recipient_user_ids=[1])

assert len(write_box.header_write_box.widget_list) == expected_box_size

Expand Down
5 changes: 0 additions & 5 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,7 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
)
elif saved_draft["type"] == "private":
recipient_user_ids = saved_draft["to"]
recipient_emails = [
self.model.user_id_email_dict[user_id]
for user_id in recipient_user_ids
]
self.write_box.private_box_view(
emails=recipient_emails,
recipient_user_ids=recipient_user_ids,
)
content = saved_draft["content"]
Expand Down
16 changes: 6 additions & 10 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,21 @@ def send_stop_typing_status(self) -> None:
def private_box_view(
self,
*,
emails: Optional[List[str]] = None,
recipient_user_ids: Optional[List[int]] = None,
) -> None:
# Neither or both arguments should be set
assert (emails is not None and recipient_user_ids is not None) or (
emails is None and recipient_user_ids is None
)

self.set_editor_mode()

if recipient_user_ids and emails:
if recipient_user_ids:
self._set_regular_and_typing_recipient_user_ids(recipient_user_ids)
self.recipient_emails = emails
self.recipient_emails = [
self.model.user_id_email_dict[user_id]
for user_id in self.recipient_user_ids
]
recipient_info = ", ".join(
[
f"{self.model.user_dict[email]['full_name']} <{email}>"
for email in emails
for email in self.recipient_emails
]
)
else:
Expand Down Expand Up @@ -1586,7 +1584,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("REPLY_MESSAGE", key):
if self.message["type"] == "private":
self.model.controller.view.write_box.private_box_view(
emails=self.recipient_emails,
recipient_user_ids=self.recipient_ids,
)
elif self.message["type"] == "stream":
Expand Down Expand Up @@ -1657,7 +1654,6 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
elif is_command_key("REPLY_AUTHOR", key):
# All subscribers from recipient_ids are not needed here.
self.model.controller.view.write_box.private_box_view(
emails=[self.message["sender_email"]],
recipient_user_ids=[self.message["sender_id"]],
)
elif is_command_key("MENTION_REPLY", key):
Expand Down
4 changes: 1 addition & 3 deletions zulipterminal/ui_tools/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ def _narrow_with_compose(self) -> None:
recipient_emails=[self.email],
)
self._view.body.focus.original_widget.set_focus("footer")
self._view.write_box.private_box_view(
emails=[self.email], recipient_user_ids=[self.user_id]
)
self._view.write_box.private_box_view(recipient_user_ids=[self.user_id])

def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("USER_INFO", key):
Expand Down

0 comments on commit 7361354

Please sign in to comment.