composebox_typeahead: Make reaction_type available in composebox emojis.

In order to make it possible to search emojis with emoji literals,
we need to make the reaction_type of every emoji available in the
emoji objects used by the composebox.
This commit is contained in:
Lani 2022-04-30 18:43:25 +01:00 committed by Tim Abbott
parent 4c6f2ae7be
commit 986dbc44b7
2 changed files with 31 additions and 7 deletions

View File

@ -169,6 +169,7 @@ const emojis_by_name = new Map(
const emoji_list = Array.from(emojis_by_name.values(), (emoji_dict) => ({
emoji_name: emoji_dict.name,
emoji_code: emoji_dict.emoji_code,
reaction_type: "unicode_emoji",
}));
const me_slash = {
@ -218,9 +219,25 @@ stream_data.add_sub(sweden_stream);
stream_data.add_sub(denmark_stream);
stream_data.add_sub(netherland_stream);
const name_to_codepoint = {};
for (const [key, val] of emojis_by_name.entries()) {
name_to_codepoint[key] = val.emoji_code;
}
const emoji_codes = {
name_to_codepoint,
names: Array.from(emojis_by_name.keys()),
emoji_catalog: {},
emoticon_conversions: {},
codepoint_to_name: {},
};
emoji.initialize({
realm_emoji: {},
emoji_codes,
});
emoji.active_realm_emojis = new Map();
emoji.emojis_by_name = emojis_by_name;
emoji.emojis = emoji_list;
const alice = {
email: "alice@zulip.com",
@ -1536,18 +1553,22 @@ test("typeahead_results", () => {
assert.deepEqual(returned, expected);
}
assert_emoji_matches("da", [
{emoji_name: "tada", emoji_code: "1f389"},
{emoji_name: "panda_face", emoji_code: "1f43c"},
{emoji_name: "tada", emoji_code: "1f389", reaction_type: "unicode_emoji"},
{emoji_name: "panda_face", emoji_code: "1f43c", reaction_type: "unicode_emoji"},
]);
assert_emoji_matches("da_", []);
assert_emoji_matches("da ", []);
assert_emoji_matches("panda ", [{emoji_name: "panda_face", emoji_code: "1f43c"}]);
assert_emoji_matches("panda_", [{emoji_name: "panda_face", emoji_code: "1f43c"}]);
assert_emoji_matches("panda ", [
{emoji_name: "panda_face", emoji_code: "1f43c", reaction_type: "unicode_emoji"},
]);
assert_emoji_matches("panda_", [
{emoji_name: "panda_face", emoji_code: "1f43c", reaction_type: "unicode_emoji"},
]);
assert_emoji_matches("japanese_post_", [
{emoji_name: "japanese_post_office", emoji_code: "1f3e3"},
{emoji_name: "japanese_post_office", emoji_code: "1f3e3", reaction_type: "unicode_emoji"},
]);
assert_emoji_matches("japanese post ", [
{emoji_name: "japanese_post_office", emoji_code: "1f3e3"},
{emoji_name: "japanese_post_office", emoji_code: "1f3e3", reaction_type: "unicode_emoji"},
]);
assert_emoji_matches("notaemoji", []);

View File

@ -47,8 +47,10 @@ export let emoji_collection = [];
export function update_emoji_data() {
emoji_collection = [];
for (const emoji_dict of emoji.emojis_by_name.values()) {
const {reaction_type} = emoji.get_emoji_details_by_name(emoji_dict.name);
if (emoji_dict.is_realm_emoji === true) {
emoji_collection.push({
reaction_type,
emoji_name: emoji_dict.name,
emoji_url: emoji_dict.url,
is_realm_emoji: true,
@ -56,6 +58,7 @@ export function update_emoji_data() {
} else {
for (const alias of emoji_dict.aliases) {
emoji_collection.push({
reaction_type,
emoji_name: alias,
emoji_code: emoji_dict.emoji_code,
});