Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

refactor: Remove duplication from reactions.add_clean_reaction.

YashRE42717c4ae603f5
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js
index 2c4af269848..a868307ce17 100644
--- a/frontend_tests/node_tests/reactions.js
+++ b/frontend_tests/node_tests/reactions.js
@@ -78,6 +78,7 @@ const emoji_params = {
id: "992",
name: "inactive_realm_emoji",
source_url: "/url/for/992",
+ still_url: "/still/url/for/992",
deactivated: true,
},
},
@@ -168,6 +169,7 @@ test("basics", () => {
label: "translated: Cali reacted with :frown:",
emoji_alt_code: false,
class: "message_reaction",
+ is_realm_emoji: false,
},
{
emoji_name: "inactive_realm_emoji",
@@ -180,6 +182,7 @@ test("basics", () => {
emoji_alt_code: false,
is_realm_emoji: true,
url: "/url/for/992",
+ still_url: "/still/url/for/992",
class: "message_reaction reacted",
},
{
@@ -192,6 +195,7 @@ test("basics", () => {
label: "translated: You (click to remove) and Bob van Roberts reacted with :smile:",
emoji_alt_code: false,
class: "message_reaction reacted",
+ is_realm_emoji: false,
},
{
emoji_name: "tada",
@@ -203,6 +207,7 @@ test("basics", () => {
label: "translated: Cali and Alexus reacted with :tada:",
emoji_alt_code: false,
class: "message_reaction",
+ is_realm_emoji: false,
},
{
emoji_name: "rocket",
@@ -214,6 +219,7 @@ test("basics", () => {
label: "translated: You (click to remove), Bob van Roberts and Cali reacted with :rocket:",
emoji_alt_code: false,
class: "message_reaction reacted",
+ is_realm_emoji: false,
},
{
emoji_name: "wave",
@@ -225,18 +231,26 @@ test("basics", () => {
label: "translated: Bob van Roberts, Cali and Alexus reacted with :wave:",
emoji_alt_code: false,
class: "message_reaction",
+ is_realm_emoji: false,
},
];
assert.deepEqual(result, expected_result);
});
test("unknown realm emojis (add)", () => {
- blueslip.expect("error", "Cannot find/add realm emoji for code 'broken'.");
- reactions.add_clean_reaction({
- reaction_type: "realm_emoji",
- emoji_code: "broken",
- user_ids: [alice.user_id],
- });
+ assert.throws(
+ () =>
+ reactions.view.insert_new_reaction({
+ reaction_type: "realm_emoji",
+ emoji_name: "false_emoji",
+ emoji_code: "broken",
+ user_ids: [alice.user_id],
+ }),
+ {
+ name: "Error",
+ message: "Cannot find realm emoji for code 'broken'.",
+ },
+ );
});
test("unknown realm emojis (insert)", () => {
diff --git a/static/js/reactions.js b/static/js/reactions.js
index 3ed6ae793a9..5bb9fcac0bc 100644
--- a/static/js/reactions.js
+++ b/static/js/reactions.js
@@ -507,27 +507,15 @@ export function set_clean_reactions(message) {
}
export function add_clean_reaction(opts) {
- const r = {};
+ const r = emoji.get_emoji_details_for_rendering(opts);
- r.reaction_type = opts.reaction_type;
- r.emoji_name = opts.emoji_name;
- r.emoji_code = opts.emoji_code;
r.local_id = opts.local_id;
r.user_ids = opts.user_ids;
update_user_fields(r);
r.emoji_alt_code = user_settings.emojiset === "text";
-
- if (r.reaction_type !== "unicode_emoji") {
- r.is_realm_emoji = true;
- const emoji_info = emoji.all_realm_emojis.get(r.emoji_code);
- if (!emoji_info) {
- blueslip.error(`Cannot find/add realm emoji for code '${r.emoji_code}'.`);
- return;
- }
- r.url = emoji_info.emoji_url;
- }
+ r.is_realm_emoji = r.reaction_type === "realm_emoji" || r.reaction_type === "zulip_extra_emoji";
opts.message.clean_reactions.set(opts.local_id, r);
}