server: Sort user_ids in recent PM conversations.

This change should prevent test flakes, plus
it's more deterministic behavior for clients,
who will generally comma-join the ids into
a key for their internal data structures.

I was able to verify test coverage on this
by making the sort reversed, which would
cause test_huddle_send_message_events to
fail.
This commit is contained in:
Steve Howell
2020-01-01 15:27:14 +00:00
committed by Tim Abbott
parent aed813f44c
commit d452ad31e0
2 changed files with 8 additions and 3 deletions

View File

@@ -424,9 +424,9 @@ def apply_event(state: Dict[str, Any],
if recipient_id not in conversations:
conversations[recipient_id] = dict(
user_ids=[user_dict['id'] for user_dict in
event['message']['display_recipient'] if
user_dict['id'] != user_profile.id]
user_ids=sorted([user_dict['id'] for user_dict in
event['message']['display_recipient'] if
user_dict['id'] != user_profile.id])
)
conversations[recipient_id]['max_message_id'] = event['message']['id']
return

View File

@@ -1133,4 +1133,9 @@ def get_recent_private_conversations(user_profile: UserProfile) -> Dict[int, Dic
user_profile_id=user_profile.id).values_list(
"recipient_id", "user_profile_id"):
recipient_map[recipient_id]['user_ids'].append(user_profile_id)
# Sort to prevent test flakes and client bugs.
for rec in recipient_map.values():
rec['user_ids'].sort()
return recipient_map