Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/unread_ops.js to ES6 module.
Anders Kaseorg9997e1303229
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 95fff91c05d..226272ed9db 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -153,7 +153,6 @@"ui": false,"ui_init": false,"unread": false,- "unread_ops": false,"widgetize": false,"zxcvbn": false}diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.jsindex 1012c389b53..0c2fcc86a73 100644--- a/frontend_tests/node_tests/compose_actions.js+++ b/frontend_tests/node_tests/compose_actions.js@@ -51,7 +51,7 @@ const narrow_state = {rewiremock("../../static/js/narrow_state").with(narrow_state);-set_global("unread_ops", {+rewiremock("../../static/js/unread_ops").with({notify_server_message_read: noop,});diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.jsindex def62700c56..b6b3c228367 100644--- a/frontend_tests/node_tests/dispatch.js+++ b/frontend_tests/node_tests/dispatch.js@@ -92,7 +92,8 @@ rewiremock("../../static/js/submessage").with(submessage);const typing_events = {__esModule: true};rewiremock("../../static/js/typing_events").with(typing_events);const ui = set_global("ui", {});-const unread_ops = set_global("unread_ops", {});+const unread_ops = {__esModule: true};+rewiremock("../../static/js/unread_ops").with(unread_ops);const user_events = {__esModule: true};rewiremock("../../static/js/user_events").with(user_events);const user_groups = {__esModule: true};diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.jsindex 7d74fe5b528..32f6435a5f7 100644--- a/frontend_tests/node_tests/message_flags.js+++ b/frontend_tests/node_tests/message_flags.js@@ -15,7 +15,6 @@ rewiremock("../../static/js/starred_messages").with({rewiremock.enable();zrequire("unread");-zrequire("unread_ops");const message_flags = zrequire("message_flags");const ui = set_global("ui", {});diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex 39407b9f7c2..efc1f9737cb 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -43,7 +43,8 @@ const typing_events = {__esModule: true};rewiremock("../../static/js/typing_events").with(typing_events);const ui_util = {__esModule: true};rewiremock("../../static/js/ui_util").with(ui_util);-const unread_ops = set_global("unread_ops", {});+const unread_ops = {__esModule: true};+rewiremock("../../static/js/unread_ops").with(unread_ops);rewiremock("../../static/js/recent_topics").with({hide: () => {},is_visible: () => {},diff --git a/frontend_tests/node_tests/tutorial.js b/frontend_tests/node_tests/tutorial.jsindex 651c57f2419..8fd743fdba3 100644--- a/frontend_tests/node_tests/tutorial.js+++ b/frontend_tests/node_tests/tutorial.js@@ -40,7 +40,8 @@ rewiremock("../../static/js/overlays").with(overlays);const resize = {__esModule: true};rewiremock("../../static/js/resize").with(resize);let stream_list = set_global("stream_list", {});-let unread_ops = set_global("unread_ops", {});+let unread_ops = {__esModule: true};+rewiremock("../../static/js/unread_ops").with(unread_ops);const unread_ui = {__esModule: true};rewiremock("../../static/js/unread_ui").with(unread_ui);const channel = {__esModule: true};@@ -596,6 +597,7 @@ run_test("explore make_stub", (override) => {*/+rewiremock("../../static/js/unread_ops").disable();unread_ops = zrequire("unread_ops");run_test("unread_ops", (override) => {diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex 7518d04430b..354eff2ccc6 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";import "../i18n";import "../fold_dict";import "../setup";-import "../unread_ops";import "../unread";import "../stream_list";import "../widgetize";diff --git a/static/js/click_handlers.js b/static/js/click_handlers.jsindex acb5f659e6c..b198cafe552 100644--- a/static/js/click_handlers.js+++ b/static/js/click_handlers.js@@ -32,6 +32,7 @@ import * as settings_toggle from "./settings_toggle";import * as stream_edit from "./stream_edit";import * as stream_popover from "./stream_popover";import * as ui_util from "./ui_util";+import * as unread_ops from "./unread_ops";import * as user_status_ui from "./user_status_ui";import * as util from "./util";diff --git a/static/js/compose_actions.js b/static/js/compose_actions.jsindex 1624acb34fc..3108c69b0d1 100644--- a/static/js/compose_actions.js+++ b/static/js/compose_actions.js@@ -20,6 +20,7 @@ const people = require("./people");const reload_state = require("./reload_state");const stream_data = require("./stream_data");const ui_util = require("./ui_util");+const unread_ops = require("./unread_ops");exports.blur_compose_inputs = function () {$(".message_comp").find("input, textarea, button, #private_message_recipient").trigger("blur");diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 6b70652fadc..94905d3eb87 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -22,7 +22,6 @@ declare let stream_list: any;declare let subs: any;declare let ui: any;declare let unread: any;-declare let unread_ops: any;declare let widgetize: any;declare let zulip_test: any;diff --git a/static/js/message_events.js b/static/js/message_events.jsindex 0bddade346e..d665f1eb7e7 100644--- a/static/js/message_events.js+++ b/static/js/message_events.js@@ -18,6 +18,7 @@ const recent_topics = require("./recent_topics");const resize = require("./resize");const stream_data = require("./stream_data");const stream_topic_history = require("./stream_topic_history");+const unread_ops = require("./unread_ops");const unread_ui = require("./unread_ui");const util = require("./util");diff --git a/static/js/message_flags.js b/static/js/message_flags.jsindex 647bb76d4fb..d4d1761dbab 100644--- a/static/js/message_flags.js+++ b/static/js/message_flags.js@@ -3,6 +3,7 @@ import _ from "lodash";import * as channel from "./channel";import * as message_store from "./message_store";import * as starred_messages from "./starred_messages";+import * as unread_ops from "./unread_ops";function send_flag_update(message, flag, op) {channel.post({diff --git a/static/js/message_scroll.js b/static/js/message_scroll.jsindex fddf9e0db58..19819daeb59 100644--- a/static/js/message_scroll.js+++ b/static/js/message_scroll.js@@ -7,6 +7,7 @@ import * as message_fetch from "./message_fetch";import * as message_viewport from "./message_viewport";import * as narrow_state from "./narrow_state";import * as recent_topics from "./recent_topics";+import * as unread_ops from "./unread_ops";let actively_scrolling = false;diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 3166d8340ed..e23807d93b8 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -27,6 +27,7 @@ const top_left_corner = require("./top_left_corner");const topic_generator = require("./topic_generator");const typing_events = require("./typing_events");const ui_util = require("./ui_util");+const unread_ops = require("./unread_ops");const util = require("./util");let unnarrow_times;diff --git a/static/js/navigate.js b/static/js/navigate.jsindex 06cc219d40c..85d89593b49 100644--- a/static/js/navigate.js+++ b/static/js/navigate.js@@ -1,5 +1,6 @@import * as message_viewport from "./message_viewport";import * as rows from "./rows";+import * as unread_ops from "./unread_ops";function go_to_row(msg_id) {current_msg_list.select_id(msg_id, {then_scroll: true, from_scroll: true});diff --git a/static/js/notifications.js b/static/js/notifications.jsindex 575c7963346..4549eb655d9 100644--- a/static/js/notifications.js+++ b/static/js/notifications.js@@ -15,6 +15,7 @@ import * as settings_config from "./settings_config";import * as spoilers from "./spoilers";import * as stream_data from "./stream_data";import * as stream_ui_updates from "./stream_ui_updates";+import * as unread_ops from "./unread_ops";const notice_memory = new Map();diff --git a/static/js/panels.js b/static/js/panels.jsindex c7383fd29cf..16eb0d401a0 100644--- a/static/js/panels.js+++ b/static/js/panels.js@@ -1,5 +1,6 @@import {localstorage} from "./localstorage";import * as notifications from "./notifications";+import * as unread_ops from "./unread_ops";import * as unread_ui from "./unread_ui";import * as util from "./util";diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.jsindex 33bbae3cb0b..8b996f90d03 100644--- a/static/js/server_events_dispatch.js+++ b/static/js/server_events_dispatch.js@@ -44,6 +44,7 @@ import * as stream_events from "./stream_events";import * as stream_topic_history from "./stream_topic_history";import * as submessage from "./submessage";import * as typing_events from "./typing_events";+import * as unread_ops from "./unread_ops";import * as user_events from "./user_events";import * as user_groups from "./user_groups";import * as user_status from "./user_status";diff --git a/static/js/stream_popover.js b/static/js/stream_popover.jsindex c51aaaf8245..634116d2e91 100644--- a/static/js/stream_popover.js+++ b/static/js/stream_popover.js@@ -18,6 +18,7 @@ import * as resize from "./resize";import * as stream_color from "./stream_color";import * as stream_data from "./stream_data";import * as ui_util from "./ui_util";+import * as unread_ops from "./unread_ops";// We handle stream popovers and topic popovers in this// module. Both are popped up from the left sidebar.diff --git a/static/js/unread_ops.js b/static/js/unread_ops.jsindex 13afe90faee..3c7905adcfa 100644--- a/static/js/unread_ops.js+++ b/static/js/unread_ops.js@@ -1,16 +1,14 @@-"use strict";--const channel = require("./channel");-const message_flags = require("./message_flags");-const message_store = require("./message_store");-const message_viewport = require("./message_viewport");-const notifications = require("./notifications");-const overlays = require("./overlays");-const recent_topics = require("./recent_topics");-const reload = require("./reload");-const unread_ui = require("./unread_ui");--exports.mark_all_as_read = function () {+import * as channel from "./channel";+import * as message_flags from "./message_flags";+import * as message_store from "./message_store";+import * as message_viewport from "./message_viewport";+import * as notifications from "./notifications";+import * as overlays from "./overlays";+import * as recent_topics from "./recent_topics";+import * as reload from "./reload";+import * as unread_ui from "./unread_ui";++export function mark_all_as_read() {unread.declare_bankruptcy();unread_ui.update_unread_counts();@@ -28,7 +26,7 @@ exports.mark_all_as_read = function () {});},});-};+}function process_newly_read_message(message, options) {home_msg_list.show_message_as_read(message, options);@@ -40,7 +38,7 @@ function process_newly_read_message(message, options) {recent_topics.update_topic_unread_count(message);}-exports.process_read_messages_event = function (message_ids) {+export function process_read_messages_event(message_ids) {/*This code has a lot in common with notify_server_messages_read,but there are subtle differences due to the fact that the@@ -72,11 +70,11 @@ exports.process_read_messages_event = function (message_ids) {}unread_ui.update_unread_counts();-};+}// Takes a list of messages and marks them as read.// Skips any messages that are already marked as read.-exports.notify_server_messages_read = function (messages, options) {+export function notify_server_messages_read(messages, options) {options = options || {};messages = unread.get_unread_messages(messages);if (messages.length === 0) {@@ -95,44 +93,42 @@ exports.notify_server_messages_read = function (messages, options) {}unread_ui.update_unread_counts();-};+}-exports.notify_server_message_read = function (message, options) {- exports.notify_server_messages_read([message], options);-};+export function notify_server_message_read(message, options) {+ notify_server_messages_read([message], options);+}// If we ever materially change the algorithm for this function, we// may need to update notifications.received_messages as well.-exports.process_visible = function () {+export function process_visible() {if (overlays.is_active() || !notifications.is_window_focused()) {return;}if (message_viewport.bottom_message_visible() && current_msg_list.can_mark_messages_read()) {- exports.mark_current_list_as_read();+ mark_current_list_as_read();}-};+}-exports.mark_current_list_as_read = function (options) {- exports.notify_server_messages_read(current_msg_list.all_messages(), options);-};+export function mark_current_list_as_read(options) {+ notify_server_messages_read(current_msg_list.all_messages(), options);+}-exports.mark_stream_as_read = function (stream_id, cont) {+export function mark_stream_as_read(stream_id, cont) {channel.post({url: "/json/mark_stream_as_read",idempotent: true,data: {stream_id},success: cont,});-};+}-exports.mark_topic_as_read = function (stream_id, topic, cont) {+export function mark_topic_as_read(stream_id, topic, cont) {channel.post({url: "/json/mark_topic_as_read",idempotent: true,data: {stream_id, topic_name: topic},success: cont,});-};--window.unread_ops = exports;+}