Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/channel.js to ES6 module.

Anders Kaseorg09920af2114b
diff --git a/.eslintrc.json b/.eslintrc.json
index 26f90de4731..7404678e007 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -136,7 +136,6 @@
"bot_data": false,
"buddy_data": false,
"buddy_list": false,
- "channel": false,
"click_handlers": false,
"color_data": false,
"compose": false,
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index 554a961c35e..4e74492aa41 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -25,7 +25,7 @@ const _document = {
},
};
-const channel = {};
+const channel = {__esModule: true};
const _ui = {
get_content_element: (element) => element,
@@ -68,7 +68,7 @@ const _resize = {
set_global("padded_widget", {
update_padding: () => {},
});
-set_global("channel", channel);
+rewiremock("../../static/js/channel").with(channel);
set_global("compose_state", compose_state);
set_global("document", _document);
rewiremock("../../static/js/keydown_util").with(_keydown_util);
diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js
index 4645195eab1..e623c0999af 100644
--- a/frontend_tests/node_tests/alert_words_ui.js
+++ b/frontend_tests/node_tests/alert_words_ui.js
@@ -2,12 +2,17 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {stub_templates} = require("../zjsunit/handlebars");
-const {set_global, zrequire} = require("../zjsunit/namespace");
+const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+
+rewiremock("../../static/js/channel").with(channel);
+rewiremock.enable();
const alert_words = zrequire("alert_words");
const alert_words_ui = zrequire("alert_words_ui");
@@ -192,3 +197,4 @@ run_test("close_status_message", (override) => {
close(event);
assert(!alert.visible());
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js
index a5ec9161a68..218c26666e7 100644
--- a/frontend_tests/node_tests/compose.js
+++ b/frontend_tests/node_tests/compose.js
@@ -60,7 +60,8 @@ rewiremock("../../static/js/rendered_markdown").with({
const local_message = set_global("local_message", {});
const transmit = set_global("transmit", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const stream_edit = set_global("stream_edit", {});
const markdown = set_global("markdown", {});
const loading = {__esModule: true};
diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js
index bc259244206..aade1cfb501 100644
--- a/frontend_tests/node_tests/compose_actions.js
+++ b/frontend_tests/node_tests/compose_actions.js
@@ -57,7 +57,9 @@ set_global("current_msg_list", {
},
});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+
+rewiremock("../../static/js/channel").with(channel);
rewiremock.enable();
@@ -358,7 +360,7 @@ run_test("quote_and_reply", (override) => {
raw_content: "Testing.",
};
- set_global("channel", {
+ rewiremock("../../static/js/channel").with({
get() {
assert.fail("channel.get should not be used if raw_content is present");
},
diff --git a/frontend_tests/node_tests/composebox_typeahead.js b/frontend_tests/node_tests/composebox_typeahead.js
index f5e422f2995..611bc1eaa70 100644
--- a/frontend_tests/node_tests/composebox_typeahead.js
+++ b/frontend_tests/node_tests/composebox_typeahead.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");
@@ -15,7 +17,8 @@ const message_store = set_global("message_store", {
});
const page_params = set_global("page_params", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const compose = set_global("compose", {
finish: noop,
});
@@ -34,6 +37,8 @@ set_global("setTimeout", (f, time) => {
});
set_global("document", "document-stub");
+rewiremock.enable();
+
const emoji = zrequire("emoji", "shared/js/emoji");
const typeahead = zrequire("typeahead", "shared/js/typeahead");
const compose_state = zrequire("compose_state");
@@ -1552,3 +1557,4 @@ run_test("message people", () => {
// harry is excluded since it has been deactivated.
assert.deepEqual(results, [hamletcharacters, hal]);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js
index abaa9808d80..7235175ac94 100644
--- a/frontend_tests/node_tests/message_fetch.js
+++ b/frontend_tests/node_tests/message_fetch.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");
@@ -26,7 +27,8 @@ set_global("ui_report", {
hide_error: noop,
});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
set_global("document", "document-stub");
set_global("message_scroll", {
show_loading_older: noop,
@@ -44,6 +46,8 @@ const stream_list = set_global("stream_list", {
maybe_scroll_narrow_into_view: () => {},
});
+rewiremock.enable();
+
const message_fetch = zrequire("message_fetch");
const Filter = zrequire("Filter", "js/filter");
const message_list = zrequire("message_list");
@@ -472,3 +476,4 @@ run_test("loading_newer", () => {
assert.equal(msg_list.data.fetch_status.can_load_newer_messages(), false);
})();
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js
index 79d8eb45ff0..2e3b1db8dba 100644
--- a/frontend_tests/node_tests/message_flags.js
+++ b/frontend_tests/node_tests/message_flags.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");
@@ -10,12 +12,16 @@ set_global("starred_messages", {
remove: () => {},
});
+rewiremock.enable();
+
zrequire("unread");
zrequire("unread_ops");
const message_flags = zrequire("message_flags");
const ui = set_global("ui", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+
+rewiremock("../../static/js/channel").with(channel);
run_test("starred", () => {
const message = {
@@ -166,3 +172,4 @@ run_test("read", () => {
success: channel_post_opts.success,
});
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js
index 646387666c0..436ddb18f30 100644
--- a/frontend_tests/node_tests/narrow_activate.js
+++ b/frontend_tests/node_tests/narrow_activate.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");
@@ -9,7 +11,8 @@ set_global("resize", {
resize_stream_filters_container: () => {},
});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const compose = set_global("compose", {});
const compose_actions = set_global("compose_actions", {});
set_global("current_msg_list", {});
@@ -59,6 +62,8 @@ set_global("muting", {
is_topic_muted: () => false,
});
+rewiremock.enable();
+
const util = zrequire("util");
const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
@@ -237,3 +242,4 @@ run_test("basics", () => {
cont();
helper.assert_events(["report narrow times"]);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.js
index 2455fee2a5a..98565428a8c 100644
--- a/frontend_tests/node_tests/reactions.js
+++ b/frontend_tests/node_tests/reactions.js
@@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {stub_templates} = require("../zjsunit/handlebars");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub");
@@ -15,7 +17,8 @@ set_global("page_params", {
user_id: alice_user_id,
});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const emoji_picker = set_global("emoji_picker", {
hide_emoji_popover() {},
});
@@ -70,6 +73,8 @@ set_global("current_msg_list", {
},
});
+rewiremock.enable();
+
const emoji_codes = zrequire("emoji_codes", "generated/emoji/emoji_codes.json");
const emoji = zrequire("emoji", "shared/js/emoji");
const people = zrequire("people");
@@ -984,3 +989,4 @@ run_test("process_reaction_click bad local id", (override) => {
);
reactions.process_reaction_click("some-msg-id", "bad-local-id");
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.js
index d0115079bd8..a4669b95069 100644
--- a/frontend_tests/node_tests/server_events.js
+++ b/frontend_tests/node_tests/server_events.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");
@@ -17,7 +19,8 @@ set_global("document", {
});
set_global("addEventListener", noop);
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
set_global("home_msg_list", {
select_id: noop,
selected_id() {
@@ -48,6 +51,8 @@ set_global("$", {
now() {},
});
+rewiremock.enable();
+
zrequire("message_store");
const server_events = zrequire("server_events");
zrequire("sent_messages");
@@ -147,3 +152,4 @@ run_test("event_edit_message_error", () => {
assert.equal(logs.length, 1);
assert.equal(logs[0].more_info, undefined);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js
index fcb212dcf51..a20d889aadc 100644
--- a/frontend_tests/node_tests/settings_org.js
+++ b/frontend_tests/node_tests/settings_org.js
@@ -41,7 +41,9 @@ const page_params = set_global("page_params", {
});
const realm_icon = set_global("realm_icon", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+
+rewiremock("../../static/js/channel").with(channel);
stub_templates((name, data) => {
if (name === "settings/admin_realm_domains_list") {
diff --git a/frontend_tests/node_tests/settings_user_groups.js b/frontend_tests/node_tests/settings_user_groups.js
index fec5325ee78..30bbef1587e 100644
--- a/frontend_tests/node_tests/settings_user_groups.js
+++ b/frontend_tests/node_tests/settings_user_groups.js
@@ -3,6 +3,7 @@
const {strict: assert} = require("assert");
const _ = require("lodash");
+const rewiremock = require("rewiremock/node");
const {stub_templates} = require("../zjsunit/handlebars");
const {set_global, zrequire} = require("../zjsunit/namespace");
@@ -19,7 +20,8 @@ const pills = {
let create_item_handler;
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const typeahead_helper = set_global("typeahead_helper", {});
const user_groups = set_global("user_groups", {
get_user_group_from_id: noop,
@@ -30,6 +32,8 @@ const ui_report = set_global("ui_report", {});
const page_params = set_global("page_params", {});
+rewiremock.enable();
+
const user_pill = zrequire("user_pill");
const settings_user_groups = zrequire("settings_user_groups");
const settings_config = zrequire("settings_config");
@@ -868,3 +872,4 @@ test_ui("on_events", () => {
assert(api_endpoint_called);
})();
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/stream_edit.js b/frontend_tests/node_tests/stream_edit.js
index e93de4dc561..5c52a8bccd6 100644
--- a/frontend_tests/node_tests/stream_edit.js
+++ b/frontend_tests/node_tests/stream_edit.js
@@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {stub_templates} = require("../zjsunit/handlebars");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
@@ -10,7 +12,7 @@ const $ = require("../zjsunit/zjquery");
const noop = () => {};
stub_templates(() => noop);
-set_global("channel", {});
+rewiremock("../../static/js/channel").with({});
set_global("hashchange", {update_browser_history: noop});
set_global("hash_util", {
stream_edit_uri: noop,
@@ -31,6 +33,8 @@ const ui = set_global("ui", {
get_scroll_element: noop,
});
+rewiremock.enable();
+
zrequire("input_pill");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
@@ -270,3 +274,4 @@ test_ui("subscriber_pills", () => {
expected_user_ids = potential_denmark_stream_subscribers.concat(fred.user_id);
add_subscribers_handler(event);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.js
index 7c32c1a1106..c4c65781b84 100644
--- a/frontend_tests/node_tests/stream_topic_history.js
+++ b/frontend_tests/node_tests/stream_topic_history.js
@@ -2,12 +2,17 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const message_list = set_global("message_list", {});
+rewiremock.enable();
+
const unread = zrequire("unread");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
@@ -332,3 +337,4 @@ run_test("server_history_end_to_end", () => {
});
assert(on_success_called);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/submessage.js b/frontend_tests/node_tests/submessage.js
index d267d96287b..455eda92d35 100644
--- a/frontend_tests/node_tests/submessage.js
+++ b/frontend_tests/node_tests/submessage.js
@@ -2,13 +2,18 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const widgetize = set_global("widgetize", {});
const message_store = set_global("message_store", {});
+rewiremock.enable();
+
const submessage = zrequire("submessage");
run_test("get_message_events", () => {
@@ -99,3 +104,4 @@ run_test("handle_event", () => {
assert.deepEqual(message.submessages[0], event);
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/transmit.js b/frontend_tests/node_tests/transmit.js
index 4840a06ab94..fb2aedf7643 100644
--- a/frontend_tests/node_tests/transmit.js
+++ b/frontend_tests/node_tests/transmit.js
@@ -2,13 +2,16 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const noop = () => {};
const page_params = set_global("page_params", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const reload = set_global("reload", {});
const reload_state = set_global("reload_state", {});
const sent_messages = set_global("sent_messages", {
@@ -16,6 +19,8 @@ const sent_messages = set_global("sent_messages", {
report_server_ack: noop,
});
+rewiremock.enable();
+
const people = zrequire("people");
const transmit = zrequire("transmit");
@@ -187,3 +192,4 @@ run_test("reply_message_errors", () => {
message: bogus_message,
});
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.js
index 8eb919efcf5..0b4d785139b 100644
--- a/frontend_tests/node_tests/tutorial.js
+++ b/frontend_tests/node_tests/tutorial.js
@@ -9,6 +9,8 @@
// become clear as you keep reading.
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, with_field, zrequire} = require("../zjsunit/namespace");
const {make_stub} = require("../zjsunit/stub");
const {run_test} = require("../zjsunit/test");
@@ -32,10 +34,13 @@ const resize = set_global("resize", {});
let stream_list = set_global("stream_list", {});
let unread_ops = set_global("unread_ops", {});
const unread_ui = set_global("unread_ui", {});
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
const message_viewport = set_global("message_viewport", {});
const topic_list = set_global("topic_list", {});
+rewiremock.enable();
+
// Let's start with testing a function from util.js.
//
// We will use our special zrequire helper to import the
@@ -818,3 +823,4 @@ run_test("stream_list", (override) => {
sidebar_helper.verify_actions();
topic_list_helper.verify_actions();
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/user_status.js b/frontend_tests/node_tests/user_status.js
index aa81ba53ca4..f323637ab10 100644
--- a/frontend_tests/node_tests/user_status.js
+++ b/frontend_tests/node_tests/user_status.js
@@ -2,10 +2,14 @@
const {strict: assert} = require("assert");
-const {set_global, zrequire} = require("../zjsunit/namespace");
+const rewiremock = require("rewiremock/node");
+
+const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-const channel = set_global("channel", {});
+const channel = {__esModule: true};
+rewiremock("../../static/js/channel").with(channel);
+rewiremock.enable();
const user_status = zrequire("user_status");
function initialize() {
@@ -83,3 +87,4 @@ run_test("defensive checks", () => {
user_status.set_away("string");
user_status.revoke_away("string");
});
+rewiremock.disable();
diff --git a/static/js/activity.js b/static/js/activity.js
index 6bcb2c18acb..bdb7c92b642 100644
--- a/static/js/activity.js
+++ b/static/js/activity.js
@@ -2,6 +2,7 @@
const _ = require("lodash");
+const channel = require("./channel");
const keydown_util = require("./keydown_util");
const {ListCursor} = require("./list_cursor");
const people = require("./people");
diff --git a/static/js/alert_words_ui.js b/static/js/alert_words_ui.js
index 7e2c805b1b9..4f3bf565997 100644
--- a/static/js/alert_words_ui.js
+++ b/static/js/alert_words_ui.js
@@ -3,6 +3,7 @@
const render_alert_word_settings_item = require("../templates/settings/alert_word_settings_item.hbs");
const alert_words = require("./alert_words");
+const channel = require("./channel");
exports.render_alert_words_ui = function () {
const words = alert_words.get_word_list();
diff --git a/static/js/attachments_ui.js b/static/js/attachments_ui.js
index 3c81190e59b..aa3f4d19329 100644
--- a/static/js/attachments_ui.js
+++ b/static/js/attachments_ui.js
@@ -3,6 +3,7 @@
const render_settings_upload_space_stats = require("../templates/settings/upload_space_stats.hbs");
const render_uploaded_files_list = require("../templates/uploaded_files_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
let attachments;
diff --git a/static/js/avatar.js b/static/js/avatar.js
index b0633a07d54..41ceee69032 100644
--- a/static/js/avatar.js
+++ b/static/js/avatar.js
@@ -1,5 +1,7 @@
"use strict";
+const channel = require("./channel");
+
exports.build_bot_create_widget = function () {
// We have to do strange gyrations with the file input to clear it,
// where we replace it wholesale, so we generalize the file input with
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index fe3af92f6be..22720b75520 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
import "../i18n";
import "../fold_dict";
import "../input_pill";
-import "../channel";
import "../setup";
import "../unread_ui";
import "../unread_ops";
diff --git a/static/js/channel.js b/static/js/channel.js
index c263422fa84..0e9e64889e3 100644
--- a/static/js/channel.js
+++ b/static/js/channel.js
@@ -1,5 +1,3 @@
-"use strict";
-
const pending_requests = [];
function add_pending_request(jqXHR) {
@@ -98,28 +96,28 @@ function call(args, idempotent) {
return jqXHR;
}
-exports.get = function (options) {
+export function get(options) {
const args = {type: "GET", dataType: "json", ...options};
return call(args, options.idempotent);
-};
+}
-exports.post = function (options) {
+export function post(options) {
const args = {type: "POST", dataType: "json", ...options};
return call(args, options.idempotent);
-};
+}
-exports.put = function (options) {
+export function put(options) {
const args = {type: "PUT", dataType: "json", ...options};
return call(args, options.idempotent);
-};
+}
// Not called exports.delete because delete is a reserved word in JS
-exports.del = function (options) {
+export function del(options) {
const args = {type: "DELETE", dataType: "json", ...options};
return call(args, options.idempotent);
-};
+}
-exports.patch = function (options) {
+export function patch(options) {
// Send a PATCH as a POST in order to work around QtWebkit
// (Linux/Windows desktop app) not supporting PATCH body.
if (options.processData === false) {
@@ -129,16 +127,14 @@ exports.patch = function (options) {
} else {
options.data = {...options.data, method: "PATCH"};
}
- return exports.post(options, options.idempotent);
-};
+ return post(options, options.idempotent);
+}
-exports.xhr_error_message = function (message, xhr) {
+export function xhr_error_message(message, xhr) {
if (xhr.status.toString().charAt(0) === "4") {
// Only display the error response for 4XX, where we've crafted
// a nice response.
message += ": " + JSON.parse(xhr.responseText).msg;
}
return message;
-};
-
-window.channel = exports;
+}
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 1f1c24d0a40..d813aebc315 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -8,6 +8,7 @@ const WinChan = require("winchan");
const render_buddy_list_tooltip = require("../templates/buddy_list_tooltip.hbs");
const render_buddy_list_tooltip_content = require("../templates/buddy_list_tooltip_content.hbs");
+const channel = require("./channel");
const message_edit_history = require("./message_edit_history");
const settings_panel_menu = require("./settings_panel_menu");
const user_status_ui = require("./user_status_ui");
diff --git a/static/js/compose.js b/static/js/compose.js
index fe39486a0e0..e916a81de08 100644
--- a/static/js/compose.js
+++ b/static/js/compose.js
@@ -9,6 +9,7 @@ const render_compose_invite_users = require("../templates/compose_invite_users.h
const render_compose_not_subscribed = require("../templates/compose_not_subscribed.hbs");
const render_compose_private_stream_alert = require("../templates/compose_private_stream_alert.hbs");
+const channel = require("./channel");
const common = require("./common");
const compose_pm_pill = require("./compose_pm_pill");
const drafts = require("./drafts");
diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js
index 109105f4192..009c978d220 100644
--- a/static/js/compose_actions.js
+++ b/static/js/compose_actions.js
@@ -4,6 +4,7 @@ const autosize = require("autosize");
const fenced_code = require("../shared/js/fenced_code");
+const channel = require("./channel");
const common = require("./common");
const compose_pm_pill = require("./compose_pm_pill");
const drafts = require("./drafts");
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 1d9ad3dbbbf..45d7a9d64a5 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -9,6 +9,7 @@ const pygments_data = require("../generated/pygments_data.json");
const emoji = require("../shared/js/emoji");
const typeahead = require("../shared/js/typeahead");
+const channel = require("./channel");
const compose_pm_pill = require("./compose_pm_pill");
const people = require("./people");
const settings_data = require("./settings_data");
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index d45010d9f41..39f8d5ce98d 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -14,7 +14,6 @@ declare let blueslip: any;
declare let bot_data: any;
declare let buddy_data: any;
declare let buddy_list: any;
-declare let channel: any;
declare let click_handlers: any;
declare let color_data: any;
declare let compose: any;
diff --git a/static/js/hotspots.js b/static/js/hotspots.js
index d96d75eeb66..e3e79a91d54 100644
--- a/static/js/hotspots.js
+++ b/static/js/hotspots.js
@@ -6,6 +6,8 @@ const render_hotspot_icon = require("../templates/hotspot_icon.hbs");
const render_hotspot_overlay = require("../templates/hotspot_overlay.hbs");
const render_intro_reply_hotspot = require("../templates/intro_reply_hotspot.hbs");
+const channel = require("./channel");
+
// popover orientations
const TOP = "top";
const LEFT = "left";
diff --git a/static/js/invite.js b/static/js/invite.js
index 7513d6a0b5a..cc2a1cc672c 100644
--- a/static/js/invite.js
+++ b/static/js/invite.js
@@ -6,6 +6,7 @@ import render_invitation_failed_error from "../templates/invitation_failed_error
import render_invite_subscription from "../templates/invite_subscription.hbs";
import render_settings_dev_env_email_access from "../templates/settings/dev_env_email_access.hbs";
+import * as channel from "./channel";
import * as common from "./common";
function reset_error_messages() {
diff --git a/static/js/message_edit.js b/static/js/message_edit.js
index 5009b465e62..8eac9cce8ac 100644
--- a/static/js/message_edit.js
+++ b/static/js/message_edit.js
@@ -5,6 +5,7 @@ const ClipboardJS = require("clipboard");
const render_message_edit_form = require("../templates/message_edit_form.hbs");
const render_topic_edit_form = require("../templates/topic_edit_form.hbs");
+const channel = require("./channel");
const echo = require("./echo");
const loading = require("./loading");
diff --git a/static/js/message_edit_history.js b/static/js/message_edit_history.js
index c61f59375c9..f3c644c602e 100644
--- a/static/js/message_edit_history.js
+++ b/static/js/message_edit_history.js
@@ -1,5 +1,6 @@
import render_message_edit_history from "../templates/message_edit_history.hbs";
+import * as channel from "./channel";
import * as people from "./people";
const {format, isSameDay} = require("date-fns");
diff --git a/static/js/message_events.js b/static/js/message_events.js
index 501823b8b18..1c1a29d574c 100644
--- a/static/js/message_events.js
+++ b/static/js/message_events.js
@@ -1,6 +1,7 @@
"use strict";
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 util = require("./util");
diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js
index c80061df349..bcc074dd585 100644
--- a/static/js/message_fetch.js
+++ b/static/js/message_fetch.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const huddle_data = require("./huddle_data");
const people = require("./people");
diff --git a/static/js/message_flags.js b/static/js/message_flags.js
index d4c36a8c745..5a5c43c100d 100644
--- a/static/js/message_flags.js
+++ b/static/js/message_flags.js
@@ -2,6 +2,8 @@
const _ = require("lodash");
+const channel = require("./channel");
+
function send_flag_update(message, flag, op) {
channel.post({
url: "/json/messages/flags",
diff --git a/static/js/muting_ui.js b/static/js/muting_ui.js
index 847398e9de3..84ad7684327 100644
--- a/static/js/muting_ui.js
+++ b/static/js/muting_ui.js
@@ -3,6 +3,7 @@
const render_muted_topic_ui_row = require("../templates/muted_topic_ui_row.hbs");
const render_topic_muted = require("../templates/topic_muted.hbs");
+const channel = require("./channel");
const feedback_widget = require("./feedback_widget");
const settings_muting = require("./settings_muting");
diff --git a/static/js/narrow.js b/static/js/narrow.js
index 48e8142da08..8e78fa27465 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const {MessageListData} = require("./message_list_data");
const people = require("./people");
const search_pill = require("./search_pill");
diff --git a/static/js/notifications.js b/static/js/notifications.js
index d2aa64c1caa..498f4199b61 100644
--- a/static/js/notifications.js
+++ b/static/js/notifications.js
@@ -6,6 +6,7 @@ const render_compose_notification = require("../templates/compose_notification.h
const render_notification = require("../templates/notification.hbs");
const alert_words = require("./alert_words");
+const channel = require("./channel");
const favicon = require("./favicon");
const people = require("./people");
const settings_config = require("./settings_config");
diff --git a/static/js/portico/email_log.js b/static/js/portico/email_log.js
index daedc8fc8d7..2bacacf03d9 100644
--- a/static/js/portico/email_log.js
+++ b/static/js/portico/email_log.js
@@ -1,3 +1,5 @@
+import * as channel from "../channel";
+
$(() => {
// This code will be executed when the user visits /emails in
// development mode and email_log.html is rendered.
@@ -43,4 +45,3 @@ $(() => {
});
});
});
-export {};
diff --git a/static/js/portico/integrations_dev_panel.js b/static/js/portico/integrations_dev_panel.js
index f2ddb504c57..73bb25061c4 100644
--- a/static/js/portico/integrations_dev_panel.js
+++ b/static/js/portico/integrations_dev_panel.js
@@ -1,3 +1,4 @@
+import * as channel from "../channel";
// Main JavaScript file for the integrations development panel at
// /devtools/integrations.
@@ -373,4 +374,3 @@ $(() => {
$("#topic_name").on("change", update_url);
});
-export {};
diff --git a/static/js/reactions.js b/static/js/reactions.js
index 27e1b095c4e..ddfa36ec6dd 100644
--- a/static/js/reactions.js
+++ b/static/js/reactions.js
@@ -5,6 +5,7 @@ const _ = require("lodash");
const emoji = require("../shared/js/emoji");
const render_message_reaction = require("../templates/message_reaction.hbs");
+const channel = require("./channel");
const people = require("./people");
exports.view = {}; // function namespace
diff --git a/static/js/realm_icon.js b/static/js/realm_icon.js
index 7bf2bd5b63b..be0bd691f97 100644
--- a/static/js/realm_icon.js
+++ b/static/js/realm_icon.js
@@ -1,5 +1,7 @@
"use strict";
+const channel = require("./channel");
+
exports.build_realm_icon_widget = function (upload_function) {
const get_file_input = function () {
return $("#realm-icon-upload-widget .image_file_input").expectOne();
diff --git a/static/js/realm_logo.js b/static/js/realm_logo.js
index 58c8bc9dfc1..ff78955a0ea 100644
--- a/static/js/realm_logo.js
+++ b/static/js/realm_logo.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const settings_config = require("./settings_config");
exports.build_realm_logo_widget = function (upload_function, is_night) {
diff --git a/static/js/reminder.js b/static/js/reminder.js
index 18f5f62f8d4..74ae7c38ea6 100644
--- a/static/js/reminder.js
+++ b/static/js/reminder.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const people = require("./people");
const util = require("./util");
diff --git a/static/js/sent_messages.js b/static/js/sent_messages.js
index 00bd22335db..c879567f5e5 100644
--- a/static/js/sent_messages.js
+++ b/static/js/sent_messages.js
@@ -1,5 +1,7 @@
"use strict";
+const channel = require("./channel");
+
exports.messages = new Map();
exports.reset_id_state = function () {
@@ -118,7 +120,7 @@ exports.start_tracking_message = function (opts) {
const state = new exports.MessageState(opts);
exports.messages.set(local_id, state);
-}
+};
exports.get_message_state = function (local_id) {
const state = exports.messages.get(local_id);
diff --git a/static/js/server_events.js b/static/js/server_events.js
index 7b607782b39..b125e44052a 100644
--- a/static/js/server_events.js
+++ b/static/js/server_events.js
@@ -2,6 +2,7 @@
const _ = require("lodash");
+const channel = require("./channel");
const echo = require("./echo");
const server_events_dispatch = require("./server_events_dispatch");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
diff --git a/static/js/settings_account.js b/static/js/settings_account.js
index 7ec2e889b31..fe01f1c654a 100644
--- a/static/js/settings_account.js
+++ b/static/js/settings_account.js
@@ -6,6 +6,7 @@ const render_settings_api_key_modal = require("../templates/settings/api_key_mod
const render_settings_custom_user_profile_field = require("../templates/settings/custom_user_profile_field.hbs");
const render_settings_dev_env_email_access = require("../templates/settings/dev_env_email_access.hbs");
+const channel = require("./channel");
const common = require("./common");
const people = require("./people");
const pill_typeahead = require("./pill_typeahead");
diff --git a/static/js/settings_bots.js b/static/js/settings_bots.js
index ed61bb8b00a..9007fff7bf6 100644
--- a/static/js/settings_bots.js
+++ b/static/js/settings_bots.js
@@ -7,6 +7,7 @@ const render_edit_bot = require("../templates/edit_bot.hbs");
const render_settings_edit_embedded_bot_service = require("../templates/settings/edit_embedded_bot_service.hbs");
const render_settings_edit_outgoing_webhook_service = require("../templates/settings/edit_outgoing_webhook_service.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const people = require("./people");
diff --git a/static/js/settings_display.js b/static/js/settings_display.js
index 78b4c83594d..6dd27af39e5 100644
--- a/static/js/settings_display.js
+++ b/static/js/settings_display.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const emojisets = require("./emojisets");
const loading = require("./loading");
const settings_config = require("./settings_config");
diff --git a/static/js/settings_emoji.js b/static/js/settings_emoji.js
index 0d4ca0584cd..ba1e67bf671 100644
--- a/static/js/settings_emoji.js
+++ b/static/js/settings_emoji.js
@@ -4,6 +4,7 @@ const emoji = require("../shared/js/emoji");
const render_admin_emoji_list = require("../templates/admin_emoji_list.hbs");
const render_settings_emoji_settings_tip = require("../templates/settings/emoji_settings_tip.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const people = require("./people");
diff --git a/static/js/settings_exports.js b/static/js/settings_exports.js
index dfa8d604a75..c0bdabb6507 100644
--- a/static/js/settings_exports.js
+++ b/static/js/settings_exports.js
@@ -2,6 +2,7 @@
const render_admin_export_list = require("../templates/admin_export_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const people = require("./people");
diff --git a/static/js/settings_invites.js b/static/js/settings_invites.js
index 25a5b4c07e4..ac57b3da73e 100644
--- a/static/js/settings_invites.js
+++ b/static/js/settings_invites.js
@@ -3,6 +3,7 @@
const render_admin_invites_list = require("../templates/admin_invites_list.hbs");
const render_settings_revoke_invite_modal = require("../templates/settings/revoke_invite_modal.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const people = require("./people");
const settings_config = require("./settings_config");
diff --git a/static/js/settings_linkifiers.js b/static/js/settings_linkifiers.js
index d35e5caeb10..18ae56a0f3e 100644
--- a/static/js/settings_linkifiers.js
+++ b/static/js/settings_linkifiers.js
@@ -2,6 +2,7 @@
const render_admin_filter_list = require("../templates/admin_filter_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const meta = {
diff --git a/static/js/settings_notifications.js b/static/js/settings_notifications.js
index 900aeb1a94b..0f042aa033d 100644
--- a/static/js/settings_notifications.js
+++ b/static/js/settings_notifications.js
@@ -2,6 +2,7 @@
const render_stream_specific_notification_row = require("../templates/settings/stream_specific_notification_row.hbs");
+const channel = require("./channel");
const settings_config = require("./settings_config");
const settings_ui = require("./settings_ui");
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index a1d0f5061da..c4a0042a9c8 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -4,6 +4,7 @@ const pygments_data = require("../generated/pygments_data.json");
const render_settings_admin_auth_methods_list = require("../templates/settings/admin_auth_methods_list.hbs");
const render_settings_admin_realm_domains_list = require("../templates/settings/admin_realm_domains_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const settings_config = require("./settings_config");
const settings_ui = require("./settings_ui");
diff --git a/static/js/settings_profile_fields.js b/static/js/settings_profile_fields.js
index 36d77647c26..2ba3945a5df 100644
--- a/static/js/settings_profile_fields.js
+++ b/static/js/settings_profile_fields.js
@@ -5,6 +5,7 @@ const {default: Sortable} = require("sortablejs");
const render_admin_profile_field_list = require("../templates/admin_profile_field_list.hbs");
const render_settings_profile_field_choice = require("../templates/settings/profile_field_choice.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const settings_ui = require("./settings_ui");
diff --git a/static/js/settings_streams.js b/static/js/settings_streams.js
index 6e16c1a34a8..ebad9755692 100644
--- a/static/js/settings_streams.js
+++ b/static/js/settings_streams.js
@@ -2,6 +2,7 @@
const render_admin_default_streams_list = require("../templates/admin_default_streams_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const meta = {
diff --git a/static/js/settings_user_groups.js b/static/js/settings_user_groups.js
index 492a3fc4c3c..aaa5102047c 100644
--- a/static/js/settings_user_groups.js
+++ b/static/js/settings_user_groups.js
@@ -5,6 +5,7 @@ const _ = require("lodash");
const render_admin_user_group_list = require("../templates/admin_user_group_list.hbs");
const render_confirm_delete_user = require("../templates/confirm_delete_user.hbs");
+const channel = require("./channel");
const people = require("./people");
const pill_typeahead = require("./pill_typeahead");
const user_pill = require("./user_pill");
diff --git a/static/js/settings_users.js b/static/js/settings_users.js
index f4fd6f39831..99c98e101ea 100644
--- a/static/js/settings_users.js
+++ b/static/js/settings_users.js
@@ -4,6 +4,7 @@ const render_admin_bot_form = require("../templates/admin_bot_form.hbs");
const render_admin_human_form = require("../templates/admin_human_form.hbs");
const render_admin_user_list = require("../templates/admin_user_list.hbs");
+const channel = require("./channel");
const loading = require("./loading");
const people = require("./people");
const settings_config = require("./settings_config");
diff --git a/static/js/stream_create.js b/static/js/stream_create.js
index e2456cb4004..67bb5dbb28b 100644
--- a/static/js/stream_create.js
+++ b/static/js/stream_create.js
@@ -2,6 +2,7 @@ import render_announce_stream_docs from "../templates/announce_stream_docs.hbs";
import render_new_stream_users from "../templates/new_stream_users.hbs";
import render_subscription_invites_warning_modal from "../templates/subscription_invites_warning_modal.hbs";
+import * as channel from "./channel";
import * as loading from "./loading";
import * as peer_data from "./peer_data";
import * as people from "./people";
diff --git a/static/js/stream_edit.js b/static/js/stream_edit.js
index e541da2fd44..5affac9bc5e 100644
--- a/static/js/stream_edit.js
+++ b/static/js/stream_edit.js
@@ -6,6 +6,7 @@ const render_stream_subscription_info = require("../templates/stream_subscriptio
const render_subscription_settings = require("../templates/subscription_settings.hbs");
const render_subscription_stream_privacy_modal = require("../templates/subscription_stream_privacy_modal.hbs");
+const channel = require("./channel");
const peer_data = require("./peer_data");
const people = require("./people");
const pill_typeahead = require("./pill_typeahead");
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 6e3f69522c4..07423f60535 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -8,6 +8,8 @@ const render_stream_sidebar_actions = require("../templates/stream_sidebar_actio
const render_topic_sidebar_actions = require("../templates/topic_sidebar_actions.hbs");
const render_unstar_messages_modal = require("../templates/unstar_messages_modal.hbs");
+const channel = require("./channel");
+
// We handle stream popovers and topic popovers in this
// module. Both are popped up from the left sidebar.
let current_stream_sidebar_elem;
diff --git a/static/js/stream_topic_history.js b/static/js/stream_topic_history.js
index 43e00fcae7d..11199d18c68 100644
--- a/static/js/stream_topic_history.js
+++ b/static/js/stream_topic_history.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const {FoldDict} = require("./fold_dict");
const stream_dict = new Map(); // stream_id -> PerStreamHistory object
diff --git a/static/js/submessage.js b/static/js/submessage.js
index 1cef93d8edd..43dea6b0584 100644
--- a/static/js/submessage.js
+++ b/static/js/submessage.js
@@ -1,5 +1,7 @@
"use strict";
+const channel = require("./channel");
+
exports.get_message_events = function (message) {
if (message.locally_echoed) {
return undefined;
diff --git a/static/js/subs.js b/static/js/subs.js
index 0008bda03b4..45d93e3dbf9 100644
--- a/static/js/subs.js
+++ b/static/js/subs.js
@@ -7,6 +7,7 @@ const render_subscription_settings = require("../templates/subscription_settings
const render_subscription_table_body = require("../templates/subscription_table_body.hbs");
const render_subscriptions = require("../templates/subscriptions.hbs");
+const channel = require("./channel");
const components = require("./components");
const loading = require("./loading");
const people = require("./people");
diff --git a/static/js/transmit.js b/static/js/transmit.js
index c2401331169..1f553d492ae 100644
--- a/static/js/transmit.js
+++ b/static/js/transmit.js
@@ -1,5 +1,6 @@
"use strict";
+const channel = require("./channel");
const people = require("./people");
exports.send_message = function (request, on_success, error) {
diff --git a/static/js/tutorial.js b/static/js/tutorial.js
index 97c193b255c..14196b04510 100644
--- a/static/js/tutorial.js
+++ b/static/js/tutorial.js
@@ -1,3 +1,5 @@
+import * as channel from "./channel";
+
function set_tutorial_status(status, callback) {
return channel.post({
url: "/json/users/me/tutorial_status",
diff --git a/static/js/typing.js b/static/js/typing.js
index 81e95c89f38..c7dba30f1d0 100644
--- a/static/js/typing.js
+++ b/static/js/typing.js
@@ -1,5 +1,6 @@
import * as typing_status from "../shared/js/typing_status";
+import * as channel from "./channel";
import * as compose_pm_pill from "./compose_pm_pill";
import * as people from "./people";
diff --git a/static/js/unread_ops.js b/static/js/unread_ops.js
index 9379104608c..44baf9c1f2d 100644
--- a/static/js/unread_ops.js
+++ b/static/js/unread_ops.js
@@ -1,5 +1,7 @@
"use strict";
+const channel = require("./channel");
+
exports.mark_all_as_read = function () {
unread.declare_bankruptcy();
unread_ui.update_unread_counts();
diff --git a/static/js/user_status.js b/static/js/user_status.js
index c33812efa3a..624adb68086 100644
--- a/static/js/user_status.js
+++ b/static/js/user_status.js
@@ -1,3 +1,5 @@
+import * as channel from "./channel";
+
const away_user_ids = new Set();
const user_info = new Map();
diff --git a/static/js/zcommand.js b/static/js/zcommand.js
index d451f1b8fc6..f43f2c8f71d 100644
--- a/static/js/zcommand.js
+++ b/static/js/zcommand.js
@@ -1,5 +1,6 @@
import marked from "../third/marked/lib/marked";
+import * as channel from "./channel";
import * as common from "./common";
import * as feedback_widget from "./feedback_widget";