diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.js index 9bee4e60f3..0604d44dc2 100644 --- a/frontend_tests/node_tests/typeahead.js +++ b/frontend_tests/node_tests/typeahead.js @@ -220,3 +220,14 @@ run_test("sort_emojis: remove duplicates", () => { ]; assert.deepEqual(typeahead.sort_emojis(emoji_list, "tear"), [emoji_list[1], emoji_list[0]]); }); + +run_test("sort_emojis: prioritise realm emojis", () => { + const emoji_list = [ + {emoji_name: "thank_you", emoji_code: "1f64f", reaction_type: "unicode_emoji"}, + {emoji_name: "thank_you_custom", url: "something", is_realm_emoji: true}, + ]; + assert.deepEqual(typeahead.sort_emojis(emoji_list, "thank you"), [ + emoji_list[1], + emoji_list[0], + ]); +}); diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.js index 49848a47c4..37f8ccc13c 100644 --- a/static/shared/js/typeahead.js +++ b/static/shared/js/typeahead.js @@ -153,10 +153,17 @@ export function sort_emojis(objs, query) { const triage_results = triage(query, others, (x) => x.emoji_name); + function prioritise_realm_emojis(emojis) { + return [ + ...emojis.filter((emoji) => emoji.is_realm_emoji), + ...emojis.filter((emoji) => !emoji.is_realm_emoji), + ]; + } + const sorted_results_with_possible_duplicates = [ ...popular_emoji_matches, - ...triage_results.matches, - ...triage_results.rest, + ...prioritise_realm_emojis(triage_results.matches), + ...prioritise_realm_emojis(triage_results.rest), ]; // remove unicode emojis with same code but different names const unicode_emoji_codes = new Set();