Skip to content

Commit

Permalink
model: Refresh topic list on update message event.
Browse files Browse the repository at this point in the history
Tests amended.
  • Loading branch information
kaustubh-nair committed Sep 8, 2020
1 parent 3000032 commit 64bfd61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ def test_notify_users_enabled(self, mocker, model, message_fixture,
({ # Only subject of 1 message is updated.
'message_id': 1,
'subject': 'new subject',
'stream_id': 10,
'message_ids': [1],
}, 1, {
'messages': {
Expand All @@ -970,6 +971,7 @@ def test_notify_users_enabled(self, mocker, model, message_fixture,
({ # Subject of 2 messages is updated
'message_id': 1,
'subject': 'new subject',
'stream_id': 10,
'message_ids': [1, 2],
}, 2, {
'messages': {
Expand All @@ -987,6 +989,7 @@ def test_notify_users_enabled(self, mocker, model, message_fixture,
}),
({ # Message content is updated
'message_id': 1,
'stream_id': 10,
'rendered_content': '<p>new content</p>',
}, 1, {
'messages': {
Expand All @@ -1006,6 +1009,7 @@ def test_notify_users_enabled(self, mocker, model, message_fixture,
'message_id': 1,
'rendered_content': '<p>new content</p>',
'subject': 'new subject',
'stream_id': 10,
'message_ids': [1],
}, 2, {
'messages': {
Expand Down Expand Up @@ -1042,6 +1046,7 @@ def test_notify_users_enabled(self, mocker, model, message_fixture,
'message_id': 3,
'rendered_content': '<p>new content</p>',
'subject': 'new subject',
'stream_id': 10,
'message_ids': [3],
}, 0, {
'messages': {
Expand Down
12 changes: 12 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,9 +974,21 @@ def _handle_update_message_event(self, event: Event) -> None:
# the event didn't have a 'subject' update.
if 'subject' in event:
new_subject = event['subject']
stream_id = event['stream_id']
for msg_id in event['message_ids']:
self.index['messages'][msg_id]['subject'] = new_subject
self._update_rendered_view(msg_id)
if stream_id in self.index['topics']:
if (hasattr(self.controller, 'view')
and self.controller.view.left_panel.
stream_is_in_topic_view(message['stream_id'])):
# Reload topic list.
self._fetch_topics_in_streams([stream_id])
self.controller.view.left_panel.show_topics_view(
self.controller.view.topic_w.stream_button)
self.controller.update_screen()
else:
self.index['topics'][stream_id] = []

def _handle_reaction_event(self, event: Event) -> None:
"""
Expand Down

0 comments on commit 64bfd61

Please sign in to comment.