mirror of
https://github.com/zulip/zulip.git
synced 2025-10-25 09:03:57 +00:00
sort_emojis: Prioritize perfect matches above all.
Currently we prioritize (even partial) realm emojis above all. Including over perfect matches if the emoji is **not** a realm emoji. The commit changes this behavior to prioritize perfect matches above all, regardless of emoji category. close https://github.com/zulip/zulip/issues/27545
This commit is contained in:
@@ -189,8 +189,11 @@ export function sort_emojis<T extends Emoji>(objs: T[], query: string): T[] {
|
||||
objs.filter((obj) => obj.is_realm_emoji).map((obj) => obj.emoji_name),
|
||||
);
|
||||
|
||||
const popular_emoji_matches = objs.filter((obj) => is_popular(obj));
|
||||
const others = objs.filter((obj) => !is_popular(obj));
|
||||
const perfect_emoji_matches = objs.filter((obj) => obj.emoji_name === query);
|
||||
const without_perfect_matches = objs.filter((obj) => obj.emoji_name !== query);
|
||||
|
||||
const popular_emoji_matches = without_perfect_matches.filter((obj) => is_popular(obj));
|
||||
const others = without_perfect_matches.filter((obj) => !is_popular(obj));
|
||||
|
||||
const triage_results = triage(query, others, (x) => x.emoji_name);
|
||||
|
||||
@@ -202,6 +205,7 @@ export function sort_emojis<T extends Emoji>(objs: T[], query: string): T[] {
|
||||
}
|
||||
|
||||
const sorted_results_with_possible_duplicates = [
|
||||
...perfect_emoji_matches,
|
||||
...popular_emoji_matches,
|
||||
...prioritise_realm_emojis(triage_results.matches),
|
||||
...prioritise_realm_emojis(triage_results.rest),
|
||||
|
||||
@@ -237,8 +237,18 @@ run_test("sort_emojis: prioritise realm emojis", () => {
|
||||
reaction_type: "realm_emoji",
|
||||
},
|
||||
];
|
||||
assert.deepEqual(typeahead.sort_emojis(emoji_list, "thank you"), [
|
||||
emoji_list[1],
|
||||
emoji_list[0],
|
||||
]);
|
||||
assert.deepEqual(typeahead.sort_emojis(emoji_list, "thank"), [emoji_list[1], emoji_list[0]]);
|
||||
});
|
||||
|
||||
run_test("sort_emojis: prioritise perfect matches", () => {
|
||||
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,
|
||||
reaction_type: "realm_emoji",
|
||||
},
|
||||
];
|
||||
assert.deepEqual(typeahead.sort_emojis(emoji_list, "thank you"), emoji_list);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user