Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typeahead: Remove is_unicode_emoji.
Zixuan James Li6e9079f8763d
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.jsindex 57563cbb4c5..bdde7f5e896 100644--- a/frontend_tests/node_tests/composebox_typeahead.js+++ b/frontend_tests/node_tests/composebox_typeahead.js@@ -326,6 +326,7 @@ const call_center = {const make_emoji = (emoji_dict) => ({emoji_name: emoji_dict.name,emoji_code: emoji_dict.emoji_code,+ reaction_type: "unicode_emoji",});function test(label, f) {diff --git a/frontend_tests/node_tests/typeahead.js b/frontend_tests/node_tests/typeahead.jsindex 0604d44dc24..bfd3fbb20df 100644--- a/frontend_tests/node_tests/typeahead.js+++ b/frontend_tests/node_tests/typeahead.js@@ -20,8 +20,8 @@ const unicode_emojis = [];const emojis = [- {emoji_name: "japanese_post_office", url: "TBD"},- {emoji_name: "tada", random_field: "whatever"},+ {emoji_name: "japanese_post_office", reaction_type: "realm_emoji", url: "TBD"},+ {emoji_name: "tada", reaction_type: "realm_emoji", random_field: "whatever"},...unicode_emojis.map(([emoji_code, emoji_name]) => ({emoji_name,emoji_code,@@ -156,10 +156,10 @@ function sort_emojis(emojis, query) {run_test("sort_emojis: th", () => {const emoji_list = [- {emoji_name: "mother_nature"},- {emoji_name: "thermometer"},- {emoji_name: "thumbs_down"},- {emoji_name: "thumbs_up", emoji_code: "1f44d"},+ {emoji_name: "mother_nature", reaction_type: "realm_emoji"},+ {emoji_name: "thermometer", reaction_type: "realm_emoji"},+ {emoji_name: "thumbs_down", reaction_type: "realm_emoji"},+ {emoji_name: "thumbs_up", reaction_type: "unicode_emoji", emoji_code: "1f44d"},];assert.deepEqual(sort_emojis(emoji_list, "th"), ["thumbs_up",@@ -171,9 +171,9 @@ run_test("sort_emojis: th", () => {run_test("sort_emojis: sm", () => {const emoji_list = [- {emoji_name: "big_smile"},- {emoji_name: "slight_smile", emoji_code: "1f642"},- {emoji_name: "small_airplane"},+ {emoji_name: "big_smile", reaction_type: "realm_emoji"},+ {emoji_name: "slight_smile", reaction_type: "unicode_emoji", emoji_code: "1f642"},+ {emoji_name: "small_airplane", reaction_type: "realm_emoji"},];assert.deepEqual(sort_emojis(emoji_list, "sm"), ["slight_smile",@@ -184,9 +184,9 @@ run_test("sort_emojis: sm", () => {run_test("sort_emojis: SM", () => {const emoji_list = [- {emoji_name: "big_smile"},- {emoji_name: "slight_smile", emoji_code: "1f642"},- {emoji_name: "small_airplane"},+ {emoji_name: "big_smile", reaction_type: "realm_emoji"},+ {emoji_name: "slight_smile", reaction_type: "unicode_emoji", emoji_code: "1f642"},+ {emoji_name: "small_airplane", reaction_type: "realm_emoji"},];assert.deepEqual(sort_emojis(emoji_list, "SM"), ["slight_smile",@@ -196,7 +196,10 @@ run_test("sort_emojis: SM", () => {});run_test("sort_emojis: prefix before midphrase, with underscore (traffic_li)", () => {- const emoji_list = [{emoji_name: "horizontal_traffic_light"}, {emoji_name: "traffic_light"}];+ const emoji_list = [+ {emoji_name: "horizontal_traffic_light", reaction_type: "realm_emoji"},+ {emoji_name: "traffic_light", reaction_type: "realm_emoji"},+ ];assert.deepEqual(sort_emojis(emoji_list, "traffic_li"), ["traffic_light","horizontal_traffic_light",@@ -204,7 +207,10 @@ run_test("sort_emojis: prefix before midphrase, with underscore (traffic_li)", (});run_test("sort_emojis: prefix before midphrase, with space (traffic li)", () => {- const emoji_list = [{emoji_name: "horizontal_traffic_light"}, {emoji_name: "traffic_light"}];+ const emoji_list = [+ {emoji_name: "horizontal_traffic_light", reaction_type: "realm_emoji"},+ {emoji_name: "traffic_light", reaction_type: "realm_emoji"},+ ];assert.deepEqual(sort_emojis(emoji_list, "traffic li"), ["traffic_light","horizontal_traffic_light",@@ -224,7 +230,12 @@ run_test("sort_emojis: remove duplicates", () => {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},+ {+ 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[1],diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.jsindex abb3854f1f3..f7c1cbd4fbf 100644--- a/static/js/emoji_picker.js+++ b/static/js/emoji_picker.js@@ -223,7 +223,7 @@ function get_rendered_emoji(section, index) {export function is_emoji_present_in_text(text, emoji_dict) {// fetching emoji details to ensure emoji_code and reaction_type are presentconst emoji_info = emoji.get_emoji_details_by_name(emoji_dict.name);- if (typeahead.is_unicode_emoji(emoji_info)) {+ if (emoji_info.reaction_type === "unicode_emoji") {// convert emoji_dict to an actual emoji characterconst parsed_emoji_code = typeahead.parse_unicode_emoji_code(emoji_info.emoji_code);diff --git a/static/shared/js/typeahead.js b/static/shared/js/typeahead.jsindex d05fd851535..24ed49f3579 100644--- a/static/shared/js/typeahead.js+++ b/static/shared/js/typeahead.js@@ -70,9 +70,6 @@ export function clean_query_lowercase(query) {return query;}-export const is_unicode_emoji = (emoji) =>- emoji.reaction_type === "unicode_emoji" && emoji.emoji_code;-export const parse_unicode_emoji_code = (code) =>code.split("-")@@ -86,7 +83,8 @@ export function get_emoji_matcher(query) {return function (emoji) {const matches_emoji_literal =- is_unicode_emoji(emoji) && parse_unicode_emoji_code(emoji.emoji_code) === query;+ emoji.reaction_type === "unicode_emoji" &&+ parse_unicode_emoji_code(emoji.emoji_code) === query;return matches_emoji_literal || query_matches_string(query, emoji.emoji_name, "_");};}@@ -172,7 +170,7 @@ export function sort_emojis(objs, query) {const unicode_emoji_codes = new Set();const sorted_unique_results = [];for (const emoji of sorted_results_with_possible_duplicates) {- if (!is_unicode_emoji(emoji)) {+ if (emoji.reaction_type !== "unicode_emoji") {sorted_unique_results.push(emoji);} else if (!unicode_emoji_codes.has(emoji.emoji_code) &&