Skip to content

Commit 2567f87

Browse files
sumanthvraoneiljp
authored andcommitted
refactor: helper: Unify message[id] and msg to message.
1 parent e6b130c commit 2567f87

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

zulipterminal/helper.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ def _set_count_in_model(id_list: List[int], new_count: int,
9393
if it's passed in, but is not tied to it).
9494
"""
9595
for id in id_list:
96-
msg = messages[id]
96+
message = messages[id]
9797

98-
if msg['type'] == 'stream':
99-
key = (messages[id]['stream_id'], msg['subject'])
98+
if message['type'] == 'stream':
99+
key = (message['stream_id'], message['subject'])
100100
unreads = unread_counts['unread_topics']
101101
# self-pm has only one display_recipient
102102
# 1-1 pms have 2 display_recipient
103-
elif len(msg['display_recipient']) <= 2:
104-
key = messages[id]['sender_id']
103+
elif len(message['display_recipient']) <= 2:
104+
key = message['sender_id']
105105
unreads = unread_counts['unread_pms'] # type: ignore
106106
else: # If it's a group pm
107107
key = frozenset( # type: ignore
108-
recipient['id'] for recipient in msg['display_recipient']
108+
recipient['id'] for recipient in message['display_recipient']
109109
)
110110
unreads = unread_counts['unread_huddles'] # type: ignore
111111

@@ -137,17 +137,18 @@ def _set_count_in_view(id_list: List[int], controller: Any, new_count: int,
137137
all_msg = controller.view.home_button
138138
all_pm = controller.view.pm_button
139139
for id in id_list:
140-
user_id = messages[id]['sender_id']
140+
message = messages[id]
141+
user_id = message['sender_id']
141142

142143
# If we sent this message, don't increase the count
143144
if user_id == controller.model.user_id:
144145
continue
145146

146-
msg_type = messages[id]['type']
147+
msg_type = message['type']
147148
add_to_counts = True
148149
if msg_type == 'stream':
149-
stream_id = messages[id]['stream_id']
150-
msg_topic = messages[id]['subject']
150+
stream_id = message['stream_id']
151+
msg_topic = message['subject']
151152
if controller.model.is_muted_stream(stream_id):
152153
add_to_counts = False # if muted, don't add to eg. all_msg
153154
else:
@@ -158,7 +159,7 @@ def _set_count_in_view(id_list: List[int], controller: Any, new_count: int,
158159
new_count)
159160
break
160161
# FIXME: Update unread_counts['unread_topics']?
161-
if ([messages[id]['display_recipient'], msg_topic] in
162+
if ([message['display_recipient'], msg_topic] in
162163
controller.model.muted_topics):
163164
add_to_counts = False
164165
if is_open_topic_view and stream_id == toggled_stream_id:

0 commit comments

Comments
 (0)