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:
kraktus
2023-11-12 17:01:55 +01:00
committed by Tim Abbott
parent 5797381ea2
commit 3de6ec0a59
2 changed files with 20 additions and 6 deletions

View File

@@ -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),