typeahead: Don't show default emojis if overridden by a realm emoji.

When a realm emoji overrides a default emoji, `:emoji_name:` now renders
as the realm emoji. Still, the typeahead menu would misleadingly show
the now overridden default emoji for the same name. Selecting it would
render as the realm emoji, which is very confusing user experience.

Now when selecting the emojis to suggest in the typeahead, the overridden
default emojis are excluded.

Fixes part of #24120.
This commit is contained in:
N-Shar-ma 2023-01-23 21:14:18 +05:30 committed by Tim Abbott
parent 8a5b71fdbd
commit 431cd8b10a
1 changed files with 9 additions and 1 deletions

View File

@ -146,6 +146,10 @@ export function sort_emojis(objs, query) {
return popular_set.has(obj.emoji_code) && decent_match(obj.emoji_name);
}
const realm_emoji_names = new Set(
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));
@ -164,12 +168,16 @@ export function sort_emojis(objs, query) {
...prioritise_realm_emojis(triage_results.rest),
];
// remove unicode emojis with same code but different names
// and unicode emojis overridden by realm emojis with same names
const unicode_emoji_codes = new Set();
const sorted_unique_results = [];
for (const emoji of sorted_results_with_possible_duplicates) {
if (!is_unicode_emoji(emoji)) {
sorted_unique_results.push(emoji);
} else if (!unicode_emoji_codes.has(emoji.emoji_code)) {
} else if (
!unicode_emoji_codes.has(emoji.emoji_code) &&
!realm_emoji_names.has(emoji.emoji_name)
) {
unicode_emoji_codes.add(emoji.emoji_code);
sorted_unique_results.push(emoji);
}