Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/muting_ui.js to ES6 module.
Anders Kaseorg6e045e44700e
diff --git a/.eslintrc.json b/.eslintrc.jsonindex fd207b9e3ec..1064fafbde0 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -181,7 +181,6 @@"message_store": false,"message_util": false,"message_viewport": false,- "muting_ui": false,"narrow": false,"narrow_state": false,"navigate": false,diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex 34b3546ca5b..ce010fae443 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.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");@@ -32,7 +34,8 @@ const markdown = set_global("markdown", {});const message_edit = set_global("message_edit", {});const message_events = set_global("message_events", {});const message_list = set_global("message_list", {});-const muting_ui = set_global("muting_ui", {});+const muting_ui = {__esModule: true};+rewiremock("../../static/js/muting_ui").with(muting_ui);const night_mode = set_global("night_mode", {});const notifications = set_global("notifications", {});const reactions = set_global("reactions", {});@@ -69,6 +72,8 @@ const page_params = set_global("page_params", {realm_description: "already set description",});+rewiremock.enable();+// For data-oriented modules, just use them, don't stub them.const alert_words = zrequire("alert_words");zrequire("unread");@@ -851,3 +856,4 @@ run_test("realm_export", (override) => {const args = stub.get_args("exports");assert.equal(args.exports, event.exports);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/hotkey.js b/frontend_tests/node_tests/hotkey.jsindex ea6f8beece1..f0e7ba8bc5e 100644--- a/frontend_tests/node_tests/hotkey.js+++ b/frontend_tests/node_tests/hotkey.js@@ -76,7 +76,8 @@ set_global("info_overlay", {});const lightbox = set_global("lightbox", {});const list_util = set_global("list_util", {});const message_edit = set_global("message_edit", {});-const muting_ui = set_global("muting_ui", {});+const muting_ui = {__esModule: true};+rewiremock("../../static/js/muting_ui").with(muting_ui);const narrow = set_global("narrow", {});const navigate = set_global("navigate", {});const reactions = set_global("reactions", {});diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.jsindex 32095d75126..97e106ccbf7 100644--- a/frontend_tests/node_tests/settings_muting.js+++ b/frontend_tests/node_tests/settings_muting.js@@ -2,11 +2,16 @@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 $ = require("../zjsunit/zjquery");-const muting_ui = set_global("muting_ui", {});+const muting_ui = {__esModule: true};++rewiremock("../../static/js/muting_ui").with(muting_ui);+rewiremock.enable();zrequire("timerender");const settings_muting = zrequire("settings_muting");@@ -88,3 +93,4 @@ run_test("reset", () => {settings_muting.reset();assert.equal(settings_muting.loaded, false);});+rewiremock.disable();diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex f7fdb08bb6a..8bbdb5eff0a 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -18,7 +18,6 @@ import "../fold_dict";import "../input_pill";import "../setup";import "../unread_ops";-import "../muting_ui";import "../message_viewport";import "../rows";import "../user_groups";diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex d813aebc315..2d1998d6986 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -10,6 +10,7 @@ const render_buddy_list_tooltip_content = require("../templates/buddy_list_tooltconst channel = require("./channel");const message_edit_history = require("./message_edit_history");+const muting_ui = require("./muting_ui");const settings_panel_menu = require("./settings_panel_menu");const user_status_ui = require("./user_status_ui");const util = require("./util");diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 843c8c2fc81..9c7e0504cb7 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -55,7 +55,6 @@ declare let message_scroll: any;declare let message_store: any;declare let message_util: any;declare let message_viewport: any;-declare let muting_ui: any;declare let narrow: any;declare let narrow_state: any;declare let navigate: any;diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex 92c5ad20358..2c02917fa32 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -6,6 +6,7 @@ const common = require("./common");const copy_and_paste = require("./copy_and_paste");const drafts = require("./drafts");const feedback_widget = require("./feedback_widget");+const muting_ui = require("./muting_ui");const topic_zoom = require("./topic_zoom");function do_narrow_action(action) {diff --git a/static/js/muting_ui.js b/static/js/muting_ui.jsindex 6d5c8090628..eb9242ddeca 100644--- a/static/js/muting_ui.js+++ b/static/js/muting_ui.js@@ -1,13 +1,11 @@-"use strict";+import render_muted_topic_ui_row from "../templates/muted_topic_ui_row.hbs";+import render_topic_muted from "../templates/topic_muted.hbs";-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 muting = require("./muting");-const settings_muting = require("./settings_muting");-const unread_ui = require("./unread_ui");+import * as channel from "./channel";+import * as feedback_widget from "./feedback_widget";+import * as muting from "./muting";+import * as settings_muting from "./settings_muting";+import * as unread_ui from "./unread_ui";function timestamp_ms() {return Date.now();@@ -15,7 +13,7 @@ function timestamp_ms() {let last_topic_update = 0;-exports.rerender_on_topic_update = function () {+export function rerender_on_topic_update() {// Note: We tend to optimistically rerender muting preferences before// the backend actually acknowledges the mute. This gives a more// immediate feel to the user, and if the backend fails temporarily,@@ -29,11 +27,11 @@ exports.rerender_on_topic_update = function () {home_msg_list.update_muting_and_rerender();}if (overlays.settings_open() && settings_muting.loaded) {- exports.set_up_muted_topics_ui();+ set_up_muted_topics_ui();}-};+}-exports.persist_topic_mute = function (stream_id, topic_name) {+export function persist_topic_mute(stream_id, topic_name) {const data = {stream_id,topic: topic_name,@@ -45,9 +43,9 @@ exports.persist_topic_mute = function (stream_id, topic_name) {idempotent: true,data,});-};+}-exports.persist_topic_unmute = function (stream_id, topic_name) {+export function persist_topic_unmute(stream_id, topic_name) {const data = {stream_id,topic: topic_name,@@ -59,9 +57,9 @@ exports.persist_topic_unmute = function (stream_id, topic_name) {idempotent: true,data,});-};+}-exports.handle_topic_updates = function (muted_topics) {+export function handle_topic_updates(muted_topics) {if (timestamp_ms() < last_topic_update + 1000) {// This topic update is either the one that we just rendered, or,// much less likely, it's coming from another device and would probably@@ -69,16 +67,16 @@ exports.handle_topic_updates = function (muted_topics) {return;}- exports.update_muted_topics(muted_topics);- exports.rerender_on_topic_update();-};+ update_muted_topics(muted_topics);+ rerender_on_topic_update();+}-exports.update_muted_topics = function (muted_topics) {+export function update_muted_topics(muted_topics) {muting.set_muted_topics(muted_topics);unread_ui.update_unread_counts();-};+}-exports.set_up_muted_topics_ui = function () {+export function set_up_muted_topics_ui() {const muted_topics = muting.get_muted_topics();const muted_topics_table = $("#muted_topics_table");const $search_input = $("#muted_topics_search");@@ -100,16 +98,16 @@ exports.set_up_muted_topics_ui = function () {parent_container: $("#muted-topic-settings"),simplebar_container: $("#muted-topic-settings .progressive-table-wrapper"),});-};+}-exports.mute_topic = function (stream_id, topic) {+export function mute_topic(stream_id, topic) {const stream_name = stream_data.maybe_get_stream_name(stream_id);stream_popover.hide_topic_popover();muting.add_muted_topic(stream_id, topic);unread_ui.update_unread_counts();- exports.rerender_on_topic_update();- exports.persist_topic_mute(stream_id, topic);+ rerender_on_topic_update();+ persist_topic_mute(stream_id, topic);feedback_widget.show({populate(container) {const rendered_html = render_topic_muted();@@ -118,36 +116,34 @@ exports.mute_topic = function (stream_id, topic) {container.find(".topic").text(topic);},on_undo() {- exports.unmute_topic(stream_id, topic);+ unmute_topic(stream_id, topic);},title_text: i18n.t("Topic muted"),undo_button_text: i18n.t("Unmute"),});recent_topics.update_topic_is_muted(stream_id, topic);-};+}-exports.unmute_topic = function (stream_id, topic) {+export function unmute_topic(stream_id, topic) {// we don't run a unmute_notify function because it isn't an issue as much// if someone accidentally unmutes a stream rather than if they mute it// and miss out on info.stream_popover.hide_topic_popover();muting.remove_muted_topic(stream_id, topic);unread_ui.update_unread_counts();- exports.rerender_on_topic_update();- exports.persist_topic_unmute(stream_id, topic);+ rerender_on_topic_update();+ persist_topic_unmute(stream_id, topic);feedback_widget.dismiss();recent_topics.update_topic_is_muted(stream_id, topic);-};+}-exports.toggle_topic_mute = function (message) {+export function toggle_topic_mute(message) {const stream_id = message.stream_id;const topic = message.topic;if (muting.is_topic_muted(stream_id, topic)) {- exports.unmute_topic(stream_id, topic);+ unmute_topic(stream_id, topic);} else if (message.type === "stream") {- exports.mute_topic(stream_id, topic);+ mute_topic(stream_id, topic);}-};--window.muting_ui = exports;+}diff --git a/static/js/popovers.js b/static/js/popovers.jsindex fe9f1b12c06..5a3269f5b0d 100644--- a/static/js/popovers.js+++ b/static/js/popovers.js@@ -19,6 +19,7 @@ const render_user_profile_modal = require("../templates/user_profile_modal.hbs")const feature_flags = require("./feature_flags");const message_edit_history = require("./message_edit_history");const muting = require("./muting");+const muting_ui = require("./muting_ui");const people = require("./people");const settings_config = require("./settings_config");const settings_data = require("./settings_data");diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex c17316a4f5d..ef730c004c9 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -1,6 +1,7 @@import * as emoji from "../shared/js/emoji";import * as alert_words from "./alert_words";+import * as muting_ui from "./muting_ui";import * as peer_data from "./peer_data";import * as people from "./people";import * as settings_config from "./settings_config";diff --git a/static/js/settings_muting.js b/static/js/settings_muting.jsindex 6b882fefb4a..9196778d404 100644--- a/static/js/settings_muting.js+++ b/static/js/settings_muting.js@@ -1,3 +1,5 @@+import * as muting_ui from "./muting_ui";+export let loaded = false;export function set_up() {diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex 81602025507..849c6208963 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -10,6 +10,7 @@ const render_unstar_messages_modal = require("../templates/unstar_messages_modalconst channel = require("./channel");const muting = require("./muting");+const muting_ui = require("./muting_ui");// We handle stream popovers and topic popovers in this// module. Both are popped up from the left sidebar.