diff --git a/src/components/emoji-input/suggestor.js b/src/components/emoji-input/suggestor.js index 54fd7f29ee..c414b1bfa4 100644 --- a/src/components/emoji-input/suggestor.js +++ b/src/components/emoji-input/suggestor.js @@ -29,7 +29,21 @@ function suggestUsers (users) { user.screen_name.toLowerCase().startsWith(noPrefix) || user.name.toLowerCase().startsWith(noPrefix) /* eslint-disable camelcase */ - ).map(({ screen_name, name, profile_image_url_original }) => ({ + ).slice(0, 20).sort((a, b) => { + let aScore = 0 + let bScore = 0 + + aScore += a.screen_name.toLowerCase().startsWith(noPrefix) * 2 + aScore += a.name.toLowerCase().startsWith(noPrefix) + bScore += b.screen_name.toLowerCase().startsWith(noPrefix) * 2 + bScore += b.name.toLowerCase().startsWith(noPrefix) + + const diff = bScore * 10 - aScore * 10 + const nameAlphabetically = a.name > b.name ? 1 : -1 + const screenNameAlphabetically = a.screen_name > b.screen_name ? 1 : -1 + + return diff + nameAlphabetically + screenNameAlphabetically + }).map(({ screen_name, name, profile_image_url_original }) => ({ displayText: screen_name, detailText: name, imageUrl: profile_image_url_original,