Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/message_flags.js to ES6 module.
Anders Kaseorg5ae2f172d0b7
diff --git a/.eslintrc.json b/.eslintrc.jsonindex f8be8ba297b..053d440a2c0 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -155,7 +155,6 @@"location": false,"message_events": false,"message_fetch": false,- "message_flags": false,"message_list": false,"message_store": false,"message_util": false,diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex 25421b6cf98..2e50a9b2fcc 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.js@@ -90,7 +90,6 @@ const alert_words = zrequire("alert_words");zrequire("unread");const stream_topic_history = zrequire("stream_topic_history");const stream_list = zrequire("stream_list");-zrequire("message_flags");const message_store = zrequire("message_store");const people = zrequire("people");const starred_messages = zrequire("starred_messages");diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.jsindex 2e3b1db8dba..f4cacfa7df7 100644--- a/frontend_tests/node_tests/message_flags.js+++ b/frontend_tests/node_tests/message_flags.js@@ -84,7 +84,7 @@ run_test("read", () => {};// For testing purpose limit the batch size value to 5 instead of 1000- message_flags._unread_batch_size = 5;+ message_flags.__Rewire__("_unread_batch_size", 5);let msgs_to_flag_read = [{locally_echoed: false, id: 1},{locally_echoed: false, id: 2},diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.jsindex 760bdca11e3..640cb41b71d 100644--- a/frontend_tests/node_tests/tutorial.js+++ b/frontend_tests/node_tests/tutorial.js@@ -595,8 +595,6 @@ run_test("explore make_stub", (override) => {*/-zrequire("message_flags");-unread_ops = zrequire("unread_ops");run_test("unread_ops", (override) => {diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex 0d5ef047bde..776086beaab 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_flags";import "../starred_messages";import "../alert_words_ui";import "../attachments_ui";diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex 253acdddf47..48e4ebc1600 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -13,6 +13,7 @@ import * as hash_util from "./hash_util";import * as hashchange from "./hashchange";import * as message_edit from "./message_edit";import * as message_edit_history from "./message_edit_history";+import * as message_flags from "./message_flags";import * as muting_ui from "./muting_ui";import * as notifications from "./notifications";import * as overlays from "./overlays";diff --git a/static/js/condense.js b/static/js/condense.jsindex 4649dd9d753..3807bd678f4 100644--- a/static/js/condense.js+++ b/static/js/condense.js@@ -1,3 +1,4 @@+import * as message_flags from "./message_flags";import * as message_viewport from "./message_viewport";import * as rows from "./rows";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex e13871ad680..d6fb27c1510 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -28,7 +28,6 @@ declare let i18n: any;declare let input_pill: any;declare let message_events: any;declare let message_fetch: any;-declare let message_flags: any;declare let message_list: any;declare let message_store: any;declare let message_util: any;diff --git a/static/js/hotkey.js b/static/js/hotkey.jsindex ab9d0667452..605caa66386 100644--- a/static/js/hotkey.js+++ b/static/js/hotkey.js@@ -12,6 +12,7 @@ import * as hashchange from "./hashchange";import * as lightbox from "./lightbox";import * as list_util from "./list_util";import * as message_edit from "./message_edit";+import * as message_flags from "./message_flags";import * as muting_ui from "./muting_ui";import * as navigate from "./navigate";import * as overlays from "./overlays";diff --git a/static/js/message_flags.js b/static/js/message_flags.jsindex 5a5c43c100d..9e1f9e66816 100644--- a/static/js/message_flags.js+++ b/static/js/message_flags.js@@ -1,8 +1,6 @@-"use strict";+import _ from "lodash";-const _ = require("lodash");--const channel = require("./channel");+import * as channel from "./channel";function send_flag_update(message, flag, op) {channel.post({@@ -15,8 +13,9 @@ function send_flag_update(message, flag, op) {},});}-exports._unread_batch_size = 1000;-exports.send_read = (function () {+export const _unread_batch_size = 1000;++export const send_read = (function () {let queue = [];let on_success;let start;@@ -30,7 +29,7 @@ exports.send_read = (function () {return;}- const real_msg_ids_batch = real_msg_ids.slice(0, exports._unread_batch_size);+ const real_msg_ids_batch = real_msg_ids.slice(0, _unread_batch_size);// We have some real IDs. If there are any left in the queue when this// call finishes, they will be handled in the success callback.@@ -65,17 +64,17 @@ exports.send_read = (function () {return add;})();-exports.save_collapsed = function (message) {+export function save_collapsed(message) {send_flag_update(message, "collapsed", "add");-};+}-exports.save_uncollapsed = function (message) {+export function save_uncollapsed(message) {send_flag_update(message, "collapsed", "remove");-};+}// This updates the state of the starred flag in local data// structures, and triggers a UI rerender.-exports.update_starred_flag = function (message_id, new_value) {+export function update_starred_flag(message_id, new_value) {const message = message_store.get(message_id);if (message === undefined) {// If we don't have the message locally, do nothing; if later@@ -84,9 +83,9 @@ exports.update_starred_flag = function (message_id, new_value) {}message.starred = new_value;ui.update_starred_view(message_id, new_value);-};+}-exports.toggle_starred_and_update_server = function (message) {+export function toggle_starred_and_update_server(message) {if (message.locally_echoed) {// This is defensive code for when you hit the "*" key// before we get a server ack. It's rare that somebody@@ -111,9 +110,9 @@ exports.toggle_starred_and_update_server = function (message) {send_flag_update(message, "starred", "remove");starred_messages.remove([message.id]);}-};+}-exports.unstar_all_messages = function () {+export function unstar_all_messages() {const starred_msg_ids = starred_messages.get_starred_msg_ids();channel.post({url: "/json/messages/flags",@@ -124,6 +123,4 @@ exports.unstar_all_messages = function () {op: "remove",},});-};--window.message_flags = exports;+}diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex b62d6c3aae5..d857c4c7882 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -5,6 +5,7 @@ import * as compose from "./compose";import * as compose_fade from "./compose_fade";import * as markdown from "./markdown";import * as message_edit from "./message_edit";+import * as message_flags from "./message_flags";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_popover.js b/static/js/stream_popover.jsindex 0aac62b9330..c51aaaf8245 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -10,6 +10,7 @@ import * as channel from "./channel";import * as hash_util from "./hash_util";import * as hashchange from "./hashchange";import * as message_edit from "./message_edit";+import * as message_flags from "./message_flags";import * as muting from "./muting";import * as muting_ui from "./muting_ui";import * as popovers from "./popovers";diff --git a/static/js/unread_ops.js b/static/js/unread_ops.jsindex 16fc22e39ee..5fdcbc2dcc4 100644--- a/static/js/unread_ops.js+++ b/static/js/unread_ops.js@@ -1,6 +1,7 @@"use strict";const channel = require("./channel");+const message_flags = require("./message_flags");const message_viewport = require("./message_viewport");const notifications = require("./notifications");const overlays = require("./overlays");