Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/message_util.js to ES6 module.
Anders Kaseorg7a45ed46afc7
diff --git a/.eslintrc.json b/.eslintrc.jsonindex f34796f23d0..b77a6664106 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -154,7 +154,6 @@"message_events": false,"message_fetch": false,"message_list": false,- "message_util": false,"narrow": false,"padded_widget": false,"page_params": false,diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.jsindex 0828b4cf43d..b6dacf5a586 100644--- a/frontend_tests/node_tests/filter.js+++ b/frontend_tests/node_tests/filter.js@@ -17,7 +17,6 @@ rewiremock.enable();zrequire("unread");const stream_data = zrequire("stream_data");const people = zrequire("people");-zrequire("message_util", "js/message_util");const {Filter} = zrequire("Filter", "js/filter");const me = {diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.jsindex bd4c20eaa8b..bdff46f640d 100644--- a/frontend_tests/node_tests/message_fetch.js+++ b/frontend_tests/node_tests/message_fetch.js@@ -39,7 +39,8 @@ rewiremock("../../static/js/message_scroll").with({hide_loading_newer: noop,update_top_of_narrow_notices: () => {},});-const message_util = set_global("message_util", {});+const message_util = {__esModule: true};+rewiremock("../../static/js/message_util").with(message_util);const message_store = {__esModule: true};rewiremock("../../static/js/message_store").with(message_store);const narrow_state = {__esModule: true};diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex 61dc8b3e3c1..b1a54e7ff45 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -28,7 +28,7 @@ const message_list = set_global("message_list", {});const message_scroll = {__esModule: true};rewiremock("../../static/js/message_scroll").with(message_scroll);-set_global("message_util", {});+rewiremock("../../static/js/message_util").with({});const notifications = {__esModule: true};rewiremock("../../static/js/notifications").with(notifications);set_global("page_params", {});diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.jsindex 6c84f824795..68cda0fa4f8 100644--- a/frontend_tests/node_tests/recent_topics.js+++ b/frontend_tests/node_tests/recent_topics.js@@ -171,7 +171,6 @@ rewiremock("../../static/js/stream_data").with({rewiremock.enable();-zrequire("message_util");const people = zrequire("people");let rt = zrequire("recent_topics");diff --git a/frontend_tests/node_tests/stream_events.js b/frontend_tests/node_tests/stream_events.jsindex f3fd8d88ef4..e840f7fe025 100644--- a/frontend_tests/node_tests/stream_events.js+++ b/frontend_tests/node_tests/stream_events.js@@ -18,7 +18,8 @@ set_global("settings_notifications", _settings_notifications);const color_data = {__esModule: true};rewiremock("../../static/js/color_data").with(color_data);set_global("current_msg_list", {});-const message_util = set_global("message_util", {});+const message_util = {__esModule: true};+rewiremock("../../static/js/message_util").with(message_util);const stream_color = {__esModule: true};rewiremock("../../static/js/stream_color").with(stream_color);const stream_list = set_global("stream_list", {});diff --git a/frontend_tests/node_tests/stream_topic_history.js b/frontend_tests/node_tests/stream_topic_history.jsindex c4c65781b84..4460e8430d4 100644--- a/frontend_tests/node_tests/stream_topic_history.js+++ b/frontend_tests/node_tests/stream_topic_history.js@@ -61,7 +61,7 @@ run_test("basics", () => {assert.deepEqual(history, ["Topic1", "topic2"]);assert.deepEqual(max_message_id, 104);- set_global("message_util", {+ rewiremock("../../static/js/message_util").with({get_messages_in_topic: () => [{id: 101}, {id: 102}],get_max_message_id_in_stream: () => 103,});@@ -78,7 +78,7 @@ run_test("basics", () => {max_message_id = stream_topic_history.get_max_message_id(stream_id);assert.deepEqual(max_message_id, 103);- set_global("message_util", {+ rewiremock("../../static/js/message_util").with({get_messages_in_topic: () => [{id: 102}],get_max_message_id_in_stream: () => 103,});diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.jsindex 640cb41b71d..5acba99bbb6 100644--- a/frontend_tests/node_tests/tutorial.js+++ b/frontend_tests/node_tests/tutorial.js@@ -29,7 +29,8 @@ rewiremock("../../static/js/pm_list").with(pm_list);const settings_users = set_global("settings_users", {});const home_msg_list = set_global("home_msg_list", {});const message_list = set_global("message_list", {});-const message_util = set_global("message_util", {});+const message_util = {__esModule: true};+rewiremock("../../static/js/message_util").with(message_util);const notifications = {__esModule: true};rewiremock("../../static/js/notifications").with(notifications);const overlays = {__esModule: true};diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex b301877f184..b14ef7611d8 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -30,7 +30,6 @@ import "../ui";import "../composebox_typeahead";import "../hotkey";import "../notifications";-import "../message_util";import "../message_events";import "../message_fetch";import "../server_events";diff --git a/static/js/filter.js b/static/js/filter.jsindex ac333db60cf..16e1e73b82f 100644--- a/static/js/filter.js+++ b/static/js/filter.js@@ -2,6 +2,7 @@ import Handlebars from "handlebars/runtime";import _ from "lodash";import * as message_store from "./message_store";+import * as message_util from "./message_util";import * as people from "./people";import * as stream_data from "./stream_data";import * as util from "./util";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 9c467a990be..9a2c20bc7bc 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -27,7 +27,6 @@ declare let input_pill: any;declare let message_events: any;declare let message_fetch: any;declare let message_list: any;-declare let message_util: any;declare let narrow: any;declare let padded_widget: any;declare let page_params: any;diff --git a/static/js/message_events.js b/static/js/message_events.jsindex 2713a5998f4..b2ee6a1fb35 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -9,6 +9,7 @@ const huddle_data = require("./huddle_data");const message_edit = require("./message_edit");const message_edit_history = require("./message_edit_history");const message_store = require("./message_store");+const message_util = require("./message_util");const narrow_state = require("./narrow_state");const notifications = require("./notifications");const pm_list = require("./pm_list");diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex a80cb2a4b55..090dc8bf821 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -5,6 +5,7 @@ const {Filter} = require("./filter");const huddle_data = require("./huddle_data");const message_scroll = require("./message_scroll");const message_store = require("./message_store");+const message_util = require("./message_util");const people = require("./people");const pm_list = require("./pm_list");const stream_data = require("./stream_data");diff --git a/static/js/message_util.js b/static/js/message_util.jsindex 1556d605116..4db20a921ab 100644--- a/static/js/message_util.js+++ b/static/js/message_util.js@@ -1,15 +1,13 @@-"use strict";+import * as loading from "./loading";+import * as message_store from "./message_store";+import * as resize from "./resize";+import * as unread_ui from "./unread_ui";-const loading = require("./loading");-const message_store = require("./message_store");-const resize = require("./resize");-const unread_ui = require("./unread_ui");--exports.do_unread_count_updates = function do_unread_count_updates(messages) {+export function do_unread_count_updates(messages) {unread.process_loaded_messages(messages);unread_ui.update_unread_counts();resize.resize_page_components();-};+}function add_messages(messages, msg_list, opts) {if (!messages) {@@ -32,23 +30,23 @@ function is_element_in_message_content(message, element_selector) {return $(`<div>${message.content}</div>`).find(`${element_selector}`).length > 0;}-exports.message_has_link = function (message) {+export function message_has_link(message) {return is_element_in_message_content(message, "a");-};+}-exports.message_has_image = function (message) {+export function message_has_image(message) {return is_element_in_message_content(message, ".message_inline_image");-};+}-exports.message_has_attachment = function (message) {+export function message_has_attachment(message) {return is_element_in_message_content(message, "a[href^='/user_uploads']");-};+}-exports.add_old_messages = function (messages, msg_list) {+export function add_old_messages(messages, msg_list) {return add_messages(messages, msg_list, {messages_are_new: false});-};+}-exports.add_new_messages = function (messages, msg_list) {+export function add_new_messages(messages, msg_list) {if (!msg_list.data.fetch_status.has_found_newest()) {// We don't render newly received messages for the message list,// if we haven't found the latest messages to be displayed in the@@ -58,9 +56,9 @@ exports.add_new_messages = function (messages, msg_list) {return undefined;}return add_messages(messages, msg_list, {messages_are_new: true});-};+}-exports.get_messages_in_topic = function (stream_id, topic) {+export function get_messages_in_topic(stream_id, topic) {return message_list.all.all_messages().filter(@@ -69,9 +67,9 @@ exports.get_messages_in_topic = function (stream_id, topic) {x.stream_id === stream_id &&x.topic.toLowerCase() === topic.toLowerCase(),);-};+}-exports.get_max_message_id_in_stream = function (stream_id) {+export function get_max_message_id_in_stream(stream_id) {let max_message_id = 0;for (const msg of message_list.all.all_messages()) {if (msg.type === "stream" && msg.stream_id === stream_id && msg.id > max_message_id) {@@ -79,9 +77,9 @@ exports.get_max_message_id_in_stream = function (stream_id) {}}return max_message_id;-};+}-exports.get_topics_for_message_ids = function (message_ids) {+export function get_topics_for_message_ids(message_ids) {const topics = new Map(); // key = stream_id:topicfor (const msg_id of message_ids) {// message_store still has data on deleted messages when this runs.@@ -98,6 +96,4 @@ exports.get_topics_for_message_ids = function (message_ids) {}}return topics;-};--window.message_util = exports;+}diff --git a/static/js/recent_senders.js b/static/js/recent_senders.jsindex 6b25de8ab3a..10d6fb0c15c 100644--- a/static/js/recent_senders.js+++ b/static/js/recent_senders.js@@ -1,4 +1,5 @@import {FoldDict} from "./fold_dict";+import * as message_util from "./message_util";// topic_senders[stream_id][topic_id][sender_id] = latest_message_idconst topic_senders = new Map();diff --git a/static/js/recent_topics.js b/static/js/recent_topics.jsindex a923128ece8..9face3ab670 100644--- a/static/js/recent_topics.js+++ b/static/js/recent_topics.js@@ -9,6 +9,7 @@ const hash_util = require("./hash_util");const ListWidget = require("./list_widget");const {localstorage} = require("./localstorage");const message_store = require("./message_store");+const message_util = require("./message_util");const muting = require("./muting");const narrow_state = require("./narrow_state");const navigate = require("./navigate");diff --git a/static/js/stream_events.js b/static/js/stream_events.jsindex f884e46b361..3d29c764da2 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_util from "./message_util";import * as narrow_state from "./narrow_state";import * as overlays from "./overlays";import * as peer_data from "./peer_data";diff --git a/static/js/stream_muting.js b/static/js/stream_muting.jsindex 27a663d3f79..4e8c53cfc1e 100644--- a/static/js/stream_muting.js+++ b/static/js/stream_muting.js@@ -1,4 +1,5 @@import * as message_scroll from "./message_scroll";+import * as message_util from "./message_util";import * as message_viewport from "./message_viewport";import * as navigate from "./navigate";import * as overlays from "./overlays";diff --git a/static/js/stream_topic_history.js b/static/js/stream_topic_history.jsindex 92157003ecf..dcfb2c23a59 100644--- a/static/js/stream_topic_history.js+++ b/static/js/stream_topic_history.js@@ -1,5 +1,6 @@import * as channel from "./channel";import {FoldDict} from "./fold_dict";+import * as message_util from "./message_util";import * as stream_data from "./stream_data";const stream_dict = new Map(); // stream_id -> PerStreamHistory object