Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/message_list.js to ES6 module.
Anders Kaseorg7a67c06581be
diff --git a/.eslintrc.json b/.eslintrc.jsonindex c7b67f321c5..04c420ec80c 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -141,7 +141,6 @@"localStorage": false,"location": false,"message_events": false,- "message_list": false,"narrow": false,"page_params": false,"pointer": false,diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex ce9298631e5..2454cd4c34a 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.js@@ -41,7 +41,8 @@ rewiremock("../../static/js/markdown").with(markdown);const message_edit = {__esModule: true};rewiremock("../../static/js/message_edit").with(message_edit);const message_events = set_global("message_events", {});-const message_list = set_global("message_list", {});+const message_list = {__esModule: true};+rewiremock("../../static/js/message_list").with(message_list);const muting_ui = {__esModule: true};rewiremock("../../static/js/muting_ui").with(muting_ui);const night_mode = {__esModule: true};diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.jsindex de9240ea4ac..254dc423b50 100644--- a/frontend_tests/node_tests/echo.js+++ b/frontend_tests/node_tests/echo.js@@ -43,7 +43,7 @@ set_global("home_msg_list", {},});-set_global("message_list", {});+rewiremock("../../static/js/message_list").with({});set_global("current_msg_list", "");diff --git a/frontend_tests/node_tests/message_events.js b/frontend_tests/node_tests/message_events.jsindex 3d3da7bbd64..97e192278ed 100644--- a/frontend_tests/node_tests/message_events.js+++ b/frontend_tests/node_tests/message_events.js@@ -12,7 +12,8 @@ rewiremock("../../static/js/condense").with(condense);set_global("current_msg_list", {});const message_edit = {__esModule: true};rewiremock("../../static/js/message_edit").with(message_edit);-const message_list = set_global("message_list", {});+const message_list = {__esModule: true};+rewiremock("../../static/js/message_list").with(message_list);const notifications = {__esModule: true};rewiremock("../../static/js/notifications").with(notifications);const page_params = set_global("page_params", {});diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.jsindex c58607c33b5..72800c2ee3e 100644--- a/frontend_tests/node_tests/message_fetch.js+++ b/frontend_tests/node_tests/message_fetch.js@@ -94,7 +94,7 @@ function make_all_list() {function reset_lists() {set_global("home_msg_list", make_home_msg_list());set_global("current_msg_list", home_msg_list);- message_list.all = make_all_list();+ message_list.__Rewire__("all", make_all_list());stub_message_view(home_msg_list);stub_message_view(message_list.all);}diff --git a/frontend_tests/node_tests/message_store.js b/frontend_tests/node_tests/message_store.jsindex a8ee8d7a13b..4a589bfddb1 100644--- a/frontend_tests/node_tests/message_store.js+++ b/frontend_tests/node_tests/message_store.js@@ -343,7 +343,7 @@ run_test("message_id_change", () => {},});- set_global("message_list", {});+ rewiremock("../../static/js/message_list").with({});set_global("home_msg_list", {});const opts = {diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex 5ed8f7365cb..718b3a823fd 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -22,11 +22,14 @@ rewiremock("../../static/js/hashchange").with(hashchange);set_global("home_msg_list", {});const message_fetch = {__esModule: true};rewiremock("../../static/js/message_fetch").with(message_fetch);-const message_list = set_global("message_list", {+const message_list = {+ __esModule: true,+set_narrowed(value) {message_list.narrowed = value;},-});+};+rewiremock("../../static/js/message_list").with(message_list);const message_scroll = {__esModule: true};rewiremock("../../static/js/message_scroll").with(message_scroll);const notifications = {__esModule: true};diff --git a/frontend_tests/node_tests/narrow_local.js b/frontend_tests/node_tests/narrow_local.jsindex 9d13f001722..4455f736902 100644--- a/frontend_tests/node_tests/narrow_local.js+++ b/frontend_tests/node_tests/narrow_local.js@@ -2,10 +2,15 @@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 message_list = set_global("message_list", {});+const message_list = {__esModule: true};++rewiremock("../../static/js/message_list").with(message_list);+rewiremock.enable();const {Filter} = zrequire("Filter", "js/filter");const {MessageListData} = zrequire("MessageListData", "js/message_list_data");@@ -445,3 +450,4 @@ run_test("final corner case", () => {test_with(fixture);});+rewiremock.disable();diff --git a/frontend_tests/node_tests/recent_senders.js b/frontend_tests/node_tests/recent_senders.jsindex 8963abcce5c..64b94840173 100644--- a/frontend_tests/node_tests/recent_senders.js+++ b/frontend_tests/node_tests/recent_senders.js@@ -4,7 +4,7 @@ const {strict: assert} = require("assert");const rewiremock = require("rewiremock/node");-const {set_global, zrequire} = require("../zjsunit/namespace");+const {zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");let next_id = 0;@@ -13,13 +13,17 @@ const messages = [];rewiremock("../../static/js/message_store").with({get: (msg_id) => messages[msg_id - 1],});-const message_list = set_global("message_list", {+const message_list = {+ __esModule: true,+all: {all_messages() {return messages;},},-});+};++rewiremock("../../static/js/message_list").with(message_list);rewiremock.enable();diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex 96a81d11f5e..274a7df35c5 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -136,13 +136,16 @@ const sender2 = 2;const messages = [];-const message_list = set_global("message_list", {+const message_list = {+ __esModule: true,+all: {all_messages() {return messages;},},-});+};+rewiremock("../../static/js/message_list").with(message_list);rewiremock("../../static/js/message_store").with({get: (msg_id) => messages[msg_id - 1],});diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.jsindex b0772a7277b..e4ee48c2c6a 100644--- a/frontend_tests/node_tests/stream_events.js+++ b/frontend_tests/node_tests/stream_events.js@@ -31,7 +31,7 @@ rewiremock("../../static/js/recent_topics").with({complete_rerender: () => {},});-set_global("message_list", {+rewiremock("../../static/js/message_list").with({all: {all_messages() {return ["msg"];diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.jsindex 7c75ea4a27c..f76026bfed7 100644--- a/frontend_tests/node_tests/stream_topic_history.js+++ b/frontend_tests/node_tests/stream_topic_history.js@@ -4,12 +4,13 @@ const {strict: assert} = require("assert");const rewiremock = require("rewiremock/node");-const {set_global, zrequire} = require("../zjsunit/namespace");+const {zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");const channel = {__esModule: true};rewiremock("../../static/js/channel").with(channel);-const message_list = set_global("message_list", {});+const message_list = {__esModule: true};+rewiremock("../../static/js/message_list").with(message_list);const message_util = {__esModule: true};rewiremock("../../static/js/message_util").with(message_util);diff --git a/frontend_tests/node_tests/topic_list_data.js b/frontend_tests/node_tests/topic_list_data.jsindex 4aa607735db..e17bd8f3be4 100644--- a/frontend_tests/node_tests/topic_list_data.js+++ b/frontend_tests/node_tests/topic_list_data.js@@ -5,7 +5,7 @@ const {strict: assert} = require("assert");const _ = require("lodash");const rewiremock = require("rewiremock/node");-const {set_global, zrequire} = require("../zjsunit/namespace");+const {zrequire} = require("../zjsunit/namespace");const {run_test} = require("../zjsunit/test");const narrow_state = {@@ -21,7 +21,7 @@ const muting = {},};rewiremock("../../static/js/muting").with(muting);-set_global("message_list", {});+rewiremock("../../static/js/message_list").with({});rewiremock.enable();diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.jsindex c6b805511c9..e477ecd29db 100644--- a/frontend_tests/node_tests/tutorial.js+++ b/frontend_tests/node_tests/tutorial.js@@ -30,7 +30,8 @@ rewiremock("../../static/js/pm_list").with(pm_list);const settings_users = {__esModule: true};rewiremock("../../static/js/settings_users").with(settings_users);const home_msg_list = set_global("home_msg_list", {});-const message_list = set_global("message_list", {});+const message_list = {__esModule: true};+rewiremock("../../static/js/message_list").with(message_list);const message_util = {__esModule: true};rewiremock("../../static/js/message_util").with(message_util);const notifications = {__esModule: true};diff --git a/static/js/echo.js b/static/js/echo.jsindex 1f0bf5cf555..9480d079d18 100644--- a/static/js/echo.js+++ b/static/js/echo.js@@ -2,6 +2,7 @@ import * as alert_words from "./alert_words";import * as compose from "./compose";import * as local_message from "./local_message";import * as markdown from "./markdown";+import * as message_list from "./message_list";import * as message_store from "./message_store";import * as narrow_state from "./narrow_state";import * as notifications from "./notifications";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex cb522214d59..a35af48a1e0 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -13,7 +13,6 @@ declare let favicon: any;declare let home_msg_list: any;declare let i18n: any;declare let message_events: any;-declare let message_list: any;declare let narrow: any;declare let page_params: any;declare let pointer: any;diff --git a/static/js/local_message.js b/static/js/local_message.jsindex 28a60085896..0ffd98b4407 100644--- a/static/js/local_message.js+++ b/static/js/local_message.js@@ -1,3 +1,5 @@+import * as message_list from "./message_list";+function truncate_precision(float) {return Number.parseFloat(float.toFixed(3));}diff --git a/static/js/message_events.js b/static/js/message_events.jsindex 5ed60b9c578..1d0c6c72843 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -8,6 +8,7 @@ const condense = require("./condense");const huddle_data = require("./huddle_data");const message_edit = require("./message_edit");const message_edit_history = require("./message_edit_history");+const message_list = require("./message_list");const message_store = require("./message_store");const message_util = require("./message_util");const narrow_state = require("./narrow_state");diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex 3695a431eac..b830f154fcd 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -1,6 +1,7 @@import * as channel from "./channel";import {Filter} from "./filter";import * as huddle_data from "./huddle_data";+import * as message_list from "./message_list";import * as message_scroll from "./message_scroll";import * as message_store from "./message_store";import * as message_util from "./message_util";diff --git a/static/js/message_list.js b/static/js/message_list.jsindex ae45800716d..9a486f22eb6 100644--- a/static/js/message_list.js+++ b/static/js/message_list.js@@ -1,18 +1,17 @@-"use strict";+import autosize from "autosize";-const autosize = require("autosize");+import {MessageListData} from "./message_list_data";+import {MessageListView} from "./message_list_view";+import * as narrow_state from "./narrow_state";+import * as stream_data from "./stream_data";-const {MessageListData} = require("./message_list_data");-const {MessageListView} = require("./message_list_view");-const narrow_state = require("./narrow_state");-const stream_data = require("./stream_data");+export let narrowed;-exports.narrowed = undefined;-exports.set_narrowed = function (value) {- exports.narrowed = value;-};+export function set_narrowed(value) {+ narrowed = value;+}-class MessageList {+export class MessageList {constructor(opts) {if (opts.data) {this.excludes_muted_topics = opts.data.excludes_muted_topics;@@ -66,14 +65,14 @@ class MessageList {render_info = this.append_to_view(bottom_messages, opts);}- if (this === exports.narrowed && !this.empty()) {+ if (this === narrowed && !this.empty()) {// If adding some new messages to the message tables caused// our current narrow to no longer be empty, hide the empty// feed placeholder text.narrow.hide_empty_narrow_message();}- if (this === exports.narrowed && !this.empty() && this.selected_id() === -1) {+ if (this === narrowed && !this.empty() && this.selected_id() === -1) {// And also select the newly arrived message.this.select_id(this.selected_id(), {then_scroll: true, use_closest: true});}@@ -361,7 +360,7 @@ class MessageList {this.view.clear_rendering_state(false);this.view.update_render_window(this.selected_idx(), false);- if (this === exports.narrowed) {+ if (this === narrowed) {if (this.empty()) {narrow.show_empty_narrow_message();} else {@@ -414,10 +413,7 @@ class MessageList {return this.data.get_last_message_sent_by_me();}}-exports.MessageList = MessageList;-exports.all = new MessageList({+export const all = new MessageList({excludes_muted_topics: false,});--window.message_list = exports;diff --git a/static/js/message_live_update.js b/static/js/message_live_update.jsindex 1d089bbd7bf..5360986289f 100644--- a/static/js/message_live_update.js+++ b/static/js/message_live_update.js@@ -1,3 +1,4 @@+import * as message_list from "./message_list";import * as message_store from "./message_store";import * as people from "./people";diff --git a/static/js/message_store.js b/static/js/message_store.jsindex ffc2abede26..83544d918e1 100644--- a/static/js/message_store.js+++ b/static/js/message_store.js@@ -1,4 +1,5 @@import * as alert_words from "./alert_words";+import * as message_list from "./message_list";import * as people from "./people";import * as pm_conversations from "./pm_conversations";import * as recent_senders from "./recent_senders";diff --git a/static/js/message_util.js b/static/js/message_util.jsindex 59ff9bac65d..ab02ac519b3 100644--- a/static/js/message_util.js+++ b/static/js/message_util.js@@ -1,4 +1,5 @@import * as loading from "./loading";+import * as message_list from "./message_list";import * as message_store from "./message_store";import * as resize from "./resize";import * as unread from "./unread";diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 0366ae8728f..4f3a9883baf 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -9,6 +9,7 @@ const {Filter} = require("./filter");const hashchange = require("./hashchange");const message_edit = require("./message_edit");const message_fetch = require("./message_fetch");+const message_list = require("./message_list");const {MessageListData} = require("./message_list_data");const message_scroll = require("./message_scroll");const message_store = require("./message_store");diff --git a/static/js/reload.js b/static/js/reload.jsindex ea9d4fff4e8..3fb46eb420c 100644--- a/static/js/reload.js+++ b/static/js/reload.js@@ -3,6 +3,7 @@ import * as compose from "./compose";import * as compose_state from "./compose_state";import * as hashchange from "./hashchange";import {localstorage} from "./localstorage";+import * as message_list from "./message_list";import * as narrow_state from "./narrow_state";import * as reload_state from "./reload_state";import * as server_events from "./server_events";diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex e053618551d..f66d1020ea1 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -12,6 +12,7 @@ import * as hotspots from "./hotspots";import * as markdown from "./markdown";import * as message_edit from "./message_edit";import * as message_flags from "./message_flags";+import * as message_list from "./message_list";import * as muting_ui from "./muting_ui";import * as narrow_state from "./narrow_state";import * as night_mode from "./night_mode";diff --git a/static/js/stream_data.js b/static/js/stream_data.jsindex 5824fe1c1d3..bb3d0ea6832 100644--- a/static/js/stream_data.js+++ b/static/js/stream_data.js@@ -1,6 +1,7 @@import * as color_data from "./color_data";import {FoldDict} from "./fold_dict";import * as hash_util from "./hash_util";+import * as message_list from "./message_list";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_events.js b/static/js/stream_events.jsindex 1a17c4b9522..b26902e33b7 100644--- a/static/js/stream_events.js+++ b/static/js/stream_events.js@@ -1,4 +1,5 @@import * as color_data from "./color_data";+import * as message_list from "./message_list";import * as message_util from "./message_util";import * as message_view_header from "./message_view_header";import * as narrow_state from "./narrow_state";diff --git a/static/js/stream_muting.js b/static/js/stream_muting.jsindex 7642e183840..da4143d0724 100644--- a/static/js/stream_muting.js+++ b/static/js/stream_muting.js@@ -1,3 +1,4 @@+import * as message_list from "./message_list";import * as message_scroll from "./message_scroll";import * as message_util from "./message_util";import * as message_viewport from "./message_viewport";diff --git a/static/js/ui.js b/static/js/ui.jsindex e36bac58d05..4433de0b0be 100644--- a/static/js/ui.js+++ b/static/js/ui.js@@ -4,6 +4,7 @@ const SimpleBar = require("simplebar/dist/simplebar");const common = require("./common");const {localstorage} = require("./localstorage");+const message_list = require("./message_list");// What, if anything, obscures the home tab?diff --git a/static/js/unread_ops.js b/static/js/unread_ops.jsindex bf9a348da84..db9ecf39a02 100644--- a/static/js/unread_ops.js+++ b/static/js/unread_ops.js@@ -1,5 +1,6 @@import * as channel from "./channel";import * as message_flags from "./message_flags";+import * as message_list from "./message_list";import * as message_store from "./message_store";import * as message_viewport from "./message_viewport";import * as notifications from "./notifications";diff --git a/static/js/zulip.js b/static/js/zulip.jsindex 7f680ce3ddb..8d662d1532a 100644--- a/static/js/zulip.js+++ b/static/js/zulip.js@@ -1,6 +1,7 @@"use strict";const {Filter} = require("./filter");+const message_list = require("./message_list");// This file is being eliminated as part of the general purge of// global variables from Zulip (everything is being moved into