From 2d8fceff5de295ac743a6f8ca6b0a7ec62a7377c Mon Sep 17 00:00:00 2001 From: aryanshridhar Date: Wed, 16 Jun 2021 15:00:13 +0000 Subject: [PATCH] settings_emoji: Improve error handling for uploading custom emojis. Previously, there wasn't any error message if a user tries to upload a custom emoji with a name that already exists. This commit essentially displays a error using `ui_report` when the user tries to do so. Fixes #18269. Co-authored-by: yasiruRathnayaka97 --- static/js/settings_emoji.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js index 5361f831a9..1b2816dd65 100644 --- a/static/js/settings_emoji.js +++ b/static/js/settings_emoji.js @@ -81,6 +81,16 @@ function is_default_emoji(emoji_name) { return emoji_codes.names.includes(emoji_name); } +function is_custom_emoji(emoji_name) { + const emoji_data = emoji.get_server_realm_emoji_data(); + for (const emoji of Object.values(emoji_data)) { + if (emoji.name === emoji_name && !emoji.deactivated) { + return true; + } + } + return false; +} + export function populate_emoji() { if (!meta.loaded) { return; @@ -239,6 +249,16 @@ export function set_up() { return; } + if (is_custom_emoji(emoji.name)) { + ui_report.client_error( + $t_html({ + defaultMessage: "Failed: A custom emoji with this name already exists.", + }), + emoji_status, + ); + return; + } + if (is_default_emoji(emoji.name)) { const modal_parent = $("#settings_content"); const html_body = emoji_settings_warning_modal({