Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Indent case clauses in switch statements.
Anders Kaseorg6924d501bc6a
diff --git a/.eslintrc.json b/.eslintrc.jsonindex eec188d2710..87cb1461bca 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -38,6 +38,7 @@"indent": ["error", 4, {"ArrayExpression": "first","ObjectExpression": "first",+ "SwitchCase": 1,"CallExpression": {"arguments": "first"},"FunctionExpression": {"parameters": "first"},"FunctionDeclaration": {"parameters": "first"}diff --git a/frontend_tests/node_tests/.eslintrc.json b/frontend_tests/node_tests/.eslintrc.jsondeleted file mode 100644index 5ff2ace9231..00000000000--- a/frontend_tests/node_tests/.eslintrc.json+++ /dev/null@@ -1,12 +0,0 @@-{- "rules": {- "indent": ["error", 4, {- "ArrayExpression": "first",- "ObjectExpression": "first",- "SwitchCase": 0,- "CallExpression": {"arguments": "first"},- "FunctionExpression": {"parameters": "first"},- "FunctionDeclaration": {"parameters": "first"}- }]- }-}diff --git a/static/js/buddy_data.js b/static/js/buddy_data.jsindex 95ce48ef874..e69aec82986 100644--- a/static/js/buddy_data.js+++ b/static/js/buddy_data.js@@ -26,15 +26,15 @@ exports.get_user_circle_class = function (user_id) {const status = exports.buddy_status(user_id);switch (status) {- case "active":- return "user_circle_green";- case "idle":- return "user_circle_orange";- case "away_them":- case "away_me":- return "user_circle_empty_line";- default:- return "user_circle_empty";+ case "active":+ return "user_circle_green";+ case "idle":+ return "user_circle_orange";+ case "away_them":+ case "away_me":+ return "user_circle_empty_line";+ default:+ return "user_circle_empty";}};@@ -42,15 +42,15 @@ exports.status_description = function (user_id) {const status = exports.buddy_status(user_id);switch (status) {- case "active":- return i18n.t("Active");- case "idle":- return i18n.t("Idle");- case "away_them":- case "away_me":- return i18n.t("Unavailable");- default:- return i18n.t("Offline");+ case "active":+ return i18n.t("Active");+ case "idle":+ return i18n.t("Idle");+ case "away_them":+ case "away_me":+ return i18n.t("Unavailable");+ default:+ return i18n.t("Offline");}};@@ -63,14 +63,14 @@ exports.level = function (user_id) {const status = exports.buddy_status(user_id);switch (status) {- case "active":- return 1;- case "idle":- return 2;- case "away_them":- return 3;- default:- return 3;+ case "active":+ return 1;+ case "idle":+ return 2;+ case "away_them":+ return 3;+ default:+ return 3;}};diff --git a/static/js/compose.js b/static/js/compose.jsindex e645b01fd95..d67205c8f72 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -543,21 +543,21 @@ exports.validation_error = function (error_type, stream_name) {context.stream_name = Handlebars.Utils.escapeExpression(stream_name);switch (error_type) {- case "does-not-exist":- response = i18n.t("<p>The stream <b>__stream_name__</b> does not exist.</p><p>Manage your subscriptions <a href='#streams/all'>on your Streams page</a>.</p>", context);- compose_error(response, $("#stream_message_recipient_stream"));- return false;- case "error":- compose_error(i18n.t("Error checking subscription"),- $("#stream_message_recipient_stream"));- return false;- case "not-subscribed": {- const sub = stream_data.get_sub(stream_name);- const new_row = render_compose_not_subscribed({- should_display_sub_button: sub.should_display_subscription_button});- compose_not_subscribed_error(new_row, $("#stream_message_recipient_stream"));- return false;- }+ case "does-not-exist":+ response = i18n.t("<p>The stream <b>__stream_name__</b> does not exist.</p><p>Manage your subscriptions <a href='#streams/all'>on your Streams page</a>.</p>", context);+ compose_error(response, $("#stream_message_recipient_stream"));+ return false;+ case "error":+ compose_error(i18n.t("Error checking subscription"),+ $("#stream_message_recipient_stream"));+ return false;+ case "not-subscribed": {+ const sub = stream_data.get_sub(stream_name);+ const new_row = render_compose_not_subscribed({+ should_display_sub_button: sub.should_display_subscription_button});+ compose_not_subscribed_error(new_row, $("#stream_message_recipient_stream"));+ return false;+ }}return true;};diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.jsindex c53ae882ae9..85950b73639 100644--- a/static/js/composebox_typeahead.js+++ b/static/js/composebox_typeahead.js@@ -291,43 +291,43 @@ exports.tokenize_compose_str = function (s) {while (i > min_i) {i -= 1;switch (s[i]) {- case "`":- case "~":+ case "`":+ case "~":// Code block must start on a new line- if (i === 2) {- return s;- } else if (i > 2 && s[i - 3] === "\n") {- return s.slice(i - 2);- }- break;- case "/":- if (i === 0) {- return s;- }- break;- case "#":- case "@":- case ":":- case "_":- if (i === 0) {- return s;- } else if (/[\s(){}[\]]/.test(s[i - 1])) {- return s.slice(i);- }- break;- case ">":+ if (i === 2) {+ return s;+ } else if (i > 2 && s[i - 3] === "\n") {+ return s.slice(i - 2);+ }+ break;+ case "/":+ if (i === 0) {+ return s;+ }+ break;+ case "#":+ case "@":+ case ":":+ case "_":+ if (i === 0) {+ return s;+ } else if (/[\s(){}[\]]/.test(s[i - 1])) {+ return s.slice(i);+ }+ break;+ case ">":// topic_jump//// If you hit `>` immediately after completing the typeahead for mentioning a stream,// this will reposition the user from. If | is the cursor, implements://// `#**stream name** >|` => `#**stream name>|`.- if (s.substring(i - 2, i) === "**" || s.substring(i - 3, i) === "** ") {+ if (s.substring(i - 2, i) === "**" || s.substring(i - 3, i) === "** ") {// return any string as long as its not ''.- return ">topic_jump";- }- // maybe topic_list; let's let the stream_topic_regex decide later.- return ">topic_list";+ return ">topic_jump";+ }+ // maybe topic_list; let's let the stream_topic_regex decide later.+ return ">topic_list";}}@@ -916,44 +916,44 @@ exports.content_typeahead_selected = function (item, event) {exports.compose_content_matcher = function (completing, token) {switch (completing) {- case "emoji":- return typeahead.get_emoji_matcher(token);- case "slash":- return get_slash_matcher(token);- case "stream":- return get_stream_or_user_group_matcher(token);- case "syntax":- return get_language_matcher(token);- case "topic_list":- return get_topic_matcher(token);+ case "emoji":+ return typeahead.get_emoji_matcher(token);+ case "slash":+ return get_slash_matcher(token);+ case "stream":+ return get_stream_or_user_group_matcher(token);+ case "syntax":+ return get_language_matcher(token);+ case "topic_list":+ return get_topic_matcher(token);}return function () {switch (completing) {- case "topic_jump":- case "time_jump":+ case "topic_jump":+ case "time_jump":// these don't actually have a typeahead popover, so we return quickly here.- return true;+ return true;}};};exports.sort_results = function (completing, matches, token) {switch (completing) {- case "emoji":- return typeahead.sort_emojis(matches, token);- case "slash":- return typeahead_helper.sort_slash_commands(matches, token);- case "stream":- return typeahead_helper.sort_streams(matches, token);- case "syntax":- return typeahead_helper.sort_languages(matches, token);- case "topic_jump":- case "time_jump":+ case "emoji":+ return typeahead.sort_emojis(matches, token);+ case "slash":+ return typeahead_helper.sort_slash_commands(matches, token);+ case "stream":+ return typeahead_helper.sort_streams(matches, token);+ case "syntax":+ return typeahead_helper.sort_languages(matches, token);+ case "topic_jump":+ case "time_jump":// topic_jump doesn't actually have a typeahead popover, so we return quickly here.- return matches;- case "topic_list":- return typeahead_helper.sorter(token, matches, (x) => x);+ return matches;+ case "topic_list":+ return typeahead_helper.sorter(token, matches, (x) => x);}};@@ -977,21 +977,21 @@ exports.compose_trigger_selection = function (event) {function get_header_text() {let tip_text = "";switch (this.completing) {- case "stream":- tip_text = i18n.t("Press > for list of topics");- break;- case "silent_mention":- tip_text = i18n.t("User will not be notified");- break;- case "syntax":- if (page_params.realm_default_code_block_language !== null) {- tip_text = i18n.t("Default is __language__. Use 'text' to disable highlighting.",- {language: page_params.realm_default_code_block_language});+ case "stream":+ tip_text = i18n.t("Press > for list of topics");break;- }- return false;- default:- return false;+ case "silent_mention":+ tip_text = i18n.t("User will not be notified");+ break;+ case "syntax":+ if (page_params.realm_default_code_block_language !== null) {+ tip_text = i18n.t("Default is __language__. Use 'text' to disable highlighting.",+ {language: page_params.realm_default_code_block_language});+ break;+ }+ return false;+ default:+ return false;}return "<em>" + tip_text + "</em>";}diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.jsindex 951e7682542..2a05559e003 100644--- a/static/js/emoji_picker.js+++ b/static/js/emoji_picker.js@@ -472,18 +472,18 @@ exports.navigate = function (event_name, e) {} else if (!is_filter_focused) {let next_coord = {};switch (event_name) {- case "down_arrow":- next_coord = get_next_emoji_coordinates(6);- break;- case "up_arrow":- next_coord = get_next_emoji_coordinates(-6);- break;- case "left_arrow":- next_coord = get_next_emoji_coordinates(-1);- break;- case "right_arrow":- next_coord = get_next_emoji_coordinates(1);- break;+ case "down_arrow":+ next_coord = get_next_emoji_coordinates(6);+ break;+ case "up_arrow":+ next_coord = get_next_emoji_coordinates(-6);+ break;+ case "left_arrow":+ next_coord = get_next_emoji_coordinates(-1);+ break;+ case "right_arrow":+ next_coord = get_next_emoji_coordinates(1);+ break;}return maybe_change_focused_emoji($emoji_map, next_coord.section, next_coord.index);diff --git a/static/js/filter.js b/static/js/filter.jsindex cd4f893654b..186ebca5516 100644--- a/static/js/filter.js+++ b/static/js/filter.js@@ -46,112 +46,112 @@ function message_in_home(message) {function message_matches_search_term(message, operator, operand) {switch (operator) {- case "has":- if (operand === "image") {- return message_util.message_has_image(message);- } else if (operand === "link") {- return message_util.message_has_link(message);- } else if (operand === "attachment") {- return message_util.message_has_attachment(message);- }- return false; // has:something_else returns false- case "is":- if (operand === "private") {- return message.type === "private";- } else if (operand === "starred") {- return message.starred;- } else if (operand === "mentioned") {- return message.mentioned;- } else if (operand === "alerted") {- return message.alerted;- } else if (operand === "unread") {- return unread.message_unread(message);- }- return true; // is:whatever returns true-- case "in":- if (operand === "home") {- return message_in_home(message);- } else if (operand === "all") {- return true;- }- return true; // in:whatever returns true+ case "has":+ if (operand === "image") {+ return message_util.message_has_image(message);+ } else if (operand === "link") {+ return message_util.message_has_link(message);+ } else if (operand === "attachment") {+ return message_util.message_has_attachment(message);+ }+ return false; // has:something_else returns false+ case "is":+ if (operand === "private") {+ return message.type === "private";+ } else if (operand === "starred") {+ return message.starred;+ } else if (operand === "mentioned") {+ return message.mentioned;+ } else if (operand === "alerted") {+ return message.alerted;+ } else if (operand === "unread") {+ return unread.message_unread(message);+ }+ return true; // is:whatever returns true- case "near":- // this is all handled server side- return true;+ case "in":+ if (operand === "home") {+ return message_in_home(message);+ } else if (operand === "all") {+ return true;+ }+ return true; // in:whatever returns true- case "id":- return message.id.toString() === operand;+ case "near":+ // this is all handled server side+ return true;- case "stream": {- if (message.type !== "stream") {- return false;- }+ case "id":+ return message.id.toString() === operand;- operand = operand.toLowerCase();- if (page_params.realm_is_zephyr_mirror_realm) {- return zephyr_stream_name_match(message, operand);- }+ case "stream": {+ if (message.type !== "stream") {+ return false;+ }- // Try to match by stream_id if have a valid sub for- // the operand.- const stream_id = stream_data.get_stream_id(operand);- if (stream_id) {- return message.stream_id === stream_id;- }+ operand = operand.toLowerCase();+ if (page_params.realm_is_zephyr_mirror_realm) {+ return zephyr_stream_name_match(message, operand);+ }- // We need this fallback logic in case we have a message- // loaded for a stream that we are no longer- // subscribed to (or that was deleted).- return message.stream.toLowerCase() === operand;- }+ // Try to match by stream_id if have a valid sub for+ // the operand.+ const stream_id = stream_data.get_stream_id(operand);+ if (stream_id) {+ return message.stream_id === stream_id;+ }- case "topic":- if (message.type !== "stream") {- return false;+ // We need this fallback logic in case we have a message+ // loaded for a stream that we are no longer+ // subscribed to (or that was deleted).+ return message.stream.toLowerCase() === operand;}- operand = operand.toLowerCase();- if (page_params.realm_is_zephyr_mirror_realm) {- return zephyr_topic_name_match(message, operand);- }- return message.topic.toLowerCase() === operand;+ case "topic":+ if (message.type !== "stream") {+ return false;+ }++ operand = operand.toLowerCase();+ if (page_params.realm_is_zephyr_mirror_realm) {+ return zephyr_topic_name_match(message, operand);+ }+ return message.topic.toLowerCase() === operand;- case "sender":- return people.id_matches_email_operand(message.sender_id, operand);+ case "sender":+ return people.id_matches_email_operand(message.sender_id, operand);- case "group-pm-with": {- const operand_ids = people.pm_with_operand_ids(operand);- if (!operand_ids) {- return false;- }- const user_ids = people.group_pm_with_user_ids(message);- if (!user_ids) {- return false;- }- return user_ids.includes(operand_ids[0]);+ case "group-pm-with": {+ const operand_ids = people.pm_with_operand_ids(operand);+ if (!operand_ids) {+ return false;+ }+ const user_ids = people.group_pm_with_user_ids(message);+ if (!user_ids) {+ return false;+ }+ return user_ids.includes(operand_ids[0]);// 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.- }+ }- case "pm-with": {+ case "pm-with": {// TODO: use user_ids, not emails here- if (message.type !== "private") {- return false;- }- const operand_ids = people.pm_with_operand_ids(operand);- if (!operand_ids) {- return false;- }- const user_ids = people.pm_with_user_ids(message);- if (!user_ids) {- return false;- }+ if (message.type !== "private") {+ return false;+ }+ const operand_ids = people.pm_with_operand_ids(operand);+ if (!operand_ids) {+ return false;+ }+ const user_ids = people.pm_with_user_ids(message);+ if (!user_ids) {+ return false;+ }- return _.isEqual(operand_ids, user_ids);- }+ return _.isEqual(operand_ids, user_ids);+ }}return true; // unknown operators return true (effectively ignored)@@ -196,36 +196,36 @@ Filter.canonicalize_term = function (opts) {operator = Filter.canonicalize_operator(operator);switch (operator) {- case "has":+ case "has":// images -> image, etc.- operand = operand.replace(/s$/, "");- break;-- case "stream":- operand = stream_data.get_name(operand);- break;- case "topic":- break;- case "sender":- case "pm-with":- operand = operand.toString().toLowerCase();- if (operand === "me") {- operand = people.my_current_email();- }- break;- case "group-pm-with":- operand = operand.toString().toLowerCase();- break;- case "search":+ operand = operand.replace(/s$/, "");+ break;++ case "stream":+ operand = stream_data.get_name(operand);+ break;+ case "topic":+ break;+ case "sender":+ case "pm-with":+ operand = operand.toString().toLowerCase();+ if (operand === "me") {+ operand = people.my_current_email();+ }+ break;+ case "group-pm-with":+ operand = operand.toString().toLowerCase();+ break;+ case "search":// The mac app automatically substitutes regular quotes with curly// quotes when typing in the search bar. Curly quotes don't trigger our// phrase search behavior, however. So, we replace all instances of// curly quotes with regular quotes when doing a search. This is// unlikely to cause any problems and is probably what the user wants.- operand = operand.toString().toLowerCase().replace(/[\u201c\u201d]/g, '"');- break;- default:- operand = operand.toString().toLowerCase();+ operand = operand.toString().toLowerCase().replace(/[\u201c\u201d]/g, '"');+ break;+ default:+ operand = operand.toString().toLowerCase();}// We may want to consider allowing mixed-case operators at some point@@ -504,27 +504,27 @@ Filter.prototype = {if (term_types[1] === "search") {switch (term_types[0]) {- case "stream":+ case "stream":// if stream does not exist, redirect to All- if (!this._sub) {- return "#";- }- return "/#narrow/stream/" + stream_data.name_to_slug(this.operands("stream")[0]);- case "is-private":- return "/#narrow/is/private";- case "is-starred":- return "/#narrow/is/starred";- case "is-mentioned":- return "/#narrow/is/mentioned";- case "streams-public":- return "/#narrow/streams/public";- case "pm-with":+ if (!this._sub) {+ return "#";+ }+ return "/#narrow/stream/" + stream_data.name_to_slug(this.operands("stream")[0]);+ case "is-private":+ return "/#narrow/is/private";+ case "is-starred":+ return "/#narrow/is/starred";+ case "is-mentioned":+ return "/#narrow/is/mentioned";+ case "streams-public":+ return "/#narrow/streams/public";+ case "pm-with":// join is used to transform the array to a comma separated string- return "/#narrow/pm-with/" + people.emails_to_slug(this.operands("pm-with").join());+ return "/#narrow/pm-with/" + people.emails_to_slug(this.operands("pm-with").join());// TODO: It is ambiguous how we want to handle the 'sender' case,// we may remove it in the future based on design decisions- case "sender":- return "/#narrow/sender/" + people.emails_to_slug(this.operands("sender")[0]);+ case "sender":+ return "/#narrow/sender/" + people.emails_to_slug(this.operands("sender")[0]);}}@@ -535,28 +535,28 @@ Filter.prototype = {// We have special icons for the simple narrows available for the via sidebars.const term_types = this.sorted_term_types();switch (term_types[0]) {- case "in-home":- case "in-all":- return "home";- case "stream":- if (!this._sub) {- return "question-circle-o";- }- if (this._sub.invite_only) {- return "lock";- }- if (this._sub.is_web_public) {- return "globe";- }- return "hashtag";- case "is-private":- return "envelope";- case "is-starred":- return "star";- case "is-mentioned":- return "at";- case "pm-with":- return "envelope";+ case "in-home":+ case "in-all":+ return "home";+ case "stream":+ if (!this._sub) {+ return "question-circle-o";+ }+ if (this._sub.invite_only) {+ return "lock";+ }+ if (this._sub.is_web_public) {+ return "globe";+ }+ return "hashtag";+ case "is-private":+ return "envelope";+ case "is-starred":+ return "star";+ case "is-mentioned":+ return "at";+ case "pm-with":+ return "envelope";}},@@ -572,37 +572,37 @@ Filter.prototype = {}if (term_types.length === 1 || term_types.length === 2 && term_types[1] === "search") {switch (term_types[0]) {- case "in-home":- return i18n.t("All messages");- case "in-all":- return i18n.t("All messages including muted streams");- case "streams-public":- return i18n.t("Public stream messages in organization");- case "stream":- if (!this._sub) {- return i18n.t("Unknown stream");- }- return this._sub.name;- case "is-starred":- return i18n.t("Starred messages");- case "is-mentioned":- return i18n.t("Mentions");- case "is-private":- return i18n.t("Private messages");- case "pm-with": {- const emails = this.operands("pm-with")[0].split(",");- const names = emails.map((email) => {- if (!people.get_by_email(email)) {- return email;+ case "in-home":+ return i18n.t("All messages");+ case "in-all":+ return i18n.t("All messages including muted streams");+ case "streams-public":+ return i18n.t("Public stream messages in organization");+ case "stream":+ if (!this._sub) {+ return i18n.t("Unknown stream");}- return people.get_by_email(email).full_name;- });-- // We use join to handle the addition of a comma and space after every name- // and also to ensure that we return a string and not an array so that we- // can have the same return type as other cases.- return names.join(", ");- }+ return this._sub.name;+ case "is-starred":+ return i18n.t("Starred messages");+ case "is-mentioned":+ return i18n.t("Mentions");+ case "is-private":+ return i18n.t("Private messages");+ case "pm-with": {+ const emails = this.operands("pm-with")[0].split(",");+ const names = emails.map((email) => {+ if (!people.get_by_email(email)) {+ return email;+ }+ return people.get_by_email(email).full_name;+ });++ // We use join to handle the addition of a comma and space after every name+ // and also to ensure that we return a string and not an array so that we+ // can have the same return type as other cases.+ return names.join(", ");+ }}}},@@ -743,15 +743,15 @@ Filter.prototype = {update_email: function (user_id, new_email) {for (const term of this._operators) {switch (term.operator) {- case "group-pm-with":- case "pm-with":- case "sender":- case "from":- term.operand = people.update_email_in_reply_to(- term.operand,- user_id,- new_email,- );+ case "group-pm-with":+ case "pm-with":+ case "sender":+ case "from":+ term.operand = people.update_email_in_reply_to(+ term.operand,+ user_id,+ new_email,+ );}}},@@ -838,38 +838,38 @@ Filter.operator_to_prefix = function (operator, negated) {const verb = negated ? "exclude " : "";switch (operator) {- case "stream":- return verb + "stream";- case "streams":- return verb + "streams";- case "near":- return verb + "messages around";+ case "stream":+ return verb + "stream";+ case "streams":+ return verb + "streams";+ case "near":+ return verb + "messages around";- // Note: We hack around using this in "describe" below.- case "has":- return verb + "messages with one or more";+ // Note: We hack around using this in "describe" below.+ case "has":+ return verb + "messages with one or more";- case "id":- return verb + "message ID";+ case "id":+ return verb + "message ID";- case "topic":- return verb + "topic";+ case "topic":+ return verb + "topic";- case "sender":- return verb + "sent by";+ case "sender":+ return verb + "sent by";- case "pm-with":- return verb + "private messages with";+ case "pm-with":+ return verb + "private messages with";- case "in":- return verb + "messages in";+ case "in":+ return verb + "messages in";- // Note: We hack around using this in "describe" below.- case "is":- return verb + "messages that are";+ // Note: We hack around using this in "describe" below.+ case "is":+ return verb + "messages that are";- case "group-pm-with":- return verb + "group private messages including";+ case "group-pm-with":+ return verb + "group private messages including";}return "";};diff --git a/static/js/hashchange.js b/static/js/hashchange.jsindex 07279ba1650..0a5cc308873 100644--- a/static/js/hashchange.js+++ b/static/js/hashchange.js@@ -77,53 +77,53 @@ function do_hashchange_normal(from_reload) {// be #ABCD.const hash = window.location.hash.split("/");switch (hash[0]) {- case "#narrow": {- ui_util.change_tab_to("#home");- const operators = hash_util.parse_narrow(hash);- if (operators === undefined) {+ case "#narrow": {+ ui_util.change_tab_to("#home");+ const operators = hash_util.parse_narrow(hash);+ if (operators === undefined) {// If the narrow URL didn't parse, clear// window.location.hash and send them to the home tab- set_hash("");- activate_home_tab();- return false;- }- const narrow_opts = {- change_hash: false, // already set- trigger: "hash change",- };- if (from_reload) {- blueslip.debug("We are narrowing as part of a reload.");- if (page_params.initial_narrow_pointer !== undefined) {- home_msg_list.pre_narrow_offset = page_params.initial_offset;- narrow_opts.then_select_id = page_params.initial_narrow_pointer;- narrow_opts.then_select_offset = page_params.initial_narrow_offset;+ set_hash("");+ activate_home_tab();+ return false;+ }+ const narrow_opts = {+ change_hash: false, // already set+ trigger: "hash change",+ };+ if (from_reload) {+ blueslip.debug("We are narrowing as part of a reload.");+ if (page_params.initial_narrow_pointer !== undefined) {+ home_msg_list.pre_narrow_offset = page_params.initial_offset;+ narrow_opts.then_select_id = page_params.initial_narrow_pointer;+ narrow_opts.then_select_offset = page_params.initial_narrow_offset;+ }}+ narrow.activate(operators, narrow_opts);+ floating_recipient_bar.update();+ return true;}- narrow.activate(operators, narrow_opts);- floating_recipient_bar.update();- return true;- }- case "":- case "#":- activate_home_tab();- break;- case "#keyboard-shortcuts":- info_overlay.show("keyboard-shortcuts");- break;- case "#message-formatting":- info_overlay.show("message-formatting");- break;- case "#search-operators":- info_overlay.show("search-operators");- break;- case "#drafts":- case "#invite":- case "#streams":- case "#organization":- case "#settings":- case "#recent_topics":- blueslip.error("overlay logic skipped for: " + hash);- break;+ case "":+ case "#":+ activate_home_tab();+ break;+ case "#keyboard-shortcuts":+ info_overlay.show("keyboard-shortcuts");+ break;+ case "#message-formatting":+ info_overlay.show("message-formatting");+ break;+ case "#search-operators":+ info_overlay.show("search-operators");+ break;+ case "#drafts":+ case "#invite":+ case "#streams":+ case "#organization":+ case "#settings":+ case "#recent_topics":+ blueslip.error("overlay logic skipped for: " + hash);+ break;}return false;}diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 35522db7a2a..576a7e03b0d 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -423,40 +423,40 @@ exports.process_hotkey = function (e, hotkey) {// This block needs to be before the `tab` handler.switch (event_name) {- case "up_arrow":- case "down_arrow":- case "left_arrow":- case "right_arrow":- case "tab":- case "shift_tab":- if (overlays.recent_topics_open()) {- return recent_topics.change_focused_element(e, event_name);- }+ case "up_arrow":+ case "down_arrow":+ case "left_arrow":+ case "right_arrow":+ case "tab":+ case "shift_tab":+ if (overlays.recent_topics_open()) {+ return recent_topics.change_focused_element(e, event_name);+ }}// We handle the most complex keys in their own functions.switch (event_name) {- case "escape":- return exports.process_escape_key(e);- case "enter":- return exports.process_enter_key(e);- case "tab":- return exports.process_tab_key();- case "shift_tab":- return exports.process_shift_tab_key();+ case "escape":+ return exports.process_escape_key(e);+ case "enter":+ return exports.process_enter_key(e);+ case "tab":+ return exports.process_tab_key();+ case "shift_tab":+ return exports.process_shift_tab_key();}// TODO: break out specific handlers for up_arrow,// down_arrow, and backspaceswitch (event_name) {- case "up_arrow":- case "down_arrow":- case "backspace":- case "delete":- if (overlays.drafts_open()) {- drafts.drafts_handle_events(e, event_name);- return true;- }+ case "up_arrow":+ case "down_arrow":+ case "backspace":+ case "delete":+ if (overlays.drafts_open()) {+ drafts.drafts_handle_events(e, event_name);+ return true;+ }}if (hotkey.message_view_only && overlays.is_active()) {@@ -626,64 +626,64 @@ exports.process_hotkey = function (e, hotkey) {// Shortcuts that don't require a messageswitch (event_name) {- case "compose": // 'c': compose- compose_actions.start("stream", {trigger: "compose_hotkey"});- return true;- case "compose_private_message":- compose_actions.start("private", {trigger: "compose_hotkey"});- return true;- case "narrow_private":- return do_narrow_action((target, opts) => {- narrow.by("is", "private", opts);- });- case "query_streams":- stream_list.initiate_search();- return true;- case "query_users":- activity.initiate_search();- return true;- case "search":- case "search_with_k":- search.initiate_search();- return true;- case "gear_menu":- gear_menu.open();- return true;- case "show_shortcuts": // Show keyboard shortcuts page- info_overlay.maybe_show_keyboard_shortcuts();- return true;- case "stream_cycle_backward":- narrow.stream_cycle_backward();- return true;- case "stream_cycle_forward":- narrow.stream_cycle_forward();- return true;- case "n_key":- narrow.narrow_to_next_topic();- return true;- case "p_key":- narrow.narrow_to_next_pm_string();- return true;- case "open_drafts":- drafts.launch();- return true;- case "reply_message": // 'r': respond to message+ case "compose": // 'c': compose+ compose_actions.start("stream", {trigger: "compose_hotkey"});+ return true;+ case "compose_private_message":+ compose_actions.start("private", {trigger: "compose_hotkey"});+ return true;+ case "narrow_private":+ return do_narrow_action((target, opts) => {+ narrow.by("is", "private", opts);+ });+ case "query_streams":+ stream_list.initiate_search();+ return true;+ case "query_users":+ activity.initiate_search();+ return true;+ case "search":+ case "search_with_k":+ search.initiate_search();+ return true;+ case "gear_menu":+ gear_menu.open();+ return true;+ case "show_shortcuts": // Show keyboard shortcuts page+ info_overlay.maybe_show_keyboard_shortcuts();+ return true;+ case "stream_cycle_backward":+ narrow.stream_cycle_backward();+ return true;+ case "stream_cycle_forward":+ narrow.stream_cycle_forward();+ return true;+ case "n_key":+ narrow.narrow_to_next_topic();+ return true;+ case "p_key":+ narrow.narrow_to_next_pm_string();+ return true;+ case "open_drafts":+ drafts.launch();+ return true;+ case "reply_message": // 'r': respond to message// Note that you can "enter" to respond to messages as well,// but that is handled in process_enter_key().- compose_actions.respond_to_message({trigger: "hotkey"});- return true;- case "C_deprecated":- ui.maybe_show_deprecation_notice("C");- return true;- case "star_deprecated":- ui.maybe_show_deprecation_notice("*");- return true;- case "copy_with_c":- copy_and_paste.copy_handler();- return true;- case "open_recent_topics":- hashchange.go_to_location("recent_topics");- return true;+ compose_actions.respond_to_message({trigger: "hotkey"});+ return true;+ case "C_deprecated":+ ui.maybe_show_deprecation_notice("C");+ return true;+ case "star_deprecated":+ ui.maybe_show_deprecation_notice("*");+ return true;+ case "copy_with_c":+ copy_and_paste.copy_handler();+ return true;+ case "open_recent_topics":+ hashchange.go_to_location("recent_topics");+ return true;}if (current_msg_list.empty()) {@@ -692,81 +692,81 @@ exports.process_hotkey = function (e, hotkey) {// Navigation shortcutsswitch (event_name) {- case "down_arrow":- case "vim_down":- navigate.down(true); // with_centering- return true;- case "up_arrow":- case "vim_up":- navigate.up();- return true;- case "home":- navigate.to_home();- return true;- case "end":- case "G_end":- navigate.to_end();- return true;- case "page_up":- case "vim_page_up":- case "shift_spacebar":- navigate.page_up();- return true;- case "page_down":- case "vim_page_down":- case "spacebar":- navigate.page_down();- return true;+ case "down_arrow":+ case "vim_down":+ navigate.down(true); // with_centering+ return true;+ case "up_arrow":+ case "vim_up":+ navigate.up();+ return true;+ case "home":+ navigate.to_home();+ return true;+ case "end":+ case "G_end":+ navigate.to_end();+ return true;+ case "page_up":+ case "vim_page_up":+ case "shift_spacebar":+ navigate.page_up();+ return true;+ case "page_down":+ case "vim_page_down":+ case "spacebar":+ navigate.page_down();+ return true;}const msg = current_msg_list.selected_message();// Shortcuts that operate on a messageswitch (event_name) {- case "message_actions":- return popovers.open_message_menu(msg);- case "star_message":- message_flags.toggle_starred_and_update_server(msg);- return true;- case "narrow_by_recipient":- return do_narrow_action(narrow.by_recipient);- case "narrow_by_topic":- return do_narrow_action(narrow.by_topic);- case "respond_to_author": // 'R': respond to author- compose_actions.respond_to_message({reply_type: "personal", trigger: "hotkey pm"});- return true;- case "compose_reply_with_mention": // '@': respond to message with mention to author- compose_actions.reply_with_mention({trigger: "hotkey"});- return true;- case "show_lightbox":- lightbox.show_from_selected_message();- return true;- case "show_sender_info":- popovers.show_sender_info();- return true;- case "toggle_reactions_popover": // ':': open reactions to message- reactions.open_reactions_popover();- return true;- case "thumbs_up_emoji": { // '+': reacts with thumbs up emoji on selected message+ case "message_actions":+ return popovers.open_message_menu(msg);+ case "star_message":+ message_flags.toggle_starred_and_update_server(msg);+ return true;+ case "narrow_by_recipient":+ return do_narrow_action(narrow.by_recipient);+ case "narrow_by_topic":+ return do_narrow_action(narrow.by_topic);+ case "respond_to_author": // 'R': respond to author+ compose_actions.respond_to_message({reply_type: "personal", trigger: "hotkey pm"});+ return true;+ case "compose_reply_with_mention": // '@': respond to message with mention to author+ compose_actions.reply_with_mention({trigger: "hotkey"});+ return true;+ case "show_lightbox":+ lightbox.show_from_selected_message();+ return true;+ case "show_sender_info":+ popovers.show_sender_info();+ return true;+ case "toggle_reactions_popover": // ':': open reactions to message+ reactions.open_reactions_popover();+ return true;+ case "thumbs_up_emoji": { // '+': reacts with thumbs up emoji on selected message// Use canonical name.- const thumbs_up_emoji_code = "1f44d";- const canonical_name = emoji.get_emoji_name(thumbs_up_emoji_code);- reactions.toggle_emoji_reaction(msg.id, canonical_name);- return true;- }- case "toggle_mute":- muting_ui.toggle_mute(msg);- return true;- case "toggle_message_collapse":- condense.toggle_collapse(msg);- return true;- case "compose_quote_reply": // > : respond to selected message with quote- compose_actions.quote_and_reply({trigger: "hotkey"});- return true;- case "edit_message": {- const row = current_msg_list.get_row(msg.id);- message_edit.start(row);- return true;- }+ const thumbs_up_emoji_code = "1f44d";+ const canonical_name = emoji.get_emoji_name(thumbs_up_emoji_code);+ reactions.toggle_emoji_reaction(msg.id, canonical_name);+ return true;+ }+ case "toggle_mute":+ muting_ui.toggle_mute(msg);+ return true;+ case "toggle_message_collapse":+ condense.toggle_collapse(msg);+ return true;+ case "compose_quote_reply": // > : respond to selected message with quote+ compose_actions.quote_and_reply({trigger: "hotkey"});+ return true;+ case "edit_message": {+ const row = current_msg_list.get_row(msg.id);+ message_edit.start(row);+ return true;+ }}return false;diff --git a/static/js/hotspots.js b/static/js/hotspots.jsindex d48032df54b..0cfcd3605dc 100644--- a/static/js/hotspots.js+++ b/static/js/hotspots.js@@ -100,60 +100,60 @@ function place_popover(hotspot) {);switch (orientation) {- case TOP:- popover_offset = {- top: -(popover_height + arrow_offset),- left: el_width / 2 - popover_width / 2,- };- arrow_placement = "bottom";- break;-- case LEFT:- popover_offset = {- top: el_height / 2 - popover_height / 2,- left: -(popover_width + arrow_offset),- };- arrow_placement = "right";- break;-- case BOTTOM:- popover_offset = {- top: el_height + arrow_offset,- left: el_width / 2 - popover_width / 2,- };- arrow_placement = "top";- break;-- case RIGHT:- popover_offset = {- top: el_height / 2 - popover_height / 2,- left: el_width + arrow_offset,- };- arrow_placement = "left";- break;-- case LEFT_BOTTOM:- popover_offset = {- top: 0,- left: -(popover_width + arrow_offset / 2),- };- arrow_placement = "";- break;-- case VIEWPORT_CENTER:- popover_offset = {- top: el_height / 2,- left: el_width / 2,- };- arrow_placement = "";- break;-- default:- blueslip.error(- "Invalid popover placement value for hotspot '" ++ case TOP:+ popover_offset = {+ top: -(popover_height + arrow_offset),+ left: el_width / 2 - popover_width / 2,+ };+ arrow_placement = "bottom";+ break;++ case LEFT:+ popover_offset = {+ top: el_height / 2 - popover_height / 2,+ left: -(popover_width + arrow_offset),+ };+ arrow_placement = "right";+ break;++ case BOTTOM:+ popover_offset = {+ top: el_height + arrow_offset,+ left: el_width / 2 - popover_width / 2,+ };+ arrow_placement = "top";+ break;++ case RIGHT:+ popover_offset = {+ top: el_height / 2 - popover_height / 2,+ left: el_width + arrow_offset,+ };+ arrow_placement = "left";+ break;++ case LEFT_BOTTOM:+ popover_offset = {+ top: 0,+ left: -(popover_width + arrow_offset / 2),+ };+ arrow_placement = "";+ break;++ case VIEWPORT_CENTER:+ popover_offset = {+ top: el_height / 2,+ left: el_width / 2,+ };+ arrow_placement = "";+ break;++ default:+ blueslip.error(+ "Invalid popover placement value for hotspot '" +hotspot.name + "'",- );- break;+ );+ break;}// position arrowdiff --git a/static/js/message_edit.js b/static/js/message_edit.jsindex 769c45842d1..dcd070bb07e 100644--- a/static/js/message_edit.js+++ b/static/js/message_edit.js@@ -169,42 +169,42 @@ exports.end_if_focused_on_message_row_edit = function () {function handle_message_row_edit_keydown(e) {const code = e.keyCode || e.which;switch (code) {- case 13:- if ($(e.target).hasClass("message_edit_content")) {+ case 13:+ if ($(e.target).hasClass("message_edit_content")) {// Pressing enter to save edits is coupled with enter to send- if (composebox_typeahead.should_enter_send(e)) {- const row = $(".message_edit_content").filter(":focus").closest(".message_row");- const message_edit_save_button = row.find(".message_edit_save");- if (message_edit_save_button.attr("disabled") === "disabled") {+ if (composebox_typeahead.should_enter_send(e)) {+ const row = $(".message_edit_content").filter(":focus").closest(".message_row");+ const message_edit_save_button = row.find(".message_edit_save");+ if (message_edit_save_button.attr("disabled") === "disabled") {// In cases when the save button is disabled// we need to disable save on pressing enter// Prevent default to avoid new-line on pressing// enter inside the textarea in this case+ e.preventDefault();+ return;+ }+ exports.save_message_row_edit(row);+ e.stopPropagation();e.preventDefault();+ } else {+ composebox_typeahead.handle_enter($(e.target), e);return;}+ } else if ($(e.target).hasClass("message_edit_topic") ||+ $(e.target).hasClass("message_edit_topic_propagate")) {+ const row = $(e.target).closest(".message_row");exports.save_message_row_edit(row);e.stopPropagation();e.preventDefault();- } else {- composebox_typeahead.handle_enter($(e.target), e);- return;}- } else if ($(e.target).hasClass("message_edit_topic") ||- $(e.target).hasClass("message_edit_topic_propagate")) {- const row = $(e.target).closest(".message_row");- exports.save_message_row_edit(row);+ return;+ case 27: // Handle escape keys in the message_edit form.+ exports.end_if_focused_on_message_row_edit();e.stopPropagation();e.preventDefault();- }- return;- case 27: // Handle escape keys in the message_edit form.- exports.end_if_focused_on_message_row_edit();- e.stopPropagation();- e.preventDefault();- return;- default:- return;+ return;+ default:+ return;}}@@ -212,19 +212,19 @@ function handle_inline_topic_edit_keydown(e) {let row;const code = e.keyCode || e.which;switch (code) {- case 13: // Handle enter key in the recipient bar/inline topic edit form- row = $(e.target).closest(".recipient_row");- exports.save_inline_topic_edit(row);- e.stopPropagation();- e.preventDefault();- return;- case 27: // handle escape- exports.end_if_focused_on_inline_topic_edit();- e.stopPropagation();- e.preventDefault();- return;- default:- return;+ case 13: // Handle enter key in the recipient bar/inline topic edit form+ row = $(e.target).closest(".recipient_row");+ exports.save_inline_topic_edit(row);+ e.stopPropagation();+ e.preventDefault();+ return;+ case 27: // handle escape+ exports.end_if_focused_on_inline_topic_edit();+ e.stopPropagation();+ e.preventDefault();+ return;+ default:+ return;}}diff --git a/static/js/message_store.js b/static/js/message_store.jsindex 2493bc0eab5..570b0ac8137 100644--- a/static/js/message_store.js+++ b/static/js/message_store.js@@ -164,37 +164,37 @@ exports.add_message_metadata = function (message) {util.convert_message_topic(message);switch (message.type) {- case "stream":- message.is_stream = true;- message.stream = message.display_recipient;- message.reply_to = message.sender_email;-- stream_topic_history.add_message({- stream_id: message.stream_id,- topic_name: message.topic,- message_id: message.id,- });-- recent_senders.process_message_for_senders(message);- message_user_ids.add(message.sender_id);- break;-- case "private":- message.is_private = true;- message.reply_to = util.normalize_recipients(- exports.get_pm_emails(message));- message.display_reply_to = exports.get_pm_full_names(message);- message.pm_with_url = people.pm_with_url(message);- message.to_user_ids = people.pm_reply_user_string(message);-- exports.process_message_for_recent_private_messages(message);-- if (people.is_my_user_id(message.sender_id)) {- for (const recip of message.display_recipient) {- message_user_ids.add(recip.id);+ case "stream":+ message.is_stream = true;+ message.stream = message.display_recipient;+ message.reply_to = message.sender_email;++ stream_topic_history.add_message({+ stream_id: message.stream_id,+ topic_name: message.topic,+ message_id: message.id,+ });++ recent_senders.process_message_for_senders(message);+ message_user_ids.add(message.sender_id);+ break;++ case "private":+ message.is_private = true;+ message.reply_to = util.normalize_recipients(+ exports.get_pm_emails(message));+ message.display_reply_to = exports.get_pm_full_names(message);+ message.pm_with_url = people.pm_with_url(message);+ message.to_user_ids = people.pm_reply_user_string(message);++ exports.process_message_for_recent_private_messages(message);++ if (people.is_my_user_id(message.sender_id)) {+ for (const recip of message.display_recipient) {+ message_user_ids.add(recip.id);+ }}- }- break;+ break;}alert_words.process_message(message);diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 6b2c9aed9e7..0aa6ffad152 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -684,13 +684,13 @@ exports.by_recipient = function (target_id, opts) {unread_ops.notify_server_message_read(message);switch (message.type) {- case "private":- exports.by("pm-with", message.reply_to, opts);- break;+ case "private":+ exports.by("pm-with", message.reply_to, opts);+ break;- case "stream":- exports.by("stream", message.stream, opts);- break;+ case "stream":+ exports.by("stream", message.stream, opts);+ break;}};diff --git a/static/js/people.js b/static/js/people.jsindex 7397547c46d..fa8d92462f1 100644--- a/static/js/people.js+++ b/static/js/people.js@@ -1135,18 +1135,18 @@ exports.extract_people_from_message = function (message) {let involved_people;switch (message.type) {- case "stream":- involved_people = [{full_name: message.sender_full_name,- user_id: message.sender_id,- email: message.sender_email}];- break;-- case "private":- involved_people = message.display_recipient;- break;-- default:- involved_people = [];+ case "stream":+ involved_people = [{full_name: message.sender_full_name,+ user_id: message.sender_id,+ email: message.sender_email}];+ break;++ case "private":+ involved_people = message.display_recipient;+ break;++ default:+ involved_people = [];}// Add new people involved in this message to the people listdiff --git a/static/js/popovers.js b/static/js/popovers.jsindex 1feda2bb060..3de0b803c8c 100644--- a/static/js/popovers.js+++ b/static/js/popovers.js@@ -131,31 +131,31 @@ function get_custom_profile_field_data(user, field, field_types, dateFormat) {profile_field.type = field_type;switch (field_type) {- case field_types.DATE.id:- profile_field.value = moment(field_value.value).format(dateFormat);- break;- case field_types.USER.id:- profile_field.id = field.id;- profile_field.is_user_field = true;- profile_field.value = field_value.value;- break;- case field_types.CHOICE.id: {- const field_choice_dict = JSON.parse(field.field_data);- profile_field.value = field_choice_dict[field_value.value].text;- break;- }- case field_types.SHORT_TEXT.id:- case field_types.LONG_TEXT.id:- profile_field.value = field_value.value;- profile_field.rendered_value = field_value.rendered_value;- break;- case field_types.EXTERNAL_ACCOUNT.id:- profile_field.value = field_value.value;- profile_field.field_data = JSON.parse(field.field_data);- profile_field.link = settings_profile_fields.get_external_account_link(profile_field);- break;- default:- profile_field.value = field_value.value;+ case field_types.DATE.id:+ profile_field.value = moment(field_value.value).format(dateFormat);+ break;+ case field_types.USER.id:+ profile_field.id = field.id;+ profile_field.is_user_field = true;+ profile_field.value = field_value.value;+ break;+ case field_types.CHOICE.id: {+ const field_choice_dict = JSON.parse(field.field_data);+ profile_field.value = field_choice_dict[field_value.value].text;+ break;+ }+ case field_types.SHORT_TEXT.id:+ case field_types.LONG_TEXT.id:+ profile_field.value = field_value.value;+ profile_field.rendered_value = field_value.rendered_value;+ break;+ case field_types.EXTERNAL_ACCOUNT.id:+ profile_field.value = field_value.value;+ profile_field.field_data = JSON.parse(field.field_data);+ profile_field.link = settings_profile_fields.get_external_account_link(profile_field);+ break;+ default:+ profile_field.value = field_value.value;}return profile_field;}diff --git a/static/js/portico/integrations.js b/static/js/portico/integrations.jsindex f4fee4fc9d9..003cdd81a06 100644--- a/static/js/portico/integrations.js+++ b/static/js/portico/integrations.js@@ -269,49 +269,49 @@ function render(next_state) {function dispatch(action, payload) {switch (action) {- case "CHANGE_CATEGORY":- render(Object.assign({}, state, {- category: payload.category,- }));- update_path();- break;-- case "SHOW_INTEGRATION":- render(Object.assign({}, state, {- integration: payload.integration,- }));- update_path();- break;-- case "HIDE_INTEGRATION":- render(Object.assign({}, state, {- integration: null,- }));- update_path();- break;-- case "SHOW_CATEGORY":- render(Object.assign({}, state, {- integration: null,- category: payload.category,- }));- update_path();- break;-- case "UPDATE_QUERY":- render(Object.assign({}, state, {- query: payload.query,- }));- break;-- case "LOAD_PATH":- render(get_state_from_path());- google_analytics.config({page_path: window.location.pathname});- break;-- default:- blueslip.error("Invalid action dispatched on /integrations.");- break;+ case "CHANGE_CATEGORY":+ render(Object.assign({}, state, {+ category: payload.category,+ }));+ update_path();+ break;++ case "SHOW_INTEGRATION":+ render(Object.assign({}, state, {+ integration: payload.integration,+ }));+ update_path();+ break;++ case "HIDE_INTEGRATION":+ render(Object.assign({}, state, {+ integration: null,+ }));+ update_path();+ break;++ case "SHOW_CATEGORY":+ render(Object.assign({}, state, {+ integration: null,+ category: payload.category,+ }));+ update_path();+ break;++ case "UPDATE_QUERY":+ render(Object.assign({}, state, {+ query: payload.query,+ }));+ break;++ case "LOAD_PATH":+ render(get_state_from_path());+ google_analytics.config({page_path: window.location.pathname});+ break;++ default:+ blueslip.error("Invalid action dispatched on /integrations.");+ break;}}diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex edb7e21449c..593ceff0829 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -488,73 +488,73 @@ exports.change_focused_element = function (e, input_key) {}switch (input_key) {- case "left_arrow":- if (start !== 0 || is_selected) {- return false;- }- current_focus_elem = filter_buttons().last();- break;- case "right_arrow":- if (end !== text_length || is_selected) {- return false;- }- current_focus_elem = filter_buttons().first();- break;- case "down_arrow":- set_table_focus(row_focus, col_focus);- return true;- case "click":+ case "left_arrow":+ if (start !== 0 || is_selected) {+ return false;+ }+ current_focus_elem = filter_buttons().last();+ break;+ case "right_arrow":+ if (end !== text_length || is_selected) {+ return false;+ }+ current_focus_elem = filter_buttons().first();+ break;+ case "down_arrow":+ set_table_focus(row_focus, col_focus);+ return true;+ case "click":// Note: current_focus_elem can be different here, so we just// set current_focus_elem to the input box, we don't want .focus() on// it since it is already focused.// We only do this for search beacuse we don't want the focus to// go away from the input box when `revive_current_focus` is called// on rerender when user is typing.- current_focus_elem = $("#recent_topics_search");- return true;+ current_focus_elem = $("#recent_topics_search");+ return true;}} else if ($elem.hasClass("btn-recent-filters")) {switch (input_key) {- case "left_arrow":- if (filter_buttons().first()[0] === $elem[0]) {- current_focus_elem = $("#recent_topics_search");- } else {- current_focus_elem = $elem.prev();- }- break;- case "right_arrow":- if (filter_buttons().last()[0] === $elem[0]) {- current_focus_elem = $("#recent_topics_search");- } else {- current_focus_elem = $elem.next();- }- break;- case "down_arrow":- set_table_focus(row_focus, col_focus);- return true;+ case "left_arrow":+ if (filter_buttons().first()[0] === $elem[0]) {+ current_focus_elem = $("#recent_topics_search");+ } else {+ current_focus_elem = $elem.prev();+ }+ break;+ case "right_arrow":+ if (filter_buttons().last()[0] === $elem[0]) {+ current_focus_elem = $("#recent_topics_search");+ } else {+ current_focus_elem = $elem.next();+ }+ break;+ case "down_arrow":+ set_table_focus(row_focus, col_focus);+ return true;}} else if (current_focus_elem === "table") {// For arrowing around the table of topics, we implement left/right// wraparound. Going off the top or the bottom takes one// to the navigation at the top (see set_table_focus).switch (input_key) {- case "left_arrow":- col_focus -= 1;- if (col_focus < 0) {- col_focus = MAX_SELECTABLE_COLS - 1;- }- break;- case "right_arrow":- col_focus += 1;- if (col_focus >= MAX_SELECTABLE_COLS) {- col_focus = 0;- }- break;- case "down_arrow":- row_focus += 1;- break;- case "up_arrow":- row_focus -= 1;+ case "left_arrow":+ col_focus -= 1;+ if (col_focus < 0) {+ col_focus = MAX_SELECTABLE_COLS - 1;+ }+ break;+ case "right_arrow":+ col_focus += 1;+ if (col_focus >= MAX_SELECTABLE_COLS) {+ col_focus = 0;+ }+ break;+ case "down_arrow":+ row_focus += 1;+ break;+ case "up_arrow":+ row_focus -= 1;}set_table_focus(row_focus, col_focus);return true;diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.jsindex 3aae2db2f0e..155d468d5d2 100644--- a/static/js/search_suggestion.js+++ b/static/js/search_suggestion.js@@ -302,21 +302,21 @@ function get_topic_suggestions(last, operators) {// in terms of telling us whether they provided the operator,// i.e. "foo" and "search:foo" both become [{operator: 'search', operand: 'foo'}].switch (operator) {- case "stream":- guess = "";- stream = operand;- suggest_operators.push(last);- break;- case "topic":- case "search":- guess = operand;- if (filter.has_operator("stream")) {- stream = filter.operands("stream")[0];- } else {- stream = narrow_state.stream();- suggest_operators.push({operator: "stream", operand: stream});- }- break;+ case "stream":+ guess = "";+ stream = operand;+ suggest_operators.push(last);+ break;+ case "topic":+ case "search":+ guess = operand;+ if (filter.has_operator("stream")) {+ stream = filter.operands("stream")[0];+ } else {+ stream = narrow_state.stream();+ suggest_operators.push({operator: "stream", operand: stream});+ }+ break;}if (!stream) {diff --git a/static/js/server_events.js b/static/js/server_events.jsindex 071cf97e39c..7d4fa526024 100644--- a/static/js/server_events.js+++ b/static/js/server_events.js@@ -52,29 +52,29 @@ function get_events_success(events) {// rarely modified logic for non-normal events.const dispatch_event = function dispatch_event(event) {switch (event.type) {- case "message": {- const msg = event.message;- msg.flags = event.flags;- if (event.local_message_id) {- msg.local_id = event.local_message_id;- sent_messages.report_event_received(event.local_message_id);+ case "message": {+ const msg = event.message;+ msg.flags = event.flags;+ if (event.local_message_id) {+ msg.local_id = event.local_message_id;+ sent_messages.report_event_received(event.local_message_id);+ }+ messages.push(msg);+ break;}- messages.push(msg);- break;- }- case "update_message":- update_message_events.push(event);- break;+ case "update_message":+ update_message_events.push(event);+ break;- case "delete_message":- case "submessage":- case "update_message_flags":- post_message_events.push(event);- break;+ case "delete_message":+ case "submessage":+ case "update_message_flags":+ post_message_events.push(event);+ break;- default:- return server_events_dispatch.dispatch_normal_event(event);+ default:+ return server_events_dispatch.dispatch_normal_event(event);}};diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex 77391a5e969..173e86c5306 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -3,548 +3,548 @@ const settings_config = require("./settings_config");exports.dispatch_normal_event = function dispatch_normal_event(event) {const noop = function () {};switch (event.type) {- case "alert_words":- alert_words.set_words(event.alert_words);- alert_words_ui.render_alert_words_ui();- break;-- case "attachment":- attachments_ui.update_attachments(event);- break;-- case "custom_profile_fields":- page_params.custom_profile_fields = event.fields;- settings_profile_fields.populate_profile_fields(page_params.custom_profile_fields);- settings_account.add_custom_profile_fields_to_settings();- break;-- case "default_streams":- stream_data.set_realm_default_streams(event.default_streams);- settings_streams.update_default_streams_table();- break;-- case "delete_message": {- const msg_ids = event.message_ids;- // message is passed to unread.get_unread_messages,- // which returns all the unread messages out of a given list.- // So double marking something as read would not occur- unread_ops.process_read_messages_event(msg_ids);-- if (event.message_type === "stream") {- stream_topic_history.remove_messages({- stream_id: event.stream_id,- topic_name: event.topic,- num_messages: msg_ids.length,- });- stream_list.update_streams_sidebar();- }+ case "alert_words":+ alert_words.set_words(event.alert_words);+ alert_words_ui.render_alert_words_ui();+ break;- ui.remove_messages(msg_ids);- break;- }+ case "attachment":+ attachments_ui.update_attachments(event);+ break;++ case "custom_profile_fields":+ page_params.custom_profile_fields = event.fields;+ settings_profile_fields.populate_profile_fields(page_params.custom_profile_fields);+ settings_account.add_custom_profile_fields_to_settings();+ break;++ case "default_streams":+ stream_data.set_realm_default_streams(event.default_streams);+ settings_streams.update_default_streams_table();+ break;- case "has_zoom_token":- page_params.has_zoom_token = event.value;- if (event.value) {- for (const callback of compose.zoom_token_callbacks.values()) {- callback();+ case "delete_message": {+ const msg_ids = event.message_ids;+ // message is passed to unread.get_unread_messages,+ // which returns all the unread messages out of a given list.+ // So double marking something as read would not occur+ unread_ops.process_read_messages_event(msg_ids);++ if (event.message_type === "stream") {+ stream_topic_history.remove_messages({+ stream_id: event.stream_id,+ topic_name: event.topic,+ num_messages: msg_ids.length,+ });+ stream_list.update_streams_sidebar();}- compose.zoom_token_callbacks.clear();- }- break;-- case "hotspots":- hotspots.load_new(event.hotspots);- page_params.hotspots = page_params.hotspots ?- page_params.hotspots.concat(event.hotspots) :- event.hotspots;- break;-- case "invites_changed":- if ($("#admin-invites-list").length) {- settings_invites.set_up(false);- }- break;-- case "muted_topics":- muting_ui.handle_updates(event.muted_topics);- break;-- case "presence":- activity.update_presence_info(event.user_id, event.presence, event.server_timestamp);- break;-- case "restart": {- const reload_options = {- save_pointer: true,- save_narrow: true,- save_compose: true,- message: "The application has been updated; reloading!",- };- if (event.immediate) {- reload_options.immediate = true;++ ui.remove_messages(msg_ids);+ break;}- reload.initiate(reload_options);- break;- }- case "reaction":- if (event.op === "add") {- reactions.add_reaction(event);- } else if (event.op === "remove") {- reactions.remove_reaction(event);+ case "has_zoom_token":+ page_params.has_zoom_token = event.value;+ if (event.value) {+ for (const callback of compose.zoom_token_callbacks.values()) {+ callback();+ }+ compose.zoom_token_callbacks.clear();+ }+ break;++ case "hotspots":+ hotspots.load_new(event.hotspots);+ page_params.hotspots = page_params.hotspots ?+ page_params.hotspots.concat(event.hotspots) :+ event.hotspots;+ break;++ case "invites_changed":+ if ($("#admin-invites-list").length) {+ settings_invites.set_up(false);+ }+ break;++ case "muted_topics":+ muting_ui.handle_updates(event.muted_topics);+ break;++ case "presence":+ activity.update_presence_info(event.user_id, event.presence, event.server_timestamp);+ break;++ case "restart": {+ const reload_options = {+ save_pointer: true,+ save_narrow: true,+ save_compose: true,+ message: "The application has been updated; reloading!",+ };+ if (event.immediate) {+ reload_options.immediate = true;+ }+ reload.initiate(reload_options);+ break;}- break;-- case "realm": {- const realm_settings = {- add_emoji_by_admins_only: settings_emoji.update_custom_emoji_ui,- allow_edit_history: noop,- allow_message_deleting: noop,- allow_message_editing: noop,- allow_community_topic_editing: noop,- user_group_edit_policy: noop,- avatar_changes_disabled: settings_account.update_avatar_change_display,- bot_creation_policy: settings_bots.update_bot_permissions_ui,- create_stream_policy: noop,- invite_to_stream_policy: noop,- default_code_block_language: noop,- default_language: noop,- default_twenty_four_hour_time: noop,- description: noop,- digest_emails_enabled: noop,- digest_weekday: noop,- email_address_visibility: noop,- email_changes_disabled: settings_account.update_email_change_display,- disallow_disposable_email_addresses: noop,- inline_image_preview: noop,- inline_url_embed_preview: noop,- invite_by_admins_only: noop,- invite_required: noop,- mandatory_topics: noop,- message_content_edit_limit_seconds: noop,- message_content_delete_limit_seconds: noop,- message_retention_days: noop,- name: notifications.redraw_title,- name_changes_disabled: settings_account.update_name_change_display,- notifications_stream_id: noop,- private_message_policy: noop,- send_welcome_emails: noop,- message_content_allowed_in_email_notifications: noop,- signup_notifications_stream_id: noop,- emails_restricted_to_domains: noop,- video_chat_provider: compose.update_video_chat_button_display,- waiting_period_threshold: noop,- };- if (event.op === "update" && Object.prototype.hasOwnProperty.call(realm_settings, event.property)) {- page_params["realm_" + event.property] = event.value;- realm_settings[event.property]();- settings_org.sync_realm_settings(event.property);- if (event.property === "create_stream_policy") {++ case "reaction":+ if (event.op === "add") {+ reactions.add_reaction(event);+ } else if (event.op === "remove") {+ reactions.remove_reaction(event);+ }+ break;++ case "realm": {+ const realm_settings = {+ add_emoji_by_admins_only: settings_emoji.update_custom_emoji_ui,+ allow_edit_history: noop,+ allow_message_deleting: noop,+ allow_message_editing: noop,+ allow_community_topic_editing: noop,+ user_group_edit_policy: noop,+ avatar_changes_disabled: settings_account.update_avatar_change_display,+ bot_creation_policy: settings_bots.update_bot_permissions_ui,+ create_stream_policy: noop,+ invite_to_stream_policy: noop,+ default_code_block_language: noop,+ default_language: noop,+ default_twenty_four_hour_time: noop,+ description: noop,+ digest_emails_enabled: noop,+ digest_weekday: noop,+ email_address_visibility: noop,+ email_changes_disabled: settings_account.update_email_change_display,+ disallow_disposable_email_addresses: noop,+ inline_image_preview: noop,+ inline_url_embed_preview: noop,+ invite_by_admins_only: noop,+ invite_required: noop,+ mandatory_topics: noop,+ message_content_edit_limit_seconds: noop,+ message_content_delete_limit_seconds: noop,+ message_retention_days: noop,+ name: notifications.redraw_title,+ name_changes_disabled: settings_account.update_name_change_display,+ notifications_stream_id: noop,+ private_message_policy: noop,+ send_welcome_emails: noop,+ message_content_allowed_in_email_notifications: noop,+ signup_notifications_stream_id: noop,+ emails_restricted_to_domains: noop,+ video_chat_provider: compose.update_video_chat_button_display,+ waiting_period_threshold: noop,+ };+ if (event.op === "update" && Object.prototype.hasOwnProperty.call(realm_settings, event.property)) {+ page_params["realm_" + event.property] = event.value;+ realm_settings[event.property]();+ settings_org.sync_realm_settings(event.property);+ if (event.property === "create_stream_policy") {// TODO: Add waiting_period_threshold logic here.- page_params.can_create_streams = page_params.is_admin ||+ page_params.can_create_streams = page_params.is_admin ||page_params.realm_create_stream_policy === 1;- } else if (event.property === "invite_to_stream_policy") {+ } else if (event.property === "invite_to_stream_policy") {// TODO: Add waiting_period_threshold logic here.- page_params.can_invite_to_stream = page_params.is_admin ||+ page_params.can_invite_to_stream = page_params.is_admin ||page_params.realm_invite_to_stream_policy === 1;- }+ }- if (event.property === "name" && window.electron_bridge !== undefined) {- window.electron_bridge.send_event("realm_name", event.value);- }- } else if (event.op === "update_dict" && event.property === "default") {- for (const [key, value] of Object.entries(event.data)) {- page_params["realm_" + key] = value;- if (key === "allow_message_editing") {- message_edit.update_message_topic_editing_pencil();+ if (event.property === "name" && window.electron_bridge !== undefined) {+ window.electron_bridge.send_event("realm_name", event.value);}- if (Object.prototype.hasOwnProperty.call(realm_settings, key)) {- settings_org.sync_realm_settings(key);+ } else if (event.op === "update_dict" && event.property === "default") {+ for (const [key, value] of Object.entries(event.data)) {+ page_params["realm_" + key] = value;+ if (key === "allow_message_editing") {+ message_edit.update_message_topic_editing_pencil();+ }+ if (Object.prototype.hasOwnProperty.call(realm_settings, key)) {+ settings_org.sync_realm_settings(key);+ }}+ if (event.data.authentication_methods !== undefined) {+ settings_org.populate_auth_methods(event.data.authentication_methods);+ }+ } else if (event.op === "update_dict" && event.property === "icon") {+ page_params.realm_icon_url = event.data.icon_url;+ page_params.realm_icon_source = event.data.icon_source;+ realm_icon.rerender();++ const electron_bridge = window.electron_bridge;+ if (electron_bridge !== undefined) {+ electron_bridge.send_event("realm_icon_url", event.data.icon_url);+ }+ } else if (event.op === "update_dict" && event.property === "logo") {+ page_params.realm_logo_url = event.data.logo_url;+ page_params.realm_logo_source = event.data.logo_source;+ realm_logo.rerender();+ } else if (event.op === "update_dict" && event.property === "night_logo") {+ page_params.realm_night_logo_url = event.data.night_logo_url;+ page_params.realm_night_logo_source = event.data.night_logo_source;+ realm_logo.rerender();+ } else if (event.op === "deactivated") {+ window.location.href = "/accounts/deactivated/";}- if (event.data.authentication_methods !== undefined) {- settings_org.populate_auth_methods(event.data.authentication_methods);- }- } else if (event.op === "update_dict" && event.property === "icon") {- page_params.realm_icon_url = event.data.icon_url;- page_params.realm_icon_source = event.data.icon_source;- realm_icon.rerender();-- const electron_bridge = window.electron_bridge;- if (electron_bridge !== undefined) {- electron_bridge.send_event("realm_icon_url", event.data.icon_url);- }- } else if (event.op === "update_dict" && event.property === "logo") {- page_params.realm_logo_url = event.data.logo_url;- page_params.realm_logo_source = event.data.logo_source;- realm_logo.rerender();- } else if (event.op === "update_dict" && event.property === "night_logo") {- page_params.realm_night_logo_url = event.data.night_logo_url;- page_params.realm_night_logo_source = event.data.night_logo_source;- realm_logo.rerender();- } else if (event.op === "deactivated") {- window.location.href = "/accounts/deactivated/";- }- if (page_params.is_admin) {+ if (page_params.is_admin) {// Update the UI notice about the user's profile being// incomplete, as we might have filled in the missing field(s).- panels.check_profile_incomplete();+ panels.check_profile_incomplete();+ }+ break;}- break;- }- case "realm_bot":- if (event.op === "add") {- bot_data.add(event.bot);- } else if (event.op === "remove") {- bot_data.deactivate(event.bot.user_id);- event.bot.is_active = false;- } else if (event.op === "delete") {- blueslip.info("ignoring bot deletion for live UI update");+ case "realm_bot":+ if (event.op === "add") {+ bot_data.add(event.bot);+ } else if (event.op === "remove") {+ bot_data.deactivate(event.bot.user_id);+ event.bot.is_active = false;+ } else if (event.op === "delete") {+ blueslip.info("ignoring bot deletion for live UI update");+ break;+ } else if (event.op === "update") {+ bot_data.update(event.bot.user_id, event.bot);+ }+ settings_users.update_bot_data(event.bot.user_id);break;- } else if (event.op === "update") {- bot_data.update(event.bot.user_id, event.bot);- }- settings_users.update_bot_data(event.bot.user_id);- break;- case "realm_emoji":+ case "realm_emoji":// Update `page_params.realm_emoji` so that settings page// can display it properly when reopened without refresh.- page_params.realm_emoji = event.realm_emoji;- emoji.update_emojis(event.realm_emoji);- settings_emoji.populate_emoji(event.realm_emoji);- emoji_picker.generate_emoji_picker_data(emoji.active_realm_emojis);- composebox_typeahead.update_emoji_data();- break;-- case "realm_filters":- page_params.realm_filters = event.realm_filters;- markdown.update_realm_filter_rules(page_params.realm_filters);- settings_linkifiers.populate_filters(page_params.realm_filters);- break;-- case "realm_domains": {- let i;- if (event.op === "add") {- page_params.realm_domains.push(event.realm_domain);- } else if (event.op === "change") {- for (i = 0; i < page_params.realm_domains.length; i += 1) {- if (page_params.realm_domains[i].domain === event.realm_domain.domain) {- page_params.realm_domains[i].allow_subdomains =+ page_params.realm_emoji = event.realm_emoji;+ emoji.update_emojis(event.realm_emoji);+ settings_emoji.populate_emoji(event.realm_emoji);+ emoji_picker.generate_emoji_picker_data(emoji.active_realm_emojis);+ composebox_typeahead.update_emoji_data();+ break;++ case "realm_filters":+ page_params.realm_filters = event.realm_filters;+ markdown.update_realm_filter_rules(page_params.realm_filters);+ settings_linkifiers.populate_filters(page_params.realm_filters);+ break;++ case "realm_domains": {+ let i;+ if (event.op === "add") {+ page_params.realm_domains.push(event.realm_domain);+ } else if (event.op === "change") {+ for (i = 0; i < page_params.realm_domains.length; i += 1) {+ if (page_params.realm_domains[i].domain === event.realm_domain.domain) {+ page_params.realm_domains[i].allow_subdomains =event.realm_domain.allow_subdomains;- break;+ break;+ }}- }- } else if (event.op === "remove") {- for (i = 0; i < page_params.realm_domains.length; i += 1) {- if (page_params.realm_domains[i].domain === event.domain) {- page_params.realm_domains.splice(i, 1);- break;+ } else if (event.op === "remove") {+ for (i = 0; i < page_params.realm_domains.length; i += 1) {+ if (page_params.realm_domains[i].domain === event.domain) {+ page_params.realm_domains.splice(i, 1);+ break;+ }}}+ settings_org.populate_realm_domains(page_params.realm_domains);+ break;}- settings_org.populate_realm_domains(page_params.realm_domains);- break;- }- case "realm_user":- if (event.op === "add") {- people.add_active_user(event.person);- } else if (event.op === "remove") {- people.deactivate(event.person);- stream_events.remove_deactivated_user_from_all_streams(event.person.user_id);- } else if (event.op === "update") {- user_events.update_person(event.person);- }- break;+ case "realm_user":+ if (event.op === "add") {+ people.add_active_user(event.person);+ } else if (event.op === "remove") {+ people.deactivate(event.person);+ stream_events.remove_deactivated_user_from_all_streams(event.person.user_id);+ } else if (event.op === "update") {+ user_events.update_person(event.person);+ }+ break;- case "stream":- if (event.op === "update") {+ case "stream":+ if (event.op === "update") {// Legacy: Stream properties are still managed by subs.js on the client side.- stream_events.update_property(- event.stream_id,- event.property,- event.value,- {- rendered_description: event.rendered_description,- history_public_to_subscribers: event.history_public_to_subscribers,- });- settings_streams.update_default_streams_table();- } else if (event.op === "create") {- stream_data.create_streams(event.streams);-- for (const stream of event.streams) {- const sub = stream_data.get_sub_by_id(stream.stream_id);- stream_data.update_calculated_fields(sub);- if (overlays.streams_open()) {- subs.add_sub_to_table(sub);- }- }- } else if (event.op === "delete") {- for (const stream of event.streams) {- const was_subscribed = stream_data.get_sub_by_id(stream.stream_id).subscribed;- subs.remove_stream(stream.stream_id);- stream_data.delete_sub(stream.stream_id);- if (was_subscribed) {- stream_list.remove_sidebar_row(stream.stream_id);- }+ stream_events.update_property(+ event.stream_id,+ event.property,+ event.value,+ {+ rendered_description: event.rendered_description,+ history_public_to_subscribers: event.history_public_to_subscribers,+ });settings_streams.update_default_streams_table();- stream_data.remove_default_stream(stream.stream_id);- if (page_params.realm_notifications_stream_id === stream.stream_id) {- page_params.realm_notifications_stream_id = -1;- settings_org.sync_realm_settings("notifications_stream_id");+ } else if (event.op === "create") {+ stream_data.create_streams(event.streams);++ for (const stream of event.streams) {+ const sub = stream_data.get_sub_by_id(stream.stream_id);+ stream_data.update_calculated_fields(sub);+ if (overlays.streams_open()) {+ subs.add_sub_to_table(sub);+ }}- if (page_params.realm_signup_notifications_stream_id === stream.stream_id) {- page_params.realm_signup_notifications_stream_id = -1;- settings_org.sync_realm_settings("signup_notifications_stream_id");+ } else if (event.op === "delete") {+ for (const stream of event.streams) {+ const was_subscribed = stream_data.get_sub_by_id(stream.stream_id).subscribed;+ subs.remove_stream(stream.stream_id);+ stream_data.delete_sub(stream.stream_id);+ if (was_subscribed) {+ stream_list.remove_sidebar_row(stream.stream_id);+ }+ settings_streams.update_default_streams_table();+ stream_data.remove_default_stream(stream.stream_id);+ if (page_params.realm_notifications_stream_id === stream.stream_id) {+ page_params.realm_notifications_stream_id = -1;+ settings_org.sync_realm_settings("notifications_stream_id");+ }+ if (page_params.realm_signup_notifications_stream_id === stream.stream_id) {+ page_params.realm_signup_notifications_stream_id = -1;+ settings_org.sync_realm_settings("signup_notifications_stream_id");+ }}}- }- break;+ break;- case "submessage": {+ case "submessage": {// The fields in the event don't quite exactly// match the layout of a submessage, since there's// an event id. We also want to be explicit here.- const submsg = {- id: event.submessage_id,- sender_id: event.sender_id,- msg_type: event.msg_type,- message_id: event.message_id,- content: event.content,- };- submessage.handle_event(submsg);- break;- }+ const submsg = {+ id: event.submessage_id,+ sender_id: event.sender_id,+ msg_type: event.msg_type,+ message_id: event.message_id,+ content: event.content,+ };+ submessage.handle_event(submsg);+ break;+ }- case "subscription":- if (event.op === "add") {- for (const rec of event.subscriptions) {- const sub = stream_data.get_sub_by_id(rec.stream_id);- if (sub) {- stream_data.update_stream_email_address(sub, rec.email_address);- stream_events.mark_subscribed(sub, rec.subscribers, rec.color);- } else {- blueslip.error("Subscribing to unknown stream with ID " + rec.stream_id);+ case "subscription":+ if (event.op === "add") {+ for (const rec of event.subscriptions) {+ const sub = stream_data.get_sub_by_id(rec.stream_id);+ if (sub) {+ stream_data.update_stream_email_address(sub, rec.email_address);+ stream_events.mark_subscribed(sub, rec.subscribers, rec.color);+ } else {+ blueslip.error("Subscribing to unknown stream with ID " + rec.stream_id);+ }}- }- } else if (event.op === "peer_add") {- function add_peer(stream_id, user_id) {- const sub = stream_data.get_sub_by_id(stream_id);-- if (!sub) {- blueslip.warn("Cannot find stream for peer_add: " + stream_id);- return;+ } else if (event.op === "peer_add") {+ function add_peer(stream_id, user_id) {+ const sub = stream_data.get_sub_by_id(stream_id);++ if (!sub) {+ blueslip.warn("Cannot find stream for peer_add: " + stream_id);+ return;+ }++ if (!stream_data.add_subscriber(stream_id, user_id)) {+ blueslip.warn("Cannot process peer_add event");+ return;+ }++ subs.update_subscribers_ui(sub);+ compose_fade.update_faded_users();}-- if (!stream_data.add_subscriber(stream_id, user_id)) {- blueslip.warn("Cannot process peer_add event");- return;+ add_peer(event.stream_id, event.user_id);+ } else if (event.op === "peer_remove") {+ function remove_peer(stream_id, user_id) {+ const sub = stream_data.get_sub_by_id(stream_id);++ if (!sub) {+ blueslip.warn("Cannot find stream for peer_remove: " + stream_id);+ return;+ }++ if (!stream_data.remove_subscriber(sub.stream_id, user_id)) {+ blueslip.warn("Cannot process peer_remove event.");+ return;+ }++ subs.update_subscribers_ui(sub);+ compose_fade.update_faded_users();}-- subs.update_subscribers_ui(sub);- compose_fade.update_faded_users();- }- add_peer(event.stream_id, event.user_id);- } else if (event.op === "peer_remove") {- function remove_peer(stream_id, user_id) {- const sub = stream_data.get_sub_by_id(stream_id);-- if (!sub) {- blueslip.warn("Cannot find stream for peer_remove: " + stream_id);- return;+ remove_peer(event.stream_id, event.user_id);+ } else if (event.op === "remove") {+ for (const rec of event.subscriptions) {+ const sub = stream_data.get_sub_by_id(rec.stream_id);+ stream_events.mark_unsubscribed(sub);}-- if (!stream_data.remove_subscriber(sub.stream_id, user_id)) {- blueslip.warn("Cannot process peer_remove event.");- return;- }-- subs.update_subscribers_ui(sub);- compose_fade.update_faded_users();+ } else if (event.op === "update") {+ stream_events.update_property(+ event.stream_id,+ event.property,+ event.value,+ );}- remove_peer(event.stream_id, event.user_id);- } else if (event.op === "remove") {- for (const rec of event.subscriptions) {- const sub = stream_data.get_sub_by_id(rec.stream_id);- stream_events.mark_unsubscribed(sub);- }- } else if (event.op === "update") {- stream_events.update_property(- event.stream_id,- event.property,- event.value,- );- }- break;+ break;- case "typing":- if (event.sender.user_id === page_params.user_id) {+ case "typing":+ if (event.sender.user_id === page_params.user_id) {// typing notifications are sent to the user who is typing// as well as recipients; we ignore such self-generated events.- return;- }+ return;+ }- if (event.op === "start") {- typing_events.display_notification(event);- } else if (event.op === "stop") {- typing_events.hide_notification(event);- }- break;-- case "update_display_settings": {- const user_display_settings = [- "color_scheme",- "default_language",- "demote_inactive_streams",- "dense_mode",- "emojiset",- "fluid_layout_width",- "high_contrast_mode",- "left_side_userlist",- "timezone",- "twenty_four_hour_time",- "translate_emoticons",- "starred_message_counts",- ];- if (user_display_settings.includes(event.setting_name)) {- page_params[event.setting_name] = event.setting;- }- if (event.setting_name === "default_language") {+ if (event.op === "start") {+ typing_events.display_notification(event);+ } else if (event.op === "stop") {+ typing_events.hide_notification(event);+ }+ break;++ case "update_display_settings": {+ const user_display_settings = [+ "color_scheme",+ "default_language",+ "demote_inactive_streams",+ "dense_mode",+ "emojiset",+ "fluid_layout_width",+ "high_contrast_mode",+ "left_side_userlist",+ "timezone",+ "twenty_four_hour_time",+ "translate_emoticons",+ "starred_message_counts",+ ];+ if (user_display_settings.includes(event.setting_name)) {+ page_params[event.setting_name] = event.setting;+ }+ if (event.setting_name === "default_language") {// We additionally need to set the language name.- page_params.default_language_name = event.language_name;- }- if (event.setting_name === "twenty_four_hour_time") {- // Rerender the whole message list UI- home_msg_list.rerender();- if (current_msg_list === message_list.narrowed) {- message_list.narrowed.rerender();+ page_params.default_language_name = event.language_name;}- }- if (event.setting_name === "high_contrast_mode") {- $("body").toggleClass("high-contrast");- }- if (event.setting_name === "demote_inactive_streams") {- stream_list.update_streams_sidebar();- stream_data.set_filter_out_inactives();- }- if (event.setting_name === "dense_mode") {- $("body").toggleClass("less_dense_mode");- $("body").toggleClass("more_dense_mode");- }- if (event.setting_name === "color_scheme") {- $("body").fadeOut(300);- setTimeout(() => {- if (event.setting === settings_config.color_scheme_values.night.code) {- night_mode.enable();- realm_logo.rerender();- } else if (event.setting === settings_config.color_scheme_values.day.code) {- night_mode.disable();- realm_logo.rerender();- } else {- night_mode.default_preference_checker();- realm_logo.rerender();+ if (event.setting_name === "twenty_four_hour_time") {+ // Rerender the whole message list UI+ home_msg_list.rerender();+ if (current_msg_list === message_list.narrowed) {+ message_list.narrowed.rerender();}- $("body").fadeIn(300);- }, 300);- }- if (event.setting_name === "starred_message_counts") {- starred_messages.rerender_ui();- }- if (event.setting_name === "fluid_layout_width") {- scroll_bar.set_layout_width();- }- if (event.setting_name === "left_side_userlist") {+ }+ if (event.setting_name === "high_contrast_mode") {+ $("body").toggleClass("high-contrast");+ }+ if (event.setting_name === "demote_inactive_streams") {+ stream_list.update_streams_sidebar();+ stream_data.set_filter_out_inactives();+ }+ if (event.setting_name === "dense_mode") {+ $("body").toggleClass("less_dense_mode");+ $("body").toggleClass("more_dense_mode");+ }+ if (event.setting_name === "color_scheme") {+ $("body").fadeOut(300);+ setTimeout(() => {+ if (event.setting === settings_config.color_scheme_values.night.code) {+ night_mode.enable();+ realm_logo.rerender();+ } else if (event.setting === settings_config.color_scheme_values.day.code) {+ night_mode.disable();+ realm_logo.rerender();+ } else {+ night_mode.default_preference_checker();+ realm_logo.rerender();+ }+ $("body").fadeIn(300);+ }, 300);+ }+ if (event.setting_name === "starred_message_counts") {+ starred_messages.rerender_ui();+ }+ if (event.setting_name === "fluid_layout_width") {+ scroll_bar.set_layout_width();+ }+ if (event.setting_name === "left_side_userlist") {// TODO: Make this change the view immediately rather// than requiring a reload or page resize.- }- if (event.setting_name === "default_language") {+ }+ if (event.setting_name === "default_language") {// TODO: Make this change the view immediately rather than// requiring a reload. This is likely fairly difficult,// because various i18n strings are rendered by the// server; we may want to instead just trigger a page// reload.- }- if (event.setting_name === "emojiset") {- settings_display.report_emojiset_change();+ }+ if (event.setting_name === "emojiset") {+ settings_display.report_emojiset_change();- // Rerender the whole message list UI- home_msg_list.rerender();- if (current_msg_list === message_list.narrowed) {- message_list.narrowed.rerender();+ // Rerender the whole message list UI+ home_msg_list.rerender();+ if (current_msg_list === message_list.narrowed) {+ message_list.narrowed.rerender();+ }}+ settings_display.update_page();+ break;}- settings_display.update_page();- break;- }- case "update_global_notifications":- notifications.handle_global_notification_updates(event.notification_name,- event.setting);- settings_notifications.update_page();- // TODO: This should also do a refresh of the stream_edit UI- // if it's currently displayed, possibly reusing some code- // from stream_events.js- // (E.g. update_stream_push_notifications).- break;-- case "update_message_flags": {- const new_value = event.operation === "add";- switch (event.flag) {- case "starred":- for (const message_id of event.messages) {- message_flags.update_starred_flag(message_id, new_value);- }+ case "update_global_notifications":+ notifications.handle_global_notification_updates(event.notification_name,+ event.setting);+ settings_notifications.update_page();+ // TODO: This should also do a refresh of the stream_edit UI+ // if it's currently displayed, possibly reusing some code+ // from stream_events.js+ // (E.g. update_stream_push_notifications).+ break;- if (event.operation === "add") {- starred_messages.add(event.messages);- } else {- starred_messages.remove(event.messages);+ case "update_message_flags": {+ const new_value = event.operation === "add";+ switch (event.flag) {+ case "starred":+ for (const message_id of event.messages) {+ message_flags.update_starred_flag(message_id, new_value);+ }++ if (event.operation === "add") {+ starred_messages.add(event.messages);+ } else {+ starred_messages.remove(event.messages);+ }+ break;+ case "read":+ unread_ops.process_read_messages_event(event.messages);+ break;}break;- case "read":- unread_ops.process_read_messages_event(event.messages);- break;}- break;- }- case "user_group":- if (event.op === "add") {- user_groups.add(event.group);- } else if (event.op === "add_members") {- user_groups.add_members(event.group_id, event.user_ids);- } else if (event.op === "remove_members") {- user_groups.remove_members(event.group_id, event.user_ids);- } else if (event.op === "update") {- user_groups.update(event);- }- settings_user_groups.reload();- break;-- case "user_status":- if (event.away !== undefined) {- if (event.away) {- activity.on_set_away(event.user_id);- } else {- activity.on_revoke_away(event.user_id);+ case "user_group":+ if (event.op === "add") {+ user_groups.add(event.group);+ } else if (event.op === "add_members") {+ user_groups.add_members(event.group_id, event.user_ids);+ } else if (event.op === "remove_members") {+ user_groups.remove_members(event.group_id, event.user_ids);+ } else if (event.op === "update") {+ user_groups.update(event);}- }+ settings_user_groups.reload();+ break;- if (event.status_text !== undefined) {- user_status.set_status_text({- user_id: event.user_id,- status_text: event.status_text,- });- activity.redraw_user(event.user_id);- }- break;- case "realm_export":- settings_exports.populate_exports_table(event.exports);- break;+ case "user_status":+ if (event.away !== undefined) {+ if (event.away) {+ activity.on_set_away(event.user_id);+ } else {+ activity.on_revoke_away(event.user_id);+ }+ }++ if (event.status_text !== undefined) {+ user_status.set_status_text({+ user_id: event.user_id,+ status_text: event.status_text,+ });+ activity.redraw_user(event.user_id);+ }+ break;+ case "realm_export":+ settings_exports.populate_exports_table(event.exports);+ break;}};diff --git a/static/js/settings_sections.js b/static/js/settings_sections.jsindex 32f511b04aa..9f729d47e82 100644--- a/static/js/settings_sections.js+++ b/static/js/settings_sections.js@@ -5,21 +5,21 @@ exports.get_group = function (section) {// Sometimes several sections all share the same code.switch (section) {- case "organization-profile":- case "organization-settings":- case "organization-permissions":- case "auth-methods":- return "org_misc";+ case "organization-profile":+ case "organization-settings":+ case "organization-permissions":+ case "auth-methods":+ return "org_misc";- case "bot-list-admin":- return "org_bots";+ case "bot-list-admin":+ return "org_bots";- case "user-list-admin":- case "deactivated-users-admin":- return "org_users";+ case "user-list-admin":+ case "deactivated-users-admin":+ return "org_users";- default:- return section;+ default:+ return section;}};diff --git a/static/js/settings_users.js b/static/js/settings_users.jsindex 1f3ab98e8c8..4c99c7e6b75 100644--- a/static/js/settings_users.js+++ b/static/js/settings_users.js@@ -118,14 +118,14 @@ function update_view_on_reactivate(row) {function get_status_field() {const current_tab = settings_panel_menu.org_settings.current_tab();switch (current_tab) {- case "deactivated-users-admin":- return $("#deactivated-user-field-status").expectOne();- case "user-list-admin":- return $("#user-field-status").expectOne();- case "bot-list-admin":- return $("#bot-field-status").expectOne();- default:- blueslip.fatal("Invalid admin settings page");+ case "deactivated-users-admin":+ return $("#deactivated-user-field-status").expectOne();+ case "user-list-admin":+ return $("#user-field-status").expectOne();+ case "bot-list-admin":+ return $("#bot-field-status").expectOne();+ default:+ blueslip.fatal("Invalid admin settings page");}}diff --git a/static/js/stream_events.js b/static/js/stream_events.jsindex 51ae135041e..730a44bc672 100644--- a/static/js/stream_events.js+++ b/static/js/stream_events.js@@ -19,48 +19,48 @@ exports.update_property = function (stream_id, property, value, other_values) {}switch (property) {- case "color":- stream_color.update_stream_color(sub, value, {update_historical: true});- break;- case "in_home_view":- stream_muting.update_is_muted(sub, !value);- break;- case "desktop_notifications":- case "audible_notifications":- case "push_notifications":- case "email_notifications":- case "wildcard_mentions_notify":- update_stream_setting(sub, value, property);- settings_notifications.update_page();- break;- case "name":- subs.update_stream_name(sub, value);- break;- case "description":- subs.update_stream_description(sub, value, other_values.rendered_description);- break;- case "email_address":- sub.email_address = value;- break;- case "pin_to_top":- update_stream_setting(sub, value, property);- stream_list.refresh_pinned_or_unpinned_stream(sub);- break;- case "invite_only":- subs.update_stream_privacy(sub, {- invite_only: value,- history_public_to_subscribers: other_values.history_public_to_subscribers,- });- break;- case "stream_post_policy":- subs.update_stream_post_policy(sub, value);- break;- case "message_retention_days":- subs.update_message_retention_setting(sub, value);- break;- default:- blueslip.warn("Unexpected subscription property type", {property: property,- value: value});+ case "color":+ stream_color.update_stream_color(sub, value, {update_historical: true});+ break;+ case "in_home_view":+ stream_muting.update_is_muted(sub, !value);+ break;+ case "desktop_notifications":+ case "audible_notifications":+ case "push_notifications":+ case "email_notifications":+ case "wildcard_mentions_notify":+ update_stream_setting(sub, value, property);+ settings_notifications.update_page();+ break;+ case "name":+ subs.update_stream_name(sub, value);+ break;+ case "description":+ subs.update_stream_description(sub, value, other_values.rendered_description);+ break;+ case "email_address":+ sub.email_address = value;+ break;+ case "pin_to_top":+ update_stream_setting(sub, value, property);+ stream_list.refresh_pinned_or_unpinned_stream(sub);+ break;+ case "invite_only":+ subs.update_stream_privacy(sub, {+ invite_only: value,+ history_public_to_subscribers: other_values.history_public_to_subscribers,+ });+ break;+ case "stream_post_policy":+ subs.update_stream_post_policy(sub, value);+ break;+ case "message_retention_days":+ subs.update_message_retention_setting(sub, value);+ break;+ default:+ blueslip.warn("Unexpected subscription property type", {property: property,+ value: value});}};diff --git a/static/js/upload.js b/static/js/upload.jsindex cf3b2b32d3e..23cca8d393a 100644--- a/static/js/upload.js+++ b/static/js/upload.js@@ -27,52 +27,52 @@ exports.get_item = function (key, config) {}if (config.mode === "compose") {switch (key) {- case "textarea":- return $("#compose-textarea");- case "send_button":- return $("#compose-send-button");- case "send_status_identifier":- return "#compose-send-status";- case "send_status":- return $("#compose-send-status");- case "send_status_close_button":- return $(".compose-send-status-close");- case "send_status_message":- return $("#compose-error-msg");- case "file_input_identifier":- return "#file_input";- case "source":- return "compose-file-input";- case "drag_drop_container":- return $("#compose");- default:- throw Error(`Invalid key name for mode "${config.mode}"`);+ case "textarea":+ return $("#compose-textarea");+ case "send_button":+ return $("#compose-send-button");+ case "send_status_identifier":+ return "#compose-send-status";+ case "send_status":+ return $("#compose-send-status");+ case "send_status_close_button":+ return $(".compose-send-status-close");+ case "send_status_message":+ return $("#compose-error-msg");+ case "file_input_identifier":+ return "#file_input";+ case "source":+ return "compose-file-input";+ case "drag_drop_container":+ return $("#compose");+ default:+ throw Error(`Invalid key name for mode "${config.mode}"`);}} else if (config.mode === "edit") {if (!config.row) {throw Error("Missing row in config");}switch (key) {- case "textarea":- return $("#message_edit_content_" + config.row);- case "send_button":- return $("#message_edit_content_" + config.row).closest("#message_edit_form").find(".message_edit_save");- case "send_status_identifier":- return "#message-edit-send-status-" + config.row;- case "send_status":- return $("#message-edit-send-status-" + config.row);- case "send_status_close_button":- return $("#message-edit-send-status-" + config.row).find(".send-status-close");- case "send_status_message":- return $("#message-edit-send-status-" + config.row).find(".error-msg");- case "file_input_identifier":- return "#message_edit_file_input_" + config.row;- case "source":- return "message-edit-file-input";- case "drag_drop_container":- return $("#message_edit_form");- default:- throw Error(`Invalid key name for mode "${config.mode}"`);+ case "textarea":+ return $("#message_edit_content_" + config.row);+ case "send_button":+ return $("#message_edit_content_" + config.row).closest("#message_edit_form").find(".message_edit_save");+ case "send_status_identifier":+ return "#message-edit-send-status-" + config.row;+ case "send_status":+ return $("#message-edit-send-status-" + config.row);+ case "send_status_close_button":+ return $("#message-edit-send-status-" + config.row).find(".send-status-close");+ case "send_status_message":+ return $("#message-edit-send-status-" + config.row).find(".error-msg");+ case "file_input_identifier":+ return "#message_edit_file_input_" + config.row;+ case "source":+ return "message-edit-file-input";+ case "drag_drop_container":+ return $("#message_edit_form");+ default:+ throw Error(`Invalid key name for mode "${config.mode}"`);}} else {throw Error("Invalid upload mode!");diff --git a/static/js/util.js b/static/js/util.jsindex f4467118400..6c8d09a65e5 100644--- a/static/js/util.js+++ b/static/js/util.js@@ -80,13 +80,13 @@ exports.same_recipient = function util_same_recipient(a, b) {}switch (a.type) {- case "private":- if (a.to_user_ids === undefined) {- return false;- }- return a.to_user_ids === b.to_user_ids;- case "stream":- return exports.same_stream_and_topic(a, b);+ case "private":+ if (a.to_user_ids === undefined) {+ return false;+ }+ return a.to_user_ids === b.to_user_ids;+ case "stream":+ return exports.same_stream_and_topic(a, b);}// should never get here