mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
js: Convert static/js/muting_ui.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
94a5da325c
commit
6e045e4470
@@ -181,7 +181,6 @@
|
|||||||
"message_store": false,
|
"message_store": false,
|
||||||
"message_util": false,
|
"message_util": false,
|
||||||
"message_viewport": false,
|
"message_viewport": false,
|
||||||
"muting_ui": false,
|
|
||||||
"narrow": false,
|
"narrow": false,
|
||||||
"narrow_state": false,
|
"narrow_state": false,
|
||||||
"navigate": false,
|
"navigate": false,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
const {strict: assert} = require("assert");
|
const {strict: assert} = require("assert");
|
||||||
|
|
||||||
|
const rewiremock = require("rewiremock/node");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||||
const {make_stub} = require("../zjsunit/stub");
|
const {make_stub} = require("../zjsunit/stub");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
@@ -32,7 +34,8 @@ const markdown = set_global("markdown", {});
|
|||||||
const message_edit = set_global("message_edit", {});
|
const message_edit = set_global("message_edit", {});
|
||||||
const message_events = set_global("message_events", {});
|
const message_events = set_global("message_events", {});
|
||||||
const message_list = set_global("message_list", {});
|
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 night_mode = set_global("night_mode", {});
|
||||||
const notifications = set_global("notifications", {});
|
const notifications = set_global("notifications", {});
|
||||||
const reactions = set_global("reactions", {});
|
const reactions = set_global("reactions", {});
|
||||||
@@ -69,6 +72,8 @@ const page_params = set_global("page_params", {
|
|||||||
realm_description: "already set description",
|
realm_description: "already set description",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rewiremock.enable();
|
||||||
|
|
||||||
// For data-oriented modules, just use them, don't stub them.
|
// For data-oriented modules, just use them, don't stub them.
|
||||||
const alert_words = zrequire("alert_words");
|
const alert_words = zrequire("alert_words");
|
||||||
zrequire("unread");
|
zrequire("unread");
|
||||||
@@ -851,3 +856,4 @@ run_test("realm_export", (override) => {
|
|||||||
const args = stub.get_args("exports");
|
const args = stub.get_args("exports");
|
||||||
assert.equal(args.exports, event.exports);
|
assert.equal(args.exports, event.exports);
|
||||||
});
|
});
|
||||||
|
rewiremock.disable();
|
||||||
|
|||||||
@@ -76,7 +76,8 @@ set_global("info_overlay", {});
|
|||||||
const lightbox = set_global("lightbox", {});
|
const lightbox = set_global("lightbox", {});
|
||||||
const list_util = set_global("list_util", {});
|
const list_util = set_global("list_util", {});
|
||||||
const message_edit = set_global("message_edit", {});
|
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 narrow = set_global("narrow", {});
|
||||||
const navigate = set_global("navigate", {});
|
const navigate = set_global("navigate", {});
|
||||||
const reactions = set_global("reactions", {});
|
const reactions = set_global("reactions", {});
|
||||||
|
|||||||
@@ -2,11 +2,16 @@
|
|||||||
|
|
||||||
const {strict: assert} = require("assert");
|
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 {run_test} = require("../zjsunit/test");
|
||||||
const $ = require("../zjsunit/zjquery");
|
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");
|
zrequire("timerender");
|
||||||
const settings_muting = zrequire("settings_muting");
|
const settings_muting = zrequire("settings_muting");
|
||||||
@@ -88,3 +93,4 @@ run_test("reset", () => {
|
|||||||
settings_muting.reset();
|
settings_muting.reset();
|
||||||
assert.equal(settings_muting.loaded, false);
|
assert.equal(settings_muting.loaded, false);
|
||||||
});
|
});
|
||||||
|
rewiremock.disable();
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import "../fold_dict";
|
|||||||
import "../input_pill";
|
import "../input_pill";
|
||||||
import "../setup";
|
import "../setup";
|
||||||
import "../unread_ops";
|
import "../unread_ops";
|
||||||
import "../muting_ui";
|
|
||||||
import "../message_viewport";
|
import "../message_viewport";
|
||||||
import "../rows";
|
import "../rows";
|
||||||
import "../user_groups";
|
import "../user_groups";
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const render_buddy_list_tooltip_content = require("../templates/buddy_list_toolt
|
|||||||
|
|
||||||
const channel = require("./channel");
|
const channel = require("./channel");
|
||||||
const message_edit_history = require("./message_edit_history");
|
const message_edit_history = require("./message_edit_history");
|
||||||
|
const muting_ui = require("./muting_ui");
|
||||||
const settings_panel_menu = require("./settings_panel_menu");
|
const settings_panel_menu = require("./settings_panel_menu");
|
||||||
const user_status_ui = require("./user_status_ui");
|
const user_status_ui = require("./user_status_ui");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|||||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -55,7 +55,6 @@ declare let message_scroll: any;
|
|||||||
declare let message_store: any;
|
declare let message_store: any;
|
||||||
declare let message_util: any;
|
declare let message_util: any;
|
||||||
declare let message_viewport: any;
|
declare let message_viewport: any;
|
||||||
declare let muting_ui: any;
|
|
||||||
declare let narrow: any;
|
declare let narrow: any;
|
||||||
declare let narrow_state: any;
|
declare let narrow_state: any;
|
||||||
declare let navigate: any;
|
declare let navigate: any;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const common = require("./common");
|
|||||||
const copy_and_paste = require("./copy_and_paste");
|
const copy_and_paste = require("./copy_and_paste");
|
||||||
const drafts = require("./drafts");
|
const drafts = require("./drafts");
|
||||||
const feedback_widget = require("./feedback_widget");
|
const feedback_widget = require("./feedback_widget");
|
||||||
|
const muting_ui = require("./muting_ui");
|
||||||
const topic_zoom = require("./topic_zoom");
|
const topic_zoom = require("./topic_zoom");
|
||||||
|
|
||||||
function do_narrow_action(action) {
|
function do_narrow_action(action) {
|
||||||
|
|||||||
@@ -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");
|
import * as channel from "./channel";
|
||||||
const render_topic_muted = require("../templates/topic_muted.hbs");
|
import * as feedback_widget from "./feedback_widget";
|
||||||
|
import * as muting from "./muting";
|
||||||
const channel = require("./channel");
|
import * as settings_muting from "./settings_muting";
|
||||||
const feedback_widget = require("./feedback_widget");
|
import * as unread_ui from "./unread_ui";
|
||||||
const muting = require("./muting");
|
|
||||||
const settings_muting = require("./settings_muting");
|
|
||||||
const unread_ui = require("./unread_ui");
|
|
||||||
|
|
||||||
function timestamp_ms() {
|
function timestamp_ms() {
|
||||||
return Date.now();
|
return Date.now();
|
||||||
@@ -15,7 +13,7 @@ function timestamp_ms() {
|
|||||||
|
|
||||||
let last_topic_update = 0;
|
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
|
// Note: We tend to optimistically rerender muting preferences before
|
||||||
// the backend actually acknowledges the mute. This gives a more
|
// the backend actually acknowledges the mute. This gives a more
|
||||||
// immediate feel to the user, and if the backend fails temporarily,
|
// 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();
|
home_msg_list.update_muting_and_rerender();
|
||||||
}
|
}
|
||||||
if (overlays.settings_open() && settings_muting.loaded) {
|
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 = {
|
const data = {
|
||||||
stream_id,
|
stream_id,
|
||||||
topic: topic_name,
|
topic: topic_name,
|
||||||
@@ -45,9 +43,9 @@ exports.persist_topic_mute = function (stream_id, topic_name) {
|
|||||||
idempotent: true,
|
idempotent: true,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.persist_topic_unmute = function (stream_id, topic_name) {
|
export function persist_topic_unmute(stream_id, topic_name) {
|
||||||
const data = {
|
const data = {
|
||||||
stream_id,
|
stream_id,
|
||||||
topic: topic_name,
|
topic: topic_name,
|
||||||
@@ -59,9 +57,9 @@ exports.persist_topic_unmute = function (stream_id, topic_name) {
|
|||||||
idempotent: true,
|
idempotent: true,
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.handle_topic_updates = function (muted_topics) {
|
export function handle_topic_updates(muted_topics) {
|
||||||
if (timestamp_ms() < last_topic_update + 1000) {
|
if (timestamp_ms() < last_topic_update + 1000) {
|
||||||
// This topic update is either the one that we just rendered, or,
|
// This topic update is either the one that we just rendered, or,
|
||||||
// much less likely, it's coming from another device and would probably
|
// much less likely, it's coming from another device and would probably
|
||||||
@@ -69,16 +67,16 @@ exports.handle_topic_updates = function (muted_topics) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.update_muted_topics(muted_topics);
|
update_muted_topics(muted_topics);
|
||||||
exports.rerender_on_topic_update();
|
rerender_on_topic_update();
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.update_muted_topics = function (muted_topics) {
|
export function update_muted_topics(muted_topics) {
|
||||||
muting.set_muted_topics(muted_topics);
|
muting.set_muted_topics(muted_topics);
|
||||||
unread_ui.update_unread_counts();
|
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 = muting.get_muted_topics();
|
||||||
const muted_topics_table = $("#muted_topics_table");
|
const muted_topics_table = $("#muted_topics_table");
|
||||||
const $search_input = $("#muted_topics_search");
|
const $search_input = $("#muted_topics_search");
|
||||||
@@ -100,16 +98,16 @@ exports.set_up_muted_topics_ui = function () {
|
|||||||
parent_container: $("#muted-topic-settings"),
|
parent_container: $("#muted-topic-settings"),
|
||||||
simplebar_container: $("#muted-topic-settings .progressive-table-wrapper"),
|
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);
|
const stream_name = stream_data.maybe_get_stream_name(stream_id);
|
||||||
|
|
||||||
stream_popover.hide_topic_popover();
|
stream_popover.hide_topic_popover();
|
||||||
muting.add_muted_topic(stream_id, topic);
|
muting.add_muted_topic(stream_id, topic);
|
||||||
unread_ui.update_unread_counts();
|
unread_ui.update_unread_counts();
|
||||||
exports.rerender_on_topic_update();
|
rerender_on_topic_update();
|
||||||
exports.persist_topic_mute(stream_id, topic);
|
persist_topic_mute(stream_id, topic);
|
||||||
feedback_widget.show({
|
feedback_widget.show({
|
||||||
populate(container) {
|
populate(container) {
|
||||||
const rendered_html = render_topic_muted();
|
const rendered_html = render_topic_muted();
|
||||||
@@ -118,36 +116,34 @@ exports.mute_topic = function (stream_id, topic) {
|
|||||||
container.find(".topic").text(topic);
|
container.find(".topic").text(topic);
|
||||||
},
|
},
|
||||||
on_undo() {
|
on_undo() {
|
||||||
exports.unmute_topic(stream_id, topic);
|
unmute_topic(stream_id, topic);
|
||||||
},
|
},
|
||||||
title_text: i18n.t("Topic muted"),
|
title_text: i18n.t("Topic muted"),
|
||||||
undo_button_text: i18n.t("Unmute"),
|
undo_button_text: i18n.t("Unmute"),
|
||||||
});
|
});
|
||||||
recent_topics.update_topic_is_muted(stream_id, topic);
|
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
|
// 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
|
// if someone accidentally unmutes a stream rather than if they mute it
|
||||||
// and miss out on info.
|
// and miss out on info.
|
||||||
stream_popover.hide_topic_popover();
|
stream_popover.hide_topic_popover();
|
||||||
muting.remove_muted_topic(stream_id, topic);
|
muting.remove_muted_topic(stream_id, topic);
|
||||||
unread_ui.update_unread_counts();
|
unread_ui.update_unread_counts();
|
||||||
exports.rerender_on_topic_update();
|
rerender_on_topic_update();
|
||||||
exports.persist_topic_unmute(stream_id, topic);
|
persist_topic_unmute(stream_id, topic);
|
||||||
feedback_widget.dismiss();
|
feedback_widget.dismiss();
|
||||||
recent_topics.update_topic_is_muted(stream_id, topic);
|
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 stream_id = message.stream_id;
|
||||||
const topic = message.topic;
|
const topic = message.topic;
|
||||||
|
|
||||||
if (muting.is_topic_muted(stream_id, 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") {
|
} else if (message.type === "stream") {
|
||||||
exports.mute_topic(stream_id, topic);
|
mute_topic(stream_id, topic);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
window.muting_ui = exports;
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ const render_user_profile_modal = require("../templates/user_profile_modal.hbs")
|
|||||||
const feature_flags = require("./feature_flags");
|
const feature_flags = require("./feature_flags");
|
||||||
const message_edit_history = require("./message_edit_history");
|
const message_edit_history = require("./message_edit_history");
|
||||||
const muting = require("./muting");
|
const muting = require("./muting");
|
||||||
|
const muting_ui = require("./muting_ui");
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const settings_config = require("./settings_config");
|
const settings_config = require("./settings_config");
|
||||||
const settings_data = require("./settings_data");
|
const settings_data = require("./settings_data");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as emoji from "../shared/js/emoji";
|
import * as emoji from "../shared/js/emoji";
|
||||||
|
|
||||||
import * as alert_words from "./alert_words";
|
import * as alert_words from "./alert_words";
|
||||||
|
import * as muting_ui from "./muting_ui";
|
||||||
import * as peer_data from "./peer_data";
|
import * as peer_data from "./peer_data";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as settings_config from "./settings_config";
|
import * as settings_config from "./settings_config";
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import * as muting_ui from "./muting_ui";
|
||||||
|
|
||||||
export let loaded = false;
|
export let loaded = false;
|
||||||
|
|
||||||
export function set_up() {
|
export function set_up() {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const render_unstar_messages_modal = require("../templates/unstar_messages_modal
|
|||||||
|
|
||||||
const channel = require("./channel");
|
const channel = require("./channel");
|
||||||
const muting = require("./muting");
|
const muting = require("./muting");
|
||||||
|
const muting_ui = require("./muting_ui");
|
||||||
|
|
||||||
// We handle stream popovers and topic popovers in this
|
// We handle stream popovers and topic popovers in this
|
||||||
// module. Both are popped up from the left sidebar.
|
// module. Both are popped up from the left sidebar.
|
||||||
|
|||||||
Reference in New Issue
Block a user