Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/narrow_state.js to ES6 module.
Anders Kaseorgb830f53eb5f2
diff --git a/.eslintrc.json b/.eslintrc.jsonindex c20e1cc670c..196704475c9 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -178,7 +178,6 @@"message_store": false,"message_util": false,"narrow": false,- "narrow_state": false,"navigate": false,"night_mode": false,"notifications": false,diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.jsindex aade1cfb501..0cf3dcb74e4 100644--- a/frontend_tests/node_tests/compose_actions.js+++ b/frontend_tests/node_tests/compose_actions.js@@ -39,9 +39,12 @@ rewiremock("../../static/js/drafts").with({update_draft: noop,});-const narrow_state = set_global("narrow_state", {+const narrow_state = {+ __esModule: true,set_compose_defaults: noop,-});+};++rewiremock("../../static/js/narrow_state").with(narrow_state);set_global("unread_ops", {notify_server_message_read: noop,diff --git a/frontend_tests/node_tests/dispatch_subs.js b/frontend_tests/node_tests/dispatch_subs.jsindex 672fd82bbe1..6eb069adef6 100644--- a/frontend_tests/node_tests/dispatch_subs.js+++ b/frontend_tests/node_tests/dispatch_subs.js@@ -2,6 +2,8 @@const {strict: assert} = require("assert");+const rewiremock = require("rewiremock/node");+const {set_global, zrequire} = require("../zjsunit/namespace");const {make_stub} = require("../zjsunit/stub");const {run_test} = require("../zjsunit/test");@@ -15,12 +17,15 @@ const compose_fade = set_global("compose_fade", {});const stream_events = set_global("stream_events", {});const subs = set_global("subs", {});+rewiremock.enable();+const peer_data = zrequire("peer_data");const people = zrequire("people");const stream_data = zrequire("stream_data");set_global("current_msg_list", {});-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);const page_params = set_global("page_params", {});const overlays = set_global("overlays", {});const settings_org = set_global("settings_org", {});@@ -266,3 +271,4 @@ test("stream delete (special streams)", (override) => {assert.equal(page_params.realm_notifications_stream_id, -1);assert.equal(page_params.realm_signup_notifications_stream_id, -1);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.jsindex 824a9a17b82..626f0ff6503 100644--- a/frontend_tests/node_tests/message_fetch.js+++ b/frontend_tests/node_tests/message_fetch.js@@ -41,7 +41,8 @@ set_global("message_scroll", {});const message_util = set_global("message_util", {});const message_store = set_global("message_store", {});-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);const pm_list = {__esModule: true};rewiremock("../../static/js/pm_list").with(pm_list);const server_events = set_global("server_events", {});diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.jsindex 7ef3b4ad4db..0e35e371584 100644--- a/frontend_tests/node_tests/message_list.js+++ b/frontend_tests/node_tests/message_list.js@@ -26,7 +26,8 @@ set_global("document", {},});-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);const stream_data = set_global("stream_data", {});set_global("recent_topics", {is_visible: () => false,diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.jsindex dc8420e60e1..ea139a2823d 100644--- a/frontend_tests/node_tests/narrow_local.js+++ b/frontend_tests/node_tests/narrow_local.js@@ -67,7 +67,7 @@ function test_with(fixture) {},};- narrow_state.get_first_unread_info = () => fixture.unread_info;+ narrow_state.__Rewire__("get_first_unread_info", () => fixture.unread_info);narrow.maybe_add_local_messages({id_info,diff --git a/frontend_tests/node_tests/narrow_unread.js b/frontend_tests/node_tests/narrow_unread.jsindex e3aed911d62..f18c3747245 100644--- a/frontend_tests/node_tests/narrow_unread.js+++ b/frontend_tests/node_tests/narrow_unread.js@@ -204,7 +204,7 @@ run_test("defensive code", () => {// _possible_unread_message_ids for any case where we// couldn't compute the unread message ids, but that// invariant is hard to future-proof.- narrow_state._possible_unread_message_ids = () => undefined;+ narrow_state.__Rewire__("_possible_unread_message_ids", () => undefined);const terms = [{operator: "some-unhandled-case", operand: "whatever"}];set_filter(terms);assert_unread_info({diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.jsindex 4769ce29d9f..b4823744293 100644--- a/frontend_tests/node_tests/pm_list.js+++ b/frontend_tests/node_tests/pm_list.js@@ -8,7 +8,8 @@ const {set_global, with_field, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");const $ = require("../zjsunit/zjquery");-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);set_global("ui", {get_content_element: (element) => element,});diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.jsindex 2dcf4732694..8624f937474 100644--- a/frontend_tests/node_tests/popovers.js+++ b/frontend_tests/node_tests/popovers.js@@ -46,7 +46,6 @@ rewiremock.enable();zrequire("hash_util");zrequire("narrow");-zrequire("narrow_state");const people = zrequire("people");zrequire("presence");zrequire("buddy_data");diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex 2cf25f2586e..00025a2a1fd 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -168,7 +168,6 @@ set_global("stream_data", {rewiremock.enable();zrequire("message_util");-zrequire("narrow_state");const people = zrequire("people");let rt = zrequire("recent_topics");diff --git a/frontend_tests/node_tests/search.js b/frontend_tests/node_tests/search.jsindex 5959c5b3778..ac68680e967 100644--- a/frontend_tests/node_tests/search.js+++ b/frontend_tests/node_tests/search.js@@ -2,6 +2,8 @@const {strict: assert} = require("assert");+const rewiremock = require("rewiremock/node");+const {set_global, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");const $ = require("../zjsunit/zjquery");@@ -12,7 +14,11 @@ set_global("page_params", {const noop = () => {};-const narrow_state = set_global("narrow_state", {filter: () => false});+const narrow_state = {+ __esModule: true,+ filter: () => false,+};+rewiremock("../../static/js/narrow_state").with(narrow_state);const search_suggestion = set_global("search_suggestion", {});set_global("ui_util", {change_tab_to: noop,@@ -27,6 +33,8 @@ set_global("search_pill_widget", {set_global("setTimeout", (func) => func());+rewiremock.enable();+const search = zrequire("search");const search_pill = zrequire("search_pill");const {Filter} = zrequire("Filter", "js/filter");@@ -341,3 +349,4 @@ run_test("initiate_search", () => {assert(is_searchbox_text_selected);assert(is_searchbox_focused);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/search_legacy.js b/frontend_tests/node_tests/search_legacy.jsindex 251249581bb..29081b5fb89 100644--- a/frontend_tests/node_tests/search_legacy.js+++ b/frontend_tests/node_tests/search_legacy.js@@ -14,7 +14,8 @@ set_global("page_params", {const noop = () => {};-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);const search_suggestion = set_global("search_suggestion", {});set_global("ui_util", {change_tab_to: noop,diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.jsindex c8f92c154c7..a0bfe2900e6 100644--- a/frontend_tests/node_tests/search_suggestion.js+++ b/frontend_tests/node_tests/search_suggestion.js@@ -88,7 +88,7 @@ run_test("basic_get_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => "office";+ narrow_state.__Rewire__("stream", () => "office");const suggestions = get_suggestions("", query);@@ -102,7 +102,7 @@ run_test("subset_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});const suggestions = get_suggestions(base_query, query);@@ -114,7 +114,7 @@ run_test("subset_suggestions", () => {run_test("private_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let query = "is:private";let suggestions = get_suggestions("", query);@@ -231,7 +231,7 @@ run_test("private_suggestions", () => {run_test("group_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});// Entering a comma in a pm-with query should immediately generate// suggestions for the next person.@@ -372,7 +372,7 @@ run_test("empty_query_suggestions", () => {stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});const suggestions = get_suggestions("", query);@@ -413,7 +413,7 @@ run_test("has_suggestions", () => {// default suggestion when suggesting `has` operator.let query = "h";stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let suggestions = get_suggestions("", query);let expected = ["h", "has:link", "has:image", "has:attachment"];@@ -467,7 +467,7 @@ run_test("has_suggestions", () => {run_test("check_is_suggestions", () => {let query = "i";stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let suggestions = get_suggestions("", query);let expected = [@@ -571,7 +571,7 @@ run_test("check_is_suggestions", () => {run_test("sent_by_me_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let query = "";let suggestions = get_suggestions("", query);@@ -650,7 +650,7 @@ run_test("topic_suggestions", () => {stream_data.subscribed_streams = () => ["office"];- narrow_state.stream = () => "office";+ narrow_state.__Rewire__("stream", () => "office");const devel_id = 44;const office_id = 77;@@ -739,7 +739,7 @@ run_test("whitespace_glitch", () => {stream_data.subscribed_streams = () => ["office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();@@ -753,7 +753,7 @@ run_test("whitespace_glitch", () => {run_test("stream_completion", () => {stream_data.subscribed_streams = () => ["office", "dev help"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();@@ -775,7 +775,7 @@ run_test("stream_completion", () => {function people_suggestion_setup() {stream_data.subscribed_streams = () => [];- narrow_state.stream = noop;+ narrow_state.__Rewire__("stream", noop);const ted = {email: "[email protected]",@@ -923,7 +923,7 @@ run_test("operator_suggestions", () => {run_test("queries_with_spaces", () => {stream_data.subscribed_streams = () => ["office", "dev help"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.jsindex 99eb53ac481..e60a20e9bd3 100644--- a/frontend_tests/node_tests/search_suggestion_legacy.js+++ b/frontend_tests/node_tests/search_suggestion_legacy.js@@ -84,7 +84,7 @@ run_test("basic_get_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => "office";+ narrow_state.__Rewire__("stream", () => "office");const suggestions = get_suggestions("", query);@@ -97,7 +97,7 @@ run_test("subset_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});const suggestions = get_suggestions("", query);@@ -113,7 +113,7 @@ run_test("subset_suggestions", () => {run_test("private_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let query = "is:private";let suggestions = get_suggestions("", query);@@ -226,7 +226,7 @@ run_test("private_suggestions", () => {run_test("group_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});// Entering a comma in a pm-with query should immediately generate// suggestions for the next person.@@ -374,7 +374,7 @@ run_test("empty_query_suggestions", () => {stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});const suggestions = get_suggestions("", query);@@ -415,7 +415,7 @@ run_test("has_suggestions", () => {// default suggestion when suggesting `has` operator.let query = "h";stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let suggestions = get_suggestions("", query);let expected = ["h", "has:link", "has:image", "has:attachment"];@@ -471,7 +471,7 @@ run_test("has_suggestions", () => {run_test("check_is_suggestions", () => {stream_data.subscribed_streams = () => ["devel", "office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let query = "i";let suggestions = get_suggestions("", query);@@ -541,7 +541,7 @@ run_test("check_is_suggestions", () => {run_test("sent_by_me_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});let query = "";let suggestions = get_suggestions("", query);@@ -615,7 +615,7 @@ run_test("topic_suggestions", () => {stream_data.subscribed_streams = () => ["office"];- narrow_state.stream = () => "office";+ narrow_state.__Rewire__("stream", () => "office");const devel_id = 44;const office_id = 77;@@ -710,7 +710,7 @@ run_test("whitespace_glitch", () => {stream_data.subscribed_streams = () => ["office"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();@@ -724,7 +724,7 @@ run_test("whitespace_glitch", () => {run_test("stream_completion", () => {stream_data.subscribed_streams = () => ["office", "dev help"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();@@ -749,7 +749,7 @@ run_test("people_suggestions", () => {stream_data.subscribed_streams = () => [];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});const ted = {email: "[email protected]",@@ -863,7 +863,7 @@ run_test("operator_suggestions", () => {run_test("queries_with_spaces", () => {stream_data.subscribed_streams = () => ["office", "dev help"];- narrow_state.stream = () => {};+ narrow_state.__Rewire__("stream", () => {});stream_topic_history.reset();diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.jsindex 64c0cd11208..30962199d94 100644--- a/frontend_tests/node_tests/stream_list.js+++ b/frontend_tests/node_tests/stream_list.js@@ -383,12 +383,12 @@ let narrow_state;test_ui("narrowing", () => {initialize_stream_data();- narrow_state = set_global("narrow_state", {+ narrow_state = rewiremock("../../static/js/narrow_state").with({stream() {return "devel";},topic: noop,- });+ }).mock.value;topic_list.close = noop;topic_list.rebuild = noop;diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.jsindex 116681f4b56..1654419cfb1 100644--- a/frontend_tests/node_tests/topic_list_data.js+++ b/frontend_tests/node_tests/topic_list_data.js@@ -8,9 +8,11 @@ const rewiremock = require("rewiremock/node");const {set_global, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");-const narrow_state = set_global("narrow_state", {+const narrow_state = {+ __esModule: true,topic() {},-});+};+rewiremock("../../static/js/narrow_state").with(narrow_state);set_global("unread", {});const muting = {__esModule: true,diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.jsindex 37dab837e5b..755b83d841f 100644--- a/frontend_tests/node_tests/ui_init.js+++ b/frontend_tests/node_tests/ui_init.js@@ -116,7 +116,6 @@ zrequire("condense");zrequire("lightbox");zrequire("overlays");zrequire("message_view_header");-zrequire("narrow_state");zrequire("presence");zrequire("search_pill_widget");zrequire("unread");diff --git a/frontend_tests/node_tests/unread.js b/frontend_tests/node_tests/unread.jsindex 0ccb6da1ed3..f3a7c3b4dd5 100644--- a/frontend_tests/node_tests/unread.js+++ b/frontend_tests/node_tests/unread.js@@ -3,6 +3,7 @@const {strict: assert} = require("assert");const _ = require("lodash");+const rewiremock = require("rewiremock/node");const {set_global, zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");@@ -11,11 +12,13 @@ let page_params = set_global("page_params", {realm_push_notifications_enabled: false,});-set_global("narrow_state", {});+rewiremock("../../static/js/narrow_state").with({});set_global("current_msg_list", {});set_global("home_msg_list", {});const message_store = set_global("message_store", {});+rewiremock.enable();+const muting = zrequire("muting");const people = zrequire("people");const stream_data = zrequire("stream_data");@@ -693,3 +696,4 @@ run_test("errors", () => {assert.equal(counts.private_message_count, 0);test_notifiable_count(counts.home_unread_messages, 0);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/user_events.js b/frontend_tests/node_tests/user_events.jsindex c0f96588a28..27cba605ed6 100644--- a/frontend_tests/node_tests/user_events.js+++ b/frontend_tests/node_tests/user_events.js@@ -38,7 +38,7 @@ rewiremock("../../static/js/pm_list").with({update_private_messages() {},});-set_global("narrow_state", {+rewiremock("../../static/js/narrow_state").with({update_email() {},});diff --git a/frontend_tests/node_tests/widgetize.js b/frontend_tests/node_tests/widgetize.jsindex 6b26ba0e9c4..6bf4ac72f63 100644--- a/frontend_tests/node_tests/widgetize.js+++ b/frontend_tests/node_tests/widgetize.js@@ -12,7 +12,8 @@ const poll_widget = {__esModule: true};rewiremock("../../static/js/poll_widget").with(poll_widget);set_global("document", "document-stub");-const narrow_state = set_global("narrow_state", {});+const narrow_state = {__esModule: true};+rewiremock("../../static/js/narrow_state").with(narrow_state);set_global("current_msg_list", {});rewiremock.enable();diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex e7be778e88f..cac35e6ade5 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -22,7 +22,6 @@ import "../unread";import "../stream_list";import "../widgetize";import "../message_list";-import "../narrow_state";import "../narrow";import "../reload_state";import "../reload";diff --git a/static/js/compose_actions.js b/static/js/compose_actions.jsindex 9efb76f6eca..5909f954898 100644--- a/static/js/compose_actions.js+++ b/static/js/compose_actions.js@@ -9,6 +9,7 @@ const common = require("./common");const compose_pm_pill = require("./compose_pm_pill");const drafts = require("./drafts");const message_viewport = require("./message_viewport");+const narrow_state = require("./narrow_state");const people = require("./people");exports.blur_compose_inputs = function () {diff --git a/static/js/echo.js b/static/js/echo.jsindex b0ceba17f64..314cbe2e21d 100644--- a/static/js/echo.js+++ b/static/js/echo.js@@ -1,4 +1,5 @@import * as alert_words from "./alert_words";+import * as narrow_state from "./narrow_state";import * as people from "./people";import * as pm_list from "./pm_list";import * as rows from "./rows";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 589bd7aafe9..94dcc68b68b 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -52,7 +52,6 @@ declare let message_scroll: any;declare let message_store: any;declare let message_util: any;declare let narrow: any;-declare let narrow_state: any;declare let navigate: any;declare let night_mode: any;declare let notifications: any;diff --git a/static/js/hash_util.js b/static/js/hash_util.jsindex be907d02845..93956436697 100644--- a/static/js/hash_util.js+++ b/static/js/hash_util.js@@ -1,5 +1,6 @@"use strict";+const narrow_state = require("./narrow_state");const people = require("./people");exports.get_hash_category = function (hash) {diff --git a/static/js/message_events.js b/static/js/message_events.jsindex f0a32cb46e4..46640f2a21a 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -4,6 +4,7 @@ const alert_words = require("./alert_words");const channel = require("./channel");const huddle_data = require("./huddle_data");const message_edit_history = require("./message_edit_history");+const narrow_state = require("./narrow_state");const pm_list = require("./pm_list");const recent_senders = require("./recent_senders");const unread_ui = require("./unread_ui");diff --git a/static/js/message_list.js b/static/js/message_list.jsindex b963e5adcfe..428028a8374 100644--- a/static/js/message_list.js+++ b/static/js/message_list.js@@ -4,6 +4,7 @@ const autosize = require("autosize");const {MessageListData} = require("./message_list_data");const {MessageListView} = require("./message_list_view");+const narrow_state = require("./narrow_state");exports.narrowed = undefined;exports.set_narrowed = function (value) {diff --git a/static/js/message_list_view.js b/static/js/message_list_view.jsindex 8aa0a6a30a3..efc4a8af705 100644--- a/static/js/message_list_view.js+++ b/static/js/message_list_view.js@@ -7,6 +7,7 @@ import render_recipient_row from "../templates/recipient_row.hbs";import render_single_message from "../templates/single_message.hbs";import * as message_viewport from "./message_viewport";+import * as narrow_state from "./narrow_state";import * as people from "./people";import * as rendered_markdown from "./rendered_markdown";import * as rows from "./rows";diff --git a/static/js/message_scroll.js b/static/js/message_scroll.jsindex b8b66552319..17b6589139b 100644--- a/static/js/message_scroll.js+++ b/static/js/message_scroll.js@@ -4,6 +4,7 @@ const _ = require("lodash");const loading = require("./loading");const message_viewport = require("./message_viewport");+const narrow_state = require("./narrow_state");let actively_scrolling = false;diff --git a/static/js/message_view_header.js b/static/js/message_view_header.jsindex 5e342239cc6..b5d97f17b58 100644--- a/static/js/message_view_header.js+++ b/static/js/message_view_header.js@@ -2,6 +2,7 @@const render_message_view_header = require("../templates/message_view_header.hbs");+const narrow_state = require("./narrow_state");const peer_data = require("./peer_data");const rendered_markdown = require("./rendered_markdown");diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 0f15021c16f..e166f680392 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -3,6 +3,7 @@const channel = require("./channel");const {Filter} = require("./filter");const {MessageListData} = require("./message_list_data");+const narrow_state = require("./narrow_state");const people = require("./people");const search_pill = require("./search_pill");const top_left_corner = require("./top_left_corner");diff --git a/static/js/narrow_state.js b/static/js/narrow_state.jsindex 4e8564bc26b..ccf0e401f17 100644--- a/static/js/narrow_state.js+++ b/static/js/narrow_state.js@@ -1,52 +1,50 @@-"use strict";--const {Filter} = require("./filter");-const people = require("./people");+import {Filter} from "./filter";+import * as people from "./people";let current_filter;-exports.reset_current_filter = function () {+export function reset_current_filter() {current_filter = undefined;-};+}-exports.set_current_filter = function (filter) {+export function set_current_filter(filter) {current_filter = filter;-};+}-exports.active = function () {+export function active() {return current_filter !== undefined;-};+}-exports.filter = function () {+export function filter() {// Both, `All messages` and// `Recent topics` have `current_filter=undefined`return current_filter;-};+}-exports.operators = function () {+export function operators() {if (current_filter === undefined) {return new Filter(page_params.narrow).operators();}return current_filter.operators();-};+}-exports.update_email = function (user_id, new_email) {+export function update_email(user_id, new_email) {if (current_filter !== undefined) {current_filter.update_email(user_id, new_email);}-};+}/* Operators we should send to the server. */-exports.public_operators = function () {+export function public_operators() {if (current_filter === undefined) {return undefined;}return current_filter.public_operators();-};+}-exports.search_string = function () {- return Filter.unparse(exports.operators());-};+export function search_string() {+ return Filter.unparse(operators());+}// Collect operators which appear only once into an object,// and discard those which appear more than once.@@ -73,9 +71,9 @@ function collect_single(operators) {// This logic is here and not in the 'compose' module because// it will get more complicated as we add things to the narrow// operator language.-exports.set_compose_defaults = function () {+export function set_compose_defaults() {const opts = {};- const single = collect_single(exports.operators());+ const single = collect_single(operators());// Set the stream, topic, and/or PM recipient if they are// uniquely specified in the narrow view.@@ -95,9 +93,9 @@ exports.set_compose_defaults = function () {}}return opts;-};+}-exports.stream = function () {+export function stream() {if (current_filter === undefined) {return undefined;}@@ -110,9 +108,9 @@ exports.stream = function () {return stream_data.get_name(name);}return undefined;-};+}-exports.stream_sub = function () {+export function stream_sub() {if (current_filter === undefined) {return undefined;}@@ -125,9 +123,9 @@ exports.stream_sub = function () {const sub = stream_data.get_sub_by_name(name);return sub;-};+}-exports.topic = function () {+export function topic() {if (current_filter === undefined) {return undefined;}@@ -136,9 +134,9 @@ exports.topic = function () {return operands[0];}return undefined;-};+}-exports.pm_string = function () {+export function pm_string() {// If you are narrowed to a PM conversation// with users 4, 5, and 99, this will return "4,5,99"@@ -160,9 +158,9 @@ exports.pm_string = function () {const user_ids_string = people.reply_to_to_user_ids_string(emails_string);return user_ids_string;-};+}-exports.get_first_unread_info = function () {+export function get_first_unread_info() {if (current_filter === undefined) {// we don't yet support the all-messages viewblueslip.error("unexpected call to get_first_unread_info");@@ -181,7 +179,7 @@ exports.get_first_unread_info = function () {};}- const unread_ids = exports._possible_unread_message_ids();+ const unread_ids = _possible_unread_message_ids();if (unread_ids === undefined) {// _possible_unread_message_ids() only works for certain narrows@@ -202,9 +200,9 @@ exports.get_first_unread_info = function () {flavor: "found",msg_id: unread_ids[0],};-};+}-exports._possible_unread_message_ids = function () {+export function _possible_unread_message_ids() {// This function currently only returns valid results for// certain types of narrows, mostly left sidebar narrows.// For more complicated narrows we may return undefined.@@ -221,16 +219,16 @@ exports._possible_unread_message_ids = function () {let current_filter_pm_string;if (current_filter.can_bucket_by("stream", "topic")) {- sub = exports.stream_sub();+ sub = stream_sub();if (sub === undefined) {return [];}- topic_name = exports.topic();+ topic_name = topic();return unread.get_msg_ids_for_topic(sub.stream_id, topic_name);}if (current_filter.can_bucket_by("stream")) {- sub = exports.stream_sub();+ sub = stream_sub();if (sub === undefined) {return [];}@@ -238,7 +236,7 @@ exports._possible_unread_message_ids = function () {}if (current_filter.can_bucket_by("pm-with")) {- current_filter_pm_string = exports.pm_string();+ current_filter_pm_string = pm_string();if (current_filter_pm_string === undefined) {return [];}@@ -267,25 +265,25 @@ exports._possible_unread_message_ids = function () {}return undefined;-};+}// Are we narrowed to PMs: all PMs or PMs with particular people.-exports.narrowed_to_pms = function () {+export function narrowed_to_pms() {if (current_filter === undefined) {return false;}return current_filter.has_operator("pm-with") || current_filter.has_operand("is", "private");-};+}-exports.narrowed_by_pm_reply = function () {+export function narrowed_by_pm_reply() {if (current_filter === undefined) {return false;}const operators = current_filter.operators();return operators.length === 1 && current_filter.has_operator("pm-with");-};+}-exports.narrowed_by_topic_reply = function () {+export function narrowed_by_topic_reply() {if (current_filter === undefined) {return false;}@@ -295,60 +293,58 @@ exports.narrowed_by_topic_reply = function () {current_filter.operands("stream").length === 1 &¤t_filter.operands("topic").length === 1);-};+}// We auto-reply under certain conditions, namely when you're narrowed// to a PM (or huddle), and when you're narrowed to some stream/topic pair-exports.narrowed_by_reply = function () {- return exports.narrowed_by_pm_reply() || exports.narrowed_by_topic_reply();-};+export function narrowed_by_reply() {+ return narrowed_by_pm_reply() || narrowed_by_topic_reply();+}-exports.narrowed_by_stream_reply = function () {+export function narrowed_by_stream_reply() {if (current_filter === undefined) {return false;}const operators = current_filter.operators();return operators.length === 1 && current_filter.operands("stream").length === 1;-};+}-exports.narrowed_to_topic = function () {+export function narrowed_to_topic() {if (current_filter === undefined) {return false;}return current_filter.has_operator("stream") && current_filter.has_operator("topic");-};+}-exports.narrowed_to_search = function () {+export function narrowed_to_search() {return current_filter !== undefined && current_filter.is_search();-};+}-exports.narrowed_to_starred = function () {+export function narrowed_to_starred() {if (current_filter === undefined) {return false;}return current_filter.has_operand("is", "starred");-};+}-exports.excludes_muted_topics = function () {+export function excludes_muted_topics() {return (- !exports.narrowed_to_topic() &&- !exports.narrowed_to_search() &&- !exports.narrowed_to_pms() &&- !exports.narrowed_to_starred()+ !narrowed_to_topic() &&+ !narrowed_to_search() &&+ !narrowed_to_pms() &&+ !narrowed_to_starred());-};+}-exports.is_for_stream_id = function (stream_id) {+export function is_for_stream_id(stream_id) {// This is not perfect, since we still track narrows by// name, not id, but at least the interface is good going// forward.- const narrow_sub = exports.stream_sub();+ const narrow_sub = stream_sub();if (narrow_sub === undefined) {return false;}return stream_id === narrow_sub.stream_id;-};--window.narrow_state = exports;+}diff --git a/static/js/notifications.js b/static/js/notifications.jsindex 2a7ca6073bf..92de10179ed 100644--- a/static/js/notifications.js+++ b/static/js/notifications.js@@ -9,6 +9,7 @@ const alert_words = require("./alert_words");const channel = require("./channel");const favicon = require("./favicon");const muting = require("./muting");+const narrow_state = require("./narrow_state");const people = require("./people");const settings_config = require("./settings_config");const spoilers = require("./spoilers");diff --git a/static/js/pm_list.js b/static/js/pm_list.jsindex a9e39f22e8a..ddd18561d87 100644--- a/static/js/pm_list.js+++ b/static/js/pm_list.js@@ -1,3 +1,4 @@+import * as narrow_state from "./narrow_state";import * as people from "./people";import * as pm_conversations from "./pm_conversations";import * as pm_list_dom from "./pm_list_dom";diff --git a/static/js/popovers.js b/static/js/popovers.jsindex cbeeb3728be..a5be73a1440 100644--- a/static/js/popovers.js+++ b/static/js/popovers.js@@ -21,6 +21,7 @@ const message_edit_history = require("./message_edit_history");const message_viewport = require("./message_viewport");const muting = require("./muting");const muting_ui = require("./muting_ui");+const narrow_state = require("./narrow_state");const people = require("./people");const rows = require("./rows");const settings_config = require("./settings_config");diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex 4d0756ac31a..77e37f21672 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -7,6 +7,7 @@ const render_recent_topics_body = require("../templates/recent_topics_table.hbs"const drafts = require("./drafts");const {localstorage} = require("./localstorage");const muting = require("./muting");+const narrow_state = require("./narrow_state");const people = require("./people");const recent_senders = require("./recent_senders");const top_left_corner = require("./top_left_corner");diff --git a/static/js/reload.js b/static/js/reload.jsindex 671b5b589ce..af35a5e3b19 100644--- a/static/js/reload.js+++ b/static/js/reload.js@@ -1,6 +1,7 @@"use strict";const {localstorage} = require("./localstorage");+const narrow_state = require("./narrow_state");const util = require("./util");// Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.htmldiff --git a/static/js/search.js b/static/js/search.jsindex faa6eaf0d0b..20ce554f056 100644--- a/static/js/search.js+++ b/static/js/search.js@@ -1,6 +1,7 @@"use strict";const {Filter} = require("./filter");+const narrow_state = require("./narrow_state");const search_pill = require("./search_pill");// Exported for unit testingdiff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.jsindex f6f8aec8209..e74c455fed3 100644--- a/static/js/search_suggestion.js+++ b/static/js/search_suggestion.js@@ -5,6 +5,7 @@ const Handlebars = require("handlebars/runtime");const common = require("./common");const {Filter} = require("./filter");const huddle_data = require("./huddle_data");+const narrow_state = require("./narrow_state");const people = require("./people");const settings_data = require("./settings_data");diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex 1e645dfd587..cc4555a9c98 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -2,6 +2,7 @@ import * as emoji from "../shared/js/emoji";import * as alert_words from "./alert_words";import * as muting_ui from "./muting_ui";+import * as narrow_state from "./narrow_state";import * as peer_data from "./peer_data";import * as people from "./people";import * as settings_config from "./settings_config";diff --git a/static/js/stream_edit.js b/static/js/stream_edit.jsindex 5affac9bc5e..e773293ab6d 100644--- a/static/js/stream_edit.js+++ b/static/js/stream_edit.js@@ -7,6 +7,7 @@ const render_subscription_settings = require("../templates/subscription_settingsconst render_subscription_stream_privacy_modal = require("../templates/subscription_stream_privacy_modal.hbs");const channel = require("./channel");+const narrow_state = require("./narrow_state");const peer_data = require("./peer_data");const people = require("./people");const pill_typeahead = require("./pill_typeahead");diff --git a/static/js/stream_events.js b/static/js/stream_events.jsindex 29a1a483c0b..6db9f7e882b 100644--- a/static/js/stream_events.js+++ b/static/js/stream_events.js@@ -1,5 +1,6 @@"use strict";+const narrow_state = require("./narrow_state");const peer_data = require("./peer_data");// In theory, this function should apply the account-level defaults,diff --git a/static/js/stream_list.js b/static/js/stream_list.jsindex 9ba786f713d..8372f382eb2 100644--- a/static/js/stream_list.js+++ b/static/js/stream_list.js@@ -7,6 +7,7 @@ const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs")const keydown_util = require("./keydown_util");const {ListCursor} = require("./list_cursor");+const narrow_state = require("./narrow_state");const scroll_util = require("./scroll_util");const stream_sort = require("./stream_sort");const topic_list = require("./topic_list");diff --git a/static/js/topic_list_data.js b/static/js/topic_list_data.jsindex 76c6f93f9a6..4808bcb45ab 100644--- a/static/js/topic_list_data.js+++ b/static/js/topic_list_data.js@@ -1,4 +1,5 @@import * as muting from "./muting";+import * as narrow_state from "./narrow_state";const max_topics = 5;const max_topics_with_unread = 8;diff --git a/static/js/typing_events.js b/static/js/typing_events.jsindex 941352d7c95..c63a30a5c4b 100644--- a/static/js/typing_events.js+++ b/static/js/typing_events.js@@ -2,6 +2,7 @@const render_typing_notifications = require("../templates/typing_notifications.hbs");+const narrow_state = require("./narrow_state");const people = require("./people");const typing_data = require("./typing_data");diff --git a/static/js/user_events.js b/static/js/user_events.jsindex f999469500c..09770e3d5be 100644--- a/static/js/user_events.js+++ b/static/js/user_events.js@@ -5,6 +5,7 @@// dependencies that existed when this code was in people.js.// (We should do bot updates here too.)const message_live_update = require("./message_live_update");+const narrow_state = require("./narrow_state");const people = require("./people");const pm_list = require("./pm_list");const settings_config = require("./settings_config");diff --git a/static/js/widgetize.js b/static/js/widgetize.jsindex 054d2603a4f..d10983888a1 100644--- a/static/js/widgetize.js+++ b/static/js/widgetize.js@@ -1,5 +1,6 @@"use strict";+const narrow_state = require("./narrow_state");const poll_widget = require("./poll_widget");const todo_widget = require("./todo_widget");const zform = require("./zform");