Skip to content

Commit 00b1a0f

Browse files
committed
bug: Integrate placeholder in create_message_box.
1 parent 2eebda5 commit 00b1a0f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

zulipterminal/ui_tools/utils.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import urwid
88

99
from zulipterminal.api_types import Message
10-
from zulipterminal.ui_tools.messages import MessageBox
11-
10+
from zulipterminal.ui_tools.messages import MessageBox,PlaceholderMessageBox
11+
from typing import List, Any
1212

1313
def create_msg_box_list(
1414
model: Any,
@@ -23,7 +23,14 @@ def create_msg_box_list(
2323
if not model.narrow and messages is None:
2424
messages = list(model.index["all_msg_ids"])
2525
if messages is not None:
26-
message_list = [model.index["messages"][id] for id in messages]
26+
message_list = [model.index["messages"][id] for id in messages if id in model.index["messages"]]
27+
else:
28+
message_list = []
29+
if not message_list:
30+
placeholder = urwid.AttrMap(PlaceholderMessageBox("No messages here"), None, "msg_selected")
31+
model.set_focus_in_current_narrow(0)
32+
return [placeholder]
33+
2734
message_list.sort(key=lambda msg: msg["timestamp"])
2835
w_list = []
2936
focus_msg = None
@@ -32,30 +39,29 @@ def create_msg_box_list(
3239
for msg in message_list:
3340
if is_unsubscribed_message(msg, model):
3441
continue
35-
# Remove messages of muted topics / streams.
3642
if is_muted(msg, model):
3743
muted_msgs += 1
3844
if model.narrow == []: # Don't show in 'All messages'.
3945
continue
4046
msg_flag: Optional[str] = "unread"
4147
flags = msg.get("flags")
42-
# update_messages sends messages with no flags
43-
# but flags are set to [] when fetching old messages.
4448
if flags and ("read" in flags):
4549
msg_flag = None
46-
elif focus_msg is None:
50+
elif (focus_msg is None) and (last_msg is None): # type: ignore[redundant-expr]
4751
focus_msg = message_list.index(msg) - muted_msgs
4852
if msg["id"] == focus_msg_id:
4953
focus_msg = message_list.index(msg) - muted_msgs
54+
# Skip invalid last_msg from placeholder
55+
if last_msg and "type" not in last_msg:
56+
last_msg = None
5057
w_list.append(
5158
urwid.AttrMap(MessageBox(msg, model, last_msg), msg_flag, "msg_selected")
5259
)
5360
last_msg = msg
5461
if focus_msg is not None:
5562
model.set_focus_in_current_narrow(focus_msg)
56-
return w_list
57-
5863

64+
return w_list
5965
# The SIM114 warnings are ignored here since combining the branches would be less clear
6066
def is_muted(msg: Message, model: Any) -> bool:
6167
# PMs cannot be muted

0 commit comments

Comments
 (0)