Skip to content

Commit 3444552

Browse files
Niloth-psumanthvrao
andcommitted
utils/messages: Add a dummy message for empty narrows.
Tests updated. Co-authored-by: Sumanth V Rao <[email protected]>
1 parent 299a1c1 commit 3444552

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

tests/ui_tools/test_messages.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_init(self, mocker, message_type, set_fields):
4848
display_recipient=[
4949
{"id": 7, "email": "[email protected]", "full_name": "Boo is awesome"}
5050
],
51+
id=457823,
5152
stream_id=5,
5253
subject="hi",
5354
sender_email="[email protected]",
@@ -71,6 +72,7 @@ def test_private_message_to_self(self, mocker):
7172
display_recipient=[
7273
{"full_name": "Foo Foo", "email": "[email protected]", "id": None}
7374
],
75+
id=457823,
7476
sender_id=9,
7577
content="<p> self message. </p>",
7678
sender_full_name="Foo Foo",
@@ -82,6 +84,7 @@ def test_private_message_to_self(self, mocker):
8284
MODULE + ".MessageBox._is_private_message_to_self", return_value=True
8385
)
8486
mocker.patch.object(MessageBox, "main_view")
87+
8588
msg_box = MessageBox(message, self.model, None)
8689

8790
assert msg_box.recipient_emails == ["[email protected]"]
@@ -753,6 +756,7 @@ def test_main_view(self, mocker, message, last_message):
753756
"color": "#bd6",
754757
},
755758
}
759+
self.model.controller.is_in_empty_narrow = False
756760
MessageBox(message, self.model, last_message)
757761

758762
@pytest.mark.parametrize(
@@ -1149,8 +1153,11 @@ def test_main_view_compact_output(
11491153
):
11501154
message_fixture.update({"id": 4})
11511155
varied_message = dict(message_fixture, **to_vary_in_each_message)
1156+
self.model.controller.is_in_empty_narrow = False
11521157
msg_box = MessageBox(varied_message, self.model, varied_message)
1158+
11531159
view_components = msg_box.main_view()
1160+
11541161
assert len(view_components) == 1
11551162
assert isinstance(view_components[0], Padding)
11561163

@@ -1160,7 +1167,9 @@ def test_main_view_generates_EDITED_label(
11601167
messages = messages_successful_response["messages"]
11611168
for message in messages:
11621169
self.model.index["edited_messages"].add(message["id"])
1170+
self.model.controller.is_in_empty_narrow = False
11631171
msg_box = MessageBox(message, self.model, message)
1172+
11641173
view_components = msg_box.main_view()
11651174

11661175
label = view_components[0].original_widget.contents[0]
@@ -1186,6 +1195,7 @@ def test_update_message_author_status(
11861195
):
11871196
message = message_fixture
11881197
last_msg = dict(message, **to_vary_in_last_message)
1198+
self.model.controller.is_in_empty_narrow = False
11891199

11901200
msg_box = MessageBox(message, self.model, last_msg)
11911201

@@ -1389,6 +1399,7 @@ def test_keypress_EDIT_MESSAGE(
13891399
to_vary_in_each_message["subject"] = ""
13901400
varied_message = dict(message_fixture, **to_vary_in_each_message)
13911401
message_type = varied_message["type"]
1402+
self.model.controller.is_in_empty_narrow = False
13921403
msg_box = MessageBox(varied_message, self.model, message_fixture)
13931404
size = widget_size(msg_box)
13941405
msg_box.model.user_id = 1

zulipterminal/ui_tools/messages.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ def __init__(self, message: Message, model: "Model", last_message: Any) -> None:
8282
self.stream_id = self.message["stream_id"]
8383
self.topic_name = self.message["subject"]
8484
else:
85-
self.email = self.message["sender_email"]
86-
self.user_id = self.message["sender_id"]
85+
# Get sender details only for non-empty narrows
86+
if self.message.get("id") is not None:
87+
self.email = self.message["sender_email"]
88+
self.user_id = self.message["sender_id"]
8789

8890
if self._is_private_message_to_self():
8991
recipient = self.message["display_recipient"][0]

zulipterminal/ui_tools/utils.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,46 @@ def create_msg_box_list(
2929
focus_msg = None
3030
last_msg = last_message
3131
muted_msgs = 0 # No of messages that are muted.
32+
33+
# Add a dummy message if no new or old messages are found
34+
if not message_list and not last_msg:
35+
message_type = "stream" if model.stream_id is not None else "private"
36+
dummy_message = {
37+
"id": None,
38+
"content": (
39+
"No search hits" if model.is_search_narrow() else "No messages here"
40+
),
41+
"is_me_message": False,
42+
"flags": ["read"],
43+
"reactions": [],
44+
"type": message_type,
45+
"stream_id": model.stream_id if message_type == "stream" else None,
46+
"stream_name": model.stream_dict[model.stream_id]["name"]
47+
if message_type == "stream"
48+
else None,
49+
"subject": next(
50+
(subnarrow[1] for subnarrow in model.narrow if subnarrow[0] == "topic"),
51+
"No topics in channel",
52+
)
53+
if message_type == "stream"
54+
else None,
55+
"display_recipient": (
56+
model.stream_dict[model.stream_id]["name"]
57+
if message_type == "stream"
58+
else [
59+
{
60+
"email": model.user_id_email_dict[recipient_id],
61+
"full_name": model.user_dict[
62+
model.user_id_email_dict[recipient_id]
63+
]["full_name"],
64+
"id": recipient_id,
65+
}
66+
for recipient_id in model.recipients
67+
]
68+
),
69+
}
70+
message_list.append(dummy_message)
71+
3272
for msg in message_list:
3373
if is_unsubscribed_message(msg, model):
3474
continue

0 commit comments

Comments
 (0)