Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
emojis: Filter out unicode emojis with same codes from typeahead menu.
N-Shar-ma249f482b0609
diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.jsindex 35a912e992c..9bee4e60f37 100644--- a/frontend_tests/node_tests/typeahead.js+++ b/frontend_tests/node_tests/typeahead.js@@ -210,3 +210,13 @@ run_test("sort_emojis: prefix before midphrase, with space (traffic li)", () =>"horizontal_traffic_light",]);});++run_test("sort_emojis: remove duplicates", () => {+ // notice the last 2 are aliases of the same emoji (same emoji code)+ const emoji_list = [+ {emoji_name: "laughter_tears", emoji_code: "1f602", reaction_type: "unicode_emoji"},+ {emoji_name: "tear", emoji_code: "1f972", reaction_type: "unicode_emoji"},+ {emoji_name: "smile_with_tear", emoji_code: "1f972", reaction_type: "unicode_emoji"},+ ];+ assert.deepEqual(typeahead.sort_emojis(emoji_list, "tear"), [emoji_list[1], emoji_list[0]]);+});diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.jsindex c992034e065..49848a47c49 100644--- a/static/shared/js/typeahead.js+++ b/static/shared/js/typeahead.js@@ -153,5 +153,22 @@ export function sort_emojis(objs, query) {const triage_results = triage(query, others, (x) => x.emoji_name);- return [...popular_emoji_matches, ...triage_results.matches, ...triage_results.rest];+ const sorted_results_with_possible_duplicates = [+ ...popular_emoji_matches,+ ...triage_results.matches,+ ...triage_results.rest,+ ];+ // remove unicode emojis with same code but different 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)) {+ unicode_emoji_codes.add(emoji.emoji_code);+ sorted_unique_results.push(emoji);+ }+ }++ return sorted_unique_results;}