Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/stream_events.js to ES6 module.
Anders Kaseorg72ffb335891b
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 7b66ac4134a..8b9212beb17 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -213,7 +213,6 @@"settings_users": false,"starred_messages": false,"stream_edit": false,- "stream_events": false,"stream_list": false,"stream_popover": false,"StripeCheckout": false,diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex d4d0102d4f8..fb17d90f900 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.js@@ -60,7 +60,8 @@ const settings_user_groups = set_global("settings_user_groups", {});const settings_users = set_global("settings_users", {});const stream_data = {__esModule: true};rewiremock("../../static/js/stream_data").with(stream_data);-const stream_events = set_global("stream_events", {});+const stream_events = {__esModule: true};+rewiremock("../../static/js/stream_events").with(stream_events);const submessage = {__esModule: true};rewiremock("../../static/js/submessage").with(submessage);const typing_events = set_global("typing_events", {});diff --git a/frontend_tests/node_tests/dispatch_subs.js b/frontend_tests/node_tests/dispatch_subs.jsindex 544b226ac6e..40b0a70edfb 100644--- a/frontend_tests/node_tests/dispatch_subs.js+++ b/frontend_tests/node_tests/dispatch_subs.js@@ -15,7 +15,8 @@ const test_user = events.test_user;const compose_fade = {__esModule: true};rewiremock("../../static/js/compose_fade").with(compose_fade);-const stream_events = set_global("stream_events", {});+const stream_events = {__esModule: true};+rewiremock("../../static/js/stream_events").with(stream_events);const subs = set_global("subs", {});rewiremock.enable();diff --git a/frontend_tests/node_tests/server_events.js b/frontend_tests/node_tests/server_events.jsindex e04eb1771ec..dbdca0ce9f9 100644--- a/frontend_tests/node_tests/server_events.js+++ b/frontend_tests/node_tests/server_events.js@@ -93,7 +93,7 @@ const setup = () => {throw new Error("update error");},});- set_global("stream_events", {+ rewiremock("../../static/js/stream_events").with({update_property() {throw new Error("subs update error");},diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex c65e9ecb46b..fd9281ed765 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -25,7 +25,6 @@ import "../message_list";import "../narrow";import "../reload";import "../compose_actions";-import "../stream_events";import "../stream_edit";import "../subs";import "../message_edit";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 9d007bcf892..47b0d40d66d 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -86,7 +86,6 @@ declare let settings_user_groups: any;declare let settings_users: any;declare let starred_messages: any;declare let stream_edit: any;-declare let stream_events: any;declare let stream_list: any;declare let stream_popover: any;declare let subs: any;diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex fee7802cdad..a8f986ab1b9 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -11,6 +11,7 @@ import * as people from "./people";import * as reload from "./reload";import * as settings_config from "./settings_config";import * as stream_data from "./stream_data";+import * as stream_events from "./stream_events";import * as stream_topic_history from "./stream_topic_history";import * as submessage from "./submessage";import * as user_groups from "./user_groups";diff --git a/static/js/stream_events.js b/static/js/stream_events.jsindex adc792b50fa..a25d9304381 100644--- a/static/js/stream_events.js+++ b/static/js/stream_events.js@@ -1,11 +1,9 @@-"use strict";--const color_data = require("./color_data");-const narrow_state = require("./narrow_state");-const peer_data = require("./peer_data");-const stream_color = require("./stream_color");-const stream_data = require("./stream_data");-const stream_muting = require("./stream_muting");+import * as color_data from "./color_data";+import * as narrow_state from "./narrow_state";+import * as peer_data from "./peer_data";+import * as stream_color from "./stream_color";+import * as stream_data from "./stream_data";+import * as stream_muting from "./stream_muting";// In theory, this function should apply the account-level defaults,// however, they are only called after a manual override, so@@ -17,7 +15,7 @@ function update_stream_setting(sub, value, setting) {sub[setting] = value;}-exports.update_property = function (stream_id, property, value, other_values) {+export function update_property(stream_id, property, value, other_values) {const sub = stream_data.get_sub_by_id(stream_id);if (sub === undefined) {// This isn't a stream we know about, so ignore it.@@ -76,12 +74,12 @@ exports.update_property = function (stream_id, property, value, other_values) {value,});}-};+}// Add yourself to a stream we already know about client-side.// It's likely we should be passing in the full sub object from the caller/backend,// but for now we just pass in the subscribers and color (things likely to be different).-exports.mark_subscribed = function (sub, subscribers, color) {+export function mark_subscribed(sub, subscribers, color) {if (sub === undefined) {blueslip.error("Undefined sub passed to mark_subscribed");return;@@ -125,9 +123,9 @@ exports.mark_subscribed = function (sub, subscribers, color) {message_util.do_unread_count_updates(message_list.all.all_messages());stream_list.add_sidebar_row(sub);-};+}-exports.mark_unsubscribed = function (sub) {+export function mark_unsubscribed(sub) {if (sub === undefined) {// We don't know about this streamreturn;@@ -149,9 +147,9 @@ exports.mark_unsubscribed = function (sub) {}stream_list.remove_sidebar_row(sub.stream_id);-};+}-exports.remove_deactivated_user_from_all_streams = function (user_id) {+export function remove_deactivated_user_from_all_streams(user_id) {const all_subs = stream_data.get_unsorted_subs();for (const sub of all_subs) {@@ -160,6 +158,4 @@ exports.remove_deactivated_user_from_all_streams = function (user_id) {subs.update_subscribers_ui(sub);}}-};--window.stream_events = exports;+}