Skip to content

Commit

Permalink
helper/model: Fix wildcard_mentions not showing in mentions.
Browse files Browse the repository at this point in the history
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 zulip#1037.
  • Loading branch information
zee-bit committed May 26, 2021
1 parent ae2117b commit 908fd26
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
20 changes: 15 additions & 5 deletions tests/helper/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,32 +153,42 @@ 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)
model.index = initial_index
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

Expand Down
4 changes: 2 additions & 2 deletions zulipterminal/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down Expand Up @@ -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':
Expand Down
5 changes: 4 additions & 1 deletion zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 908fd26

Please sign in to comment.