Skip to content

Commit afe1500

Browse files
committed
helper: Modify set_counts to use index['unread_msgs'].
Per-message 'sender_id' is not available for stream messages. Due to this, messages sent by user might cause undesirable behaviours.
1 parent 2eea856 commit afe1500

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

tests/model/test_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ def test_update_read_status(self, mocker, model, event_op,
12771277
flags_before)
12781278

12791279
if event_op == 'add':
1280-
set_count.assert_called_once_with(list(changed_ids),
1280+
set_count.assert_called_once_with(list(event_message_ids),
12811281
self.controller, -1)
12821282
elif event_op == 'remove':
12831283
set_count.assert_not_called()

zulipterminal/helper.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def set_count(id_list: List[int], controller: Any, new_count: int) -> None:
9191
# (we could ensure this in a different way by a different type)
9292
assert new_count == 1 or new_count == -1
9393

94-
messages = controller.model.index['messages']
94+
messages = controller.model.index['unread_msgs']
9595
unread_counts = controller.model.unread_counts # type: UnreadCounts
9696

9797
for id in id_list:
@@ -100,9 +100,8 @@ def set_count(id_list: List[int], controller: Any, new_count: int) -> None:
100100
if msg['type'] == 'stream':
101101
key = (messages[id]['stream_id'], msg['subject'])
102102
unreads = unread_counts['unread_topics']
103-
# self-pm has only one display_recipient
104-
# 1-1 pms have 2 display_recipient
105-
elif len(msg['display_recipient']) <= 2:
103+
# 1-1 pms and self-pms
104+
elif msg['type'] == 'private' and 'sender_id' in msg:
106105
key = messages[id]['sender_id']
107106
unreads = unread_counts['unread_pms'] # type: ignore
108107
else: # If it's a group pm
@@ -133,14 +132,16 @@ def set_count(id_list: List[int], controller: Any, new_count: int) -> None:
133132
all_msg = controller.view.home_button
134133
all_pm = controller.view.pm_button
135134
for id in id_list:
136-
user_id = messages[id]['sender_id']
137-
138-
# If we sent this message, don't increase the count
139-
if user_id == controller.model.user_id:
140-
continue
141-
142135
msg_type = messages[id]['type']
143136
add_to_counts = True
137+
# FIXME no user_id for streams?
138+
if msg_type != 'stream':
139+
user_id = messages[id]['sender_id']
140+
141+
# If we sent this message, don't increase the count
142+
if user_id == controller.model.user_id:
143+
continue
144+
144145
if msg_type == 'stream':
145146
stream_id = messages[id]['stream_id']
146147
msg_topic = messages[id]['subject']

zulipterminal/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ def update_message_flag_status(self, event: Event) -> None:
840840
self.update_rendered_view(message_id)
841841

842842
if event['operation'] == 'add' and flag_to_change == 'read':
843-
set_count(list(message_ids_to_mark & indexed_message_ids),
844-
self.controller, -1)
843+
set_count(list(message_ids_to_mark), self.controller, -1)
845844

846845
def update_rendered_view(self, msg_id: int) -> None:
847846
# Update new content in the rendered view

0 commit comments

Comments
 (0)