From 908fd265458ff41ecc5fba28a0dac5547f6a3677 Mon Sep 17 00:00:00 2001 From: Zeeshan Date: Tue, 25 May 2021 20:46:27 +0530 Subject: [PATCH] helper/model: Fix wildcard_mentions not showing in mentions. This commit fixes a small bug that prevented messages with wildcard_mentions from appearing in the all_mentions narrow. The server defines several wildcard_mentions like @all/@everyone /@stream, which are not marked with 'mentions' in the message flags, but rather 'wildcard_mentions'. The bugfix now checks for this flag in the message response from server and appropriately categorizes these messages as mentioned and also updates the count in the respective narrows. Also fixes a related expression in model's current_narrow_contains_message function, that did not check for 'wildcard_mentioned' in message flags. Tests amended. Fixes #1037. --- tests/helper/test_helper.py | 20 +++++++++++++++----- zulipterminal/helper.py | 4 ++-- zulipterminal/model.py | 5 ++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/helper/test_helper.py b/tests/helper/test_helper.py index 785c8dbbd03..8473b00f92c 100644 --- a/tests/helper/test_helper.py +++ b/tests/helper/test_helper.py @@ -153,20 +153,25 @@ def test_index_starred(mocker, assert index_messages(messages, model, model.index) == expected_index -@pytest.mark.parametrize('mentioned_messages', [ - {537286, 537287, 537288}, - {537286}, {537287}, {537288}, - {537286, 537287}, {537286, 537288}, {537287, 537288}, +@pytest.mark.parametrize('mentioned_messages, wildcard_mentioned_messages', [ + ({537286, 537288}, {537287}), ({537286}, {537286}), + ({537287}, {537286, 537288}), ({537288}, {537286, 537287, 537288}), + ({537286, 537287}, set()), ({537286, 537288}, {537286, 537288}), + ({537287, 537288}, {537286, 537287, 537288}), ]) def test_index_mentioned_messages(mocker, messages_successful_response, empty_index, mentioned_messages, + wildcard_mentioned_messages, initial_index): messages = messages_successful_response['messages'] for msg in messages: if msg['id'] in mentioned_messages and 'mentioned' not in msg['flags']: msg['flags'].append('mentioned') + if (msg['id'] in wildcard_mentioned_messages + and 'wildcard_mentioned' not in msg['flags']): + msg['flags'].append('wildcard_mentioned') model = mocker.patch('zulipterminal.model.Model.__init__', return_value=None) @@ -174,11 +179,16 @@ def test_index_mentioned_messages(mocker, model.narrow = [['is', 'mentioned']] model.is_search_narrow.return_value = False expected_index = dict(empty_index, private_msg_ids={537287, 537288}, - mentioned_msg_ids=mentioned_messages) + mentioned_msg_ids=( + mentioned_messages | wildcard_mentioned_messages) + ) for msg_id, msg in expected_index['messages'].items(): if msg_id in mentioned_messages and 'mentioned' not in msg['flags']: msg['flags'].append('mentioned') + if (msg['id'] in wildcard_mentioned_messages + and 'wildcard_mentioned' not in msg['flags']): + msg['flags'].append('wildcard_mentioned') assert index_messages(messages, model, model.index) == expected_index diff --git a/zulipterminal/helper.py b/zulipterminal/helper.py index 1572eb32a75..e690cf8f417 100644 --- a/zulipterminal/helper.py +++ b/zulipterminal/helper.py @@ -173,7 +173,7 @@ def _set_count_in_view(controller: Any, new_count: int, msg_type = message['type'] add_to_counts = True - if 'mentioned' in message['flags']: + if ({'mentioned', 'wildcard_mentioned'} & set(message['flags'])): unread_counts['all_mentions'] += new_count all_mentioned.update_count(unread_counts['all_mentions']) @@ -382,7 +382,7 @@ def index_messages(messages: List[Message], index['starred_msg_ids'].add(msg['id']) if narrow[0][1] == 'mentioned': - if 'mentioned' in msg['flags']: + if ({'mentioned', 'wildcard_mentioned'} & set(msg['flags'])): index['mentioned_msg_ids'].add(msg['id']) if msg['type'] == 'private': diff --git a/zulipterminal/model.py b/zulipterminal/model.py index a2ecd833260..a043999545c 100644 --- a/zulipterminal/model.py +++ b/zulipterminal/model.py @@ -292,7 +292,10 @@ def current_narrow_contains_message(self, message: Message) -> bool: # mentions or ( self.narrow[0][1] == 'mentioned' - and 'mentioned' in message['flags'] + and ( + 'mentioned' in message['flags'] + or 'wildcard_mentioned' in message['flags'] + ) ) # All-PMs # FIXME Buggy condition?