bug fix: Fix sorting for group-pm edge cases.

If you have a group PM where some users have
three-digit user_ids and some with four-digit
user_ids (or similar), a huddle could effectively
be ignored when determining the order of
search search suggestions.

Basically, we need a way to canonically sort
user_ids in "huddle" strings, and it's somewhat
arbitrary whether you sort lexically or sort
numerically, but you do need to be consistent
about it.

And JS is not exactly helpful here:

    > [99, 101].sort()
    [ 101, 99 ]

This is a pretty obscure bug with pretty low
user-facing consequences, and it was never
reported to us as far as I know, but the fix
here is pretty straightforward.

We have had similar bugs of slightly more consequence
in the past.  The reason this bug has shown
up multiple times in our codebase is that every
component that deals with huddles has slightly
different forces that determine how it wants
to serialize the huddle.  It's just one of those
annoying things.  Plus, bugs with group PMs
do tend to escape detection, since most people
spend most of their time either on streams
or in 1:1 PMs.
This commit is contained in:
Steve Howell
2020-05-26 23:29:50 +00:00
committed by Tim Abbott
parent 4803a12416
commit ede709f75c
4 changed files with 7 additions and 6 deletions

View File

@@ -360,7 +360,8 @@ exports.concat_huddle = function (user_ids, user_id) {
The only logic we're encapsulating here is
how to encode huddles.
*/
return user_ids.concat(user_id).sort().join(',');
const sorted_ids = sort_numerically([...user_ids, user_id]);
return sorted_ids.join(',');
};
exports.pm_lookup_key = function (user_ids_string) {