mirror of https://github.com/zulip/zulip.git
reactions: Handle missing realm emojis.
For the lines of code that I changed here, we were getting field reports that the below code was getting `undefined`: emoji.all_realm_emojis.get(r.emoji_code) It's not really clear to me how this could happen, but we definitely should fail softly here. We still report it as an error, but we let the function return and don't trigger a TypeError. If there's a legitimate reason for realms to delete realm emojis, we should either downgrade this to a warning or consider a strategy of back-fixing messages when realm emojis get deleted.
This commit is contained in:
parent
d19baaaf71
commit
98529564ae
|
@ -179,6 +179,24 @@ run_test("basics", () => {
|
|||
assert.deepEqual(result, expected_result);
|
||||
});
|
||||
|
||||
run_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],
|
||||
});
|
||||
});
|
||||
|
||||
run_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,
|
||||
});
|
||||
});
|
||||
|
||||
run_test("sending", (override) => {
|
||||
const message_id = 1001; // see above for setup
|
||||
let emoji_name = "smile"; // should be a current reaction
|
||||
|
|
|
@ -295,7 +295,12 @@ exports.view.insert_new_reaction = function (opts) {
|
|||
|
||||
if (opts.reaction_type !== "unicode_emoji") {
|
||||
context.is_realm_emoji = true;
|
||||
context.url = emoji.all_realm_emojis.get(emoji_code).emoji_url;
|
||||
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;
|
||||
}
|
||||
|
||||
context.count = 1;
|
||||
|
@ -499,7 +504,12 @@ exports.add_clean_reaction = function (opts) {
|
|||
|
||||
if (r.reaction_type !== "unicode_emoji") {
|
||||
r.is_realm_emoji = true;
|
||||
r.url = emoji.all_realm_emojis.get(r.emoji_code).emoji_url;
|
||||
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;
|
||||
}
|
||||
|
||||
opts.message.clean_reactions.set(opts.local_id, r);
|
||||
|
|
Loading…
Reference in New Issue