7
7
import urwid
8
8
9
9
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
12
12
13
13
def create_msg_box_list (
14
14
model : Any ,
@@ -23,7 +23,14 @@ def create_msg_box_list(
23
23
if not model .narrow and messages is None :
24
24
messages = list (model .index ["all_msg_ids" ])
25
25
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
+
27
34
message_list .sort (key = lambda msg : msg ["timestamp" ])
28
35
w_list = []
29
36
focus_msg = None
@@ -32,30 +39,29 @@ def create_msg_box_list(
32
39
for msg in message_list :
33
40
if is_unsubscribed_message (msg , model ):
34
41
continue
35
- # Remove messages of muted topics / streams.
36
42
if is_muted (msg , model ):
37
43
muted_msgs += 1
38
44
if model .narrow == []: # Don't show in 'All messages'.
39
45
continue
40
46
msg_flag : Optional [str ] = "unread"
41
47
flags = msg .get ("flags" )
42
- # update_messages sends messages with no flags
43
- # but flags are set to [] when fetching old messages.
44
48
if flags and ("read" in flags ):
45
49
msg_flag = None
46
- elif focus_msg is None :
50
+ elif ( focus_msg is None ) and ( last_msg is None ): # type: ignore[redundant-expr]
47
51
focus_msg = message_list .index (msg ) - muted_msgs
48
52
if msg ["id" ] == focus_msg_id :
49
53
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
50
57
w_list .append (
51
58
urwid .AttrMap (MessageBox (msg , model , last_msg ), msg_flag , "msg_selected" )
52
59
)
53
60
last_msg = msg
54
61
if focus_msg is not None :
55
62
model .set_focus_in_current_narrow (focus_msg )
56
- return w_list
57
-
58
63
64
+ return w_list
59
65
# The SIM114 warnings are ignored here since combining the branches would be less clear
60
66
def is_muted (msg : Message , model : Any ) -> bool :
61
67
# PMs cannot be muted
0 commit comments