Fix apply_unread_message_event() for mentions.

We were exiting this function in certain cases before updating
mentions. This bug was always there, but it was flaky in terms
of database setup whether the tests would fail, so now the
relevant test sends three consecutive messages.

We also avoid putting duplicate message ids in mentions.
This commit is contained in:
Steve Howell
2017-08-10 04:58:39 -04:00
parent 9cb9e0d687
commit c7b9044ee5
2 changed files with 13 additions and 10 deletions

View File

@@ -518,6 +518,10 @@ def apply_unread_message_event(state, message):
unread_message_ids=[message_id],
)
if message.get('is_mentioned'):
if message_id not in state['mentions']:
state['mentions'].append(message_id)
for obj in state[unread_key]:
if key_func(obj) == my_key:
obj['unread_message_ids'].append(message_id)
@@ -526,6 +530,3 @@ def apply_unread_message_event(state, message):
state[unread_key].append(new_obj)
state[unread_key].sort(key=key_func)
if message.get('is_mentioned'):
state['mentions'].append(message_id)