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 <yasirurathnayaka97@gmail.com>
This commit is contained in:
aryanshridhar
2021-06-16 15:00:13 +00:00
committed by Tim Abbott
parent 7227c12ba1
commit 2d8fceff5d

View File

@@ -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({