js: Add braces to case blocks declaring variables.

This helps to prepare for the migration of `var` to `let` and `const`.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2019-10-25 14:55:37 -07:00
committed by Tim Abbott
parent 12bd3c04c0
commit a547413347
8 changed files with 36 additions and 19 deletions

View File

@@ -499,13 +499,14 @@ exports.validation_error = function (error_type, stream_name) {
compose_error(i18n.t("Error checking subscription"), compose_error(i18n.t("Error checking subscription"),
$("#stream_message_recipient_stream")); $("#stream_message_recipient_stream"));
return false; return false;
case "not-subscribed": case "not-subscribed": {
var sub = stream_data.get_sub(stream_name); var sub = stream_data.get_sub(stream_name);
var new_row = render_compose_not_subscribed({ var new_row = render_compose_not_subscribed({
should_display_sub_button: sub.should_display_subscription_button}); should_display_sub_button: sub.should_display_subscription_button});
compose_not_subscribed_error(new_row, $('#stream_message_recipient_stream')); compose_not_subscribed_error(new_row, $('#stream_message_recipient_stream'));
return false; return false;
} }
}
return true; return true;
}; };

View File

@@ -74,7 +74,7 @@ function message_matches_search_term(message, operator, operand) {
case 'id': case 'id':
return message.id.toString() === operand; return message.id.toString() === operand;
case 'stream': case 'stream': {
if (message.type !== 'stream') { if (message.type !== 'stream') {
return false; return false;
} }
@@ -95,6 +95,7 @@ function message_matches_search_term(message, operator, operand) {
// loaded for a stream that we are no longer // loaded for a stream that we are no longer
// subscribed to (or that was deleted). // subscribed to (or that was deleted).
return message.stream.toLowerCase() === operand; return message.stream.toLowerCase() === operand;
}
case 'topic': case 'topic':
if (message.type !== 'stream') { if (message.type !== 'stream') {
@@ -111,7 +112,7 @@ function message_matches_search_term(message, operator, operand) {
case 'sender': case 'sender':
return people.id_matches_email_operand(message.sender_id, operand); return people.id_matches_email_operand(message.sender_id, operand);
case 'group-pm-with': case 'group-pm-with': {
var operand_ids = people.pm_with_operand_ids(operand); var operand_ids = people.pm_with_operand_ids(operand);
if (!operand_ids) { if (!operand_ids) {
return false; return false;
@@ -123,23 +124,25 @@ function message_matches_search_term(message, operator, operand) {
return user_ids.indexOf(operand_ids[0]) !== -1; return user_ids.indexOf(operand_ids[0]) !== -1;
// We should also check if the current user is in the recipient list (user_ids) of the // We should also check if the current user is in the recipient list (user_ids) of the
// message, but it is implicit by the fact that the current user has access to the message. // message, but it is implicit by the fact that the current user has access to the message.
}
case 'pm-with': case 'pm-with': {
// TODO: use user_ids, not emails here // TODO: use user_ids, not emails here
if (message.type !== 'private') { if (message.type !== 'private') {
return false; return false;
} }
operand_ids = people.pm_with_operand_ids(operand); const operand_ids = people.pm_with_operand_ids(operand);
if (!operand_ids) { if (!operand_ids) {
return false; return false;
} }
user_ids = people.pm_with_user_ids(message); const user_ids = people.pm_with_user_ids(message);
if (!user_ids) { if (!user_ids) {
return false; return false;
} }
return _.isEqual(operand_ids, user_ids); return _.isEqual(operand_ids, user_ids);
} }
}
return true; // unknown operators return true (effectively ignored) return true; // unknown operators return true (effectively ignored)
} }

View File

@@ -78,7 +78,7 @@ function do_hashchange_normal(from_reload) {
// be #ABCD. // be #ABCD.
var hash = window.location.hash.split("/"); var hash = window.location.hash.split("/");
switch (hash[0]) { switch (hash[0]) {
case "#narrow": case "#narrow": {
ui_util.change_tab_to("#home"); ui_util.change_tab_to("#home");
var operators = hash_util.parse_narrow(hash); var operators = hash_util.parse_narrow(hash);
if (operators === undefined) { if (operators === undefined) {
@@ -103,6 +103,7 @@ function do_hashchange_normal(from_reload) {
narrow.activate(operators, narrow_opts); narrow.activate(operators, narrow_opts);
floating_recipient_bar.update(); floating_recipient_bar.update();
return true; return true;
}
case "": case "":
case "#": case "#":
activate_home_tab(); activate_home_tab();

View File

@@ -749,12 +749,13 @@ exports.process_hotkey = function (e, hotkey) {
case 'toggle_reactions_popover': // ':': open reactions to message case 'toggle_reactions_popover': // ':': open reactions to message
reactions.open_reactions_popover(); reactions.open_reactions_popover();
return true; return true;
case 'thumbs_up_emoji': // '+': reacts with thumbs up emoji on selected message case 'thumbs_up_emoji': { // '+': reacts with thumbs up emoji on selected message
// Use canonical name. // Use canonical name.
var thumbs_up_emoji_code = '1f44d'; var thumbs_up_emoji_code = '1f44d';
var canonical_name = emoji_codes.codepoint_to_name[thumbs_up_emoji_code]; var canonical_name = emoji_codes.codepoint_to_name[thumbs_up_emoji_code];
reactions.toggle_emoji_reaction(msg.id, canonical_name); reactions.toggle_emoji_reaction(msg.id, canonical_name);
return true; return true;
}
case 'toggle_mute': case 'toggle_mute':
muting_ui.toggle_mute(msg); muting_ui.toggle_mute(msg);
return true; return true;
@@ -764,11 +765,12 @@ exports.process_hotkey = function (e, hotkey) {
case 'compose_quote_reply': // > : respond to selected message with quote case 'compose_quote_reply': // > : respond to selected message with quote
compose_actions.quote_and_reply({trigger: 'hotkey'}); compose_actions.quote_and_reply({trigger: 'hotkey'});
return true; return true;
case 'edit_message': case 'edit_message': {
var row = current_msg_list.get_row(msg.id); var row = current_msg_list.get_row(msg.id);
message_edit.start(row); message_edit.start(row);
return true; return true;
} }
}
return false; return false;
}; };

View File

@@ -122,10 +122,11 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {
profile_field.is_user_field = true; profile_field.is_user_field = true;
profile_field.value = field_value.value; profile_field.value = field_value.value;
break; break;
case field_types.CHOICE.id: case field_types.CHOICE.id: {
var field_choice_dict = JSON.parse(field.field_data); var field_choice_dict = JSON.parse(field.field_data);
profile_field.value = field_choice_dict[field_value.value].text; profile_field.value = field_choice_dict[field_value.value].text;
break; break;
}
case field_types.SHORT_TEXT.id: case field_types.SHORT_TEXT.id:
case field_types.LONG_TEXT.id: case field_types.LONG_TEXT.id:
profile_field.value = field_value.value; profile_field.value = field_value.value;

View File

@@ -53,7 +53,7 @@ function get_events_success(events) {
// rarely modified logic for non-normal events. // rarely modified logic for non-normal events.
var dispatch_event = function dispatch_event(event) { var dispatch_event = function dispatch_event(event) {
switch (event.type) { switch (event.type) {
case 'message': case 'message': {
var msg = event.message; var msg = event.message;
msg.flags = event.flags; msg.flags = event.flags;
if (event.local_message_id) { if (event.local_message_id) {
@@ -62,6 +62,7 @@ function get_events_success(events) {
} }
messages.push(msg); messages.push(msg);
break; break;
}
case 'pointer': case 'pointer':
new_pointer = event.pointer; new_pointer = event.pointer;

View File

@@ -21,7 +21,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
settings_streams.update_default_streams_table(); settings_streams.update_default_streams_table();
break; break;
case 'delete_message': case 'delete_message': {
var msg_id = event.message_id; var msg_id = event.message_id;
// message is passed to unread.get_unread_messages, // message is passed to unread.get_unread_messages,
// which returns all the unread messages out of a given list. // which returns all the unread messages out of a given list.
@@ -36,6 +36,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
ui.remove_message(msg_id); ui.remove_message(msg_id);
break; break;
}
case 'hotspots': case 'hotspots':
hotspots.load_new(event.hotspots); hotspots.load_new(event.hotspots);
@@ -58,7 +59,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
activity.update_presence_info(event.email, event.presence, event.server_timestamp); activity.update_presence_info(event.email, event.presence, event.server_timestamp);
break; break;
case 'restart': case 'restart': {
var reload_options = { var reload_options = {
save_pointer: true, save_pointer: true,
save_narrow: true, save_narrow: true,
@@ -70,6 +71,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
reload.initiate(reload_options); reload.initiate(reload_options);
break; break;
}
case 'reaction': case 'reaction':
if (event.op === 'add') { if (event.op === 'add') {
@@ -79,7 +81,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
break; break;
case 'realm': case 'realm': {
var realm_settings = { var realm_settings = {
add_emoji_by_admins_only: settings_emoji.update_custom_emoji_ui, add_emoji_by_admins_only: settings_emoji.update_custom_emoji_ui,
allow_edit_history: noop, allow_edit_history: noop,
@@ -184,6 +186,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
break; break;
}
case 'realm_bot': case 'realm_bot':
if (event.op === 'add') { if (event.op === 'add') {
@@ -221,7 +224,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
settings_linkifiers.populate_filters(page_params.realm_filters); settings_linkifiers.populate_filters(page_params.realm_filters);
break; break;
case 'realm_domains': case 'realm_domains': {
var i; var i;
if (event.op === 'add') { if (event.op === 'add') {
page_params.realm_domains.push(event.realm_domain); page_params.realm_domains.push(event.realm_domain);
@@ -243,6 +246,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
settings_org.populate_realm_domains(page_params.realm_domains); settings_org.populate_realm_domains(page_params.realm_domains);
break; break;
}
case 'realm_user': case 'realm_user':
if (event.op === 'add') { if (event.op === 'add') {
@@ -300,7 +304,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
break; break;
case 'submessage': case 'submessage': {
// The fields in the event don't quite exactly // The fields in the event don't quite exactly
// match the layout of a submessage, since there's // match the layout of a submessage, since there's
// an event id. We also want to be explicit here. // an event id. We also want to be explicit here.
@@ -313,6 +317,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
}; };
submessage.handle_event(submsg); submessage.handle_event(submsg);
break; break;
}
case 'subscription': case 'subscription':
if (event.op === 'add') { if (event.op === 'add') {
@@ -369,7 +374,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
break; break;
case 'update_display_settings': case 'update_display_settings': {
var user_display_settings = [ var user_display_settings = [
'default_language', 'default_language',
'demote_inactive_streams', 'demote_inactive_streams',
@@ -446,6 +451,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
} }
settings_display.update_page(); settings_display.update_page();
break; break;
}
case 'update_global_notifications': case 'update_global_notifications':
notifications.handle_global_notification_updates(event.notification_name, notifications.handle_global_notification_updates(event.notification_name,
@@ -457,7 +463,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
// (E.g. update_stream_push_notifications). // (E.g. update_stream_push_notifications).
break; break;
case 'update_message_flags': case 'update_message_flags': {
var new_value = event.operation === "add"; var new_value = event.operation === "add";
switch (event.flag) { switch (event.flag) {
case 'starred': case 'starred':
@@ -475,6 +481,7 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
break; break;
} }
break; break;
}
case 'user_group': case 'user_group':
if (event.op === 'add') { if (event.op === 'add') {

View File

@@ -113,10 +113,11 @@ exports.options = function (config) {
case 413: // HTTP status "Request Entity Too Large" case 413: // HTTP status "Request Entity Too Large"
msg = i18n.t("Sorry, the file was too large."); msg = i18n.t("Sorry, the file was too large.");
break; break;
case 400: case 400: {
var server_message = server_response && server_response.msg; var server_message = server_response && server_response.msg;
msg = server_message || i18n.t("An unknown error occurred."); msg = server_message || i18n.t("An unknown error occurred.");
break; break;
}
default: default:
msg = i18n.t("An unknown error occurred."); msg = i18n.t("An unknown error occurred.");
break; break;