settings: Use switch case instead of if-else for message delete checks.

This is a prep commit for making zero as invalid value for
message_content_delete_limit_seconds, as that change would
add one more else-if and our eslint rules convert such cases
to switch case. Doing this here would keep the diff smaller
in the original commit of making zero as invalid value.
This commit is contained in:
sahil839 2021-06-15 18:38:23 +05:30 committed by Tim Abbott
parent cfadb8297c
commit d09da692c6
1 changed files with 24 additions and 16 deletions

View File

@ -774,22 +774,30 @@ export function build_page() {
).seconds;
}
const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val();
if (delete_limit_setting_value === "never") {
data.allow_message_deleting = false;
} else if (delete_limit_setting_value === "custom_limit") {
data.message_content_delete_limit_seconds = parse_time_limit(
$("#id_realm_message_content_delete_limit_minutes"),
);
// Disable deleting if the parsed time limit is 0 seconds
data.allow_message_deleting = Boolean(
data.message_content_delete_limit_seconds,
);
} else {
data.allow_message_deleting = true;
data.message_content_delete_limit_seconds =
settings_config.msg_delete_limit_dropdown_values.get(
delete_limit_setting_value,
).seconds;
switch (delete_limit_setting_value) {
case "never": {
data.allow_message_deleting = false;
break;
}
case "custom_limit": {
data.message_content_delete_limit_seconds = parse_time_limit(
$("#id_realm_message_content_delete_limit_minutes"),
);
// Disable deleting if the parsed time limit is 0 seconds
data.allow_message_deleting = Boolean(
data.message_content_delete_limit_seconds,
);
break;
}
default: {
data.allow_message_deleting = true;
data.message_content_delete_limit_seconds =
settings_config.msg_delete_limit_dropdown_values.get(
delete_limit_setting_value,
).seconds;
}
}
break;
}