emojis: Prioritise custom / realm emojis when sorting.

Fixes: #18135.
This commit is contained in:
N-Shar-ma 2023-01-13 22:20:05 +05:30 committed by Tim Abbott
parent 249f482b06
commit aa72b51bca
2 changed files with 20 additions and 2 deletions

View File

@ -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],
]);
});

View File

@ -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();