Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
refactor: Remove duplication from reactions.view.insert_new_reaction.
YashRE4271a4985ebc4f
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.jsindex fe092f49290..2c4af269848 100644--- a/frontend_tests/node_tests/reactions.js+++ b/frontend_tests/node_tests/reactions.js@@ -240,12 +240,19 @@ test("unknown realm emojis (add)", () => {});test("unknown realm emojis (insert)", () => {- blueslip.expect("error", "Cannot find/insert realm emoji for code 'bogus'.");- reactions.view.insert_new_reaction({- reaction_type: "realm_emoji",- emoji_code: "bogus",- user_id: bob.user_id,- });+ assert.throws(+ () =>+ reactions.view.insert_new_reaction({+ reaction_type: "realm_emoji",+ emoji_name: "fake_emoji",+ emoji_code: "bogus",+ user_id: bob.user_id,+ }),+ {+ name: "Error",+ message: "Cannot find realm emoji for code 'bogus'.",+ },+ );});test("sending", ({override}) => {@@ -600,6 +607,8 @@ test("view.insert_new_reaction (me w/unicode emoji)", ({override, mock_template}class: "message_reaction reacted",message_id: opts.message_id,label: "translated: You (click to remove) reacted with :8ball:",+ reaction_type: opts.reaction_type,+ is_realm_emoji: false,});return "<new reaction html>";});@@ -647,6 +656,8 @@ test("view.insert_new_reaction (them w/zulip emoji)", ({override, mock_template}class: "message_reaction",message_id: opts.message_id,label: "translated: Bob van Roberts reacted with :zulip:",+ still_url: undefined,+ reaction_type: opts.reaction_type,});return "<new reaction html>";});diff --git a/static/js/reactions.js b/static/js/reactions.jsindex 735d0a62416..3ed6ae793a9 100644--- a/static/js/reactions.js+++ b/static/js/reactions.js@@ -308,33 +308,22 @@ view.insert_new_reaction = function (opts) {// before the add button.const message_id = opts.message_id;- const emoji_name = opts.emoji_name;- const emoji_code = opts.emoji_code;const user_id = opts.user_id;const user_list = [user_id];const context = {message_id,- emoji_name,- emoji_code,+ ...emoji.get_emoji_details_for_rendering(opts),};- const new_label = generate_title(emoji_name, user_list);-- if (opts.reaction_type !== "unicode_emoji") {- context.is_realm_emoji = true;- const emoji_info = emoji.all_realm_emojis.get(emoji_code);- if (!emoji_info) {- blueslip.error(`Cannot find/insert realm emoji for code '${emoji_code}'.`);- return;- }- context.url = emoji_info.emoji_url;- }+ const new_label = generate_title(opts.emoji_name, user_list);context.count = 1;context.label = new_label;context.local_id = get_local_reaction_id(opts);context.emoji_alt_code = user_settings.emojiset === "text";+ context.is_realm_emoji =+ context.reaction_type === "realm_emoji" || context.reaction_type === "zulip_extra_emoji";if (opts.user_id === page_params.user_id) {context.class = "message_reaction reacted";