Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/unread.js to ES6 module.

Anders Kaseorg727208b84c1e
diff --git a/.eslintrc.json b/.eslintrc.json
index 226272ed9db..453030a41dc 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -152,7 +152,6 @@
"subs": false,
"ui": false,
"ui_init": false,
- "unread": false,
"widgetize": false,
"zxcvbn": false
}
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index b1f56f08bda..5a4245c1423 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -90,7 +90,6 @@ rewiremock.enable();
const huddle_data = zrequire("huddle_data");
const compose_fade = zrequire("compose_fade");
-zrequire("unread");
const narrow = zrequire("narrow");
const presence = zrequire("presence");
const people = zrequire("people");
diff --git a/frontend_tests/node_tests/dispatch.js b/frontend_tests/node_tests/dispatch.js
index b6b3c228367..ce9298631e5 100644
--- a/frontend_tests/node_tests/dispatch.js
+++ b/frontend_tests/node_tests/dispatch.js
@@ -111,7 +111,6 @@ rewiremock.enable();
// For data-oriented modules, just use them, don't stub them.
const alert_words = zrequire("alert_words");
-zrequire("unread");
const stream_topic_history = zrequire("stream_topic_history");
const stream_list = zrequire("stream_list");
const message_store = zrequire("message_store");
diff --git a/frontend_tests/node_tests/filter.js b/frontend_tests/node_tests/filter.js
index b6dacf5a586..2a84a1634b2 100644
--- a/frontend_tests/node_tests/filter.js
+++ b/frontend_tests/node_tests/filter.js
@@ -14,7 +14,6 @@ const page_params = set_global("page_params", {});
rewiremock.enable();
-zrequire("unread");
const stream_data = zrequire("stream_data");
const people = zrequire("people");
const {Filter} = zrequire("Filter", "js/filter");
diff --git a/frontend_tests/node_tests/message_flags.js b/frontend_tests/node_tests/message_flags.js
index 32f6435a5f7..a5556964b19 100644
--- a/frontend_tests/node_tests/message_flags.js
+++ b/frontend_tests/node_tests/message_flags.js
@@ -14,7 +14,6 @@ rewiremock("../../static/js/starred_messages").with({
rewiremock.enable();
-zrequire("unread");
const message_flags = zrequire("message_flags");
const ui = set_global("ui", {});
diff --git a/frontend_tests/node_tests/message_list_data.js b/frontend_tests/node_tests/message_list_data.js
index 2308484ca2b..9ec38b180ff 100644
--- a/frontend_tests/node_tests/message_list_data.js
+++ b/frontend_tests/node_tests/message_list_data.js
@@ -13,7 +13,6 @@ set_global("setTimeout", (f, delay) => {
});
const muting = zrequire("muting");
-zrequire("unread");
const {MessageListData} = zrequire("MessageListData", "js/message_list_data");
function make_msg(msg_id) {
diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js
index e3fd54edffa..d9e7664400b 100644
--- a/frontend_tests/node_tests/message_list_view.js
+++ b/frontend_tests/node_tests/message_list_view.js
@@ -16,7 +16,7 @@ const page_params = set_global("page_params", {
twenty_four_hour_time: false,
});
set_global("home_msg_list", "stub");
-set_global("unread", {message_unread() {}});
+rewiremock("../../static/js/unread").with({message_unread() {}});
// timerender calls setInterval when imported
rewiremock("../../static/js/timerender").with({
render_date(time1, time2) {
diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js
index efc1f9737cb..e43701b06ca 100644
--- a/frontend_tests/node_tests/narrow_activate.js
+++ b/frontend_tests/node_tests/narrow_activate.js
@@ -67,7 +67,6 @@ rewiremock.enable();
const util = zrequire("util");
const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
-zrequire("unread");
const narrow = zrequire("narrow");
const denmark = {
diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.js
index 52f819cdf62..bd92bbb2cc2 100644
--- a/frontend_tests/node_tests/pm_list.js
+++ b/frontend_tests/node_tests/pm_list.js
@@ -16,7 +16,8 @@ set_global("ui", {
rewiremock("../../static/js/stream_popover").with({
hide_topic_popover() {},
});
-const unread = set_global("unread", {});
+const unread = {__esModule: true};
+rewiremock("../../static/js/unread").with(unread);
const unread_ui = {__esModule: true};
rewiremock("../../static/js/unread_ui").with(unread_ui);
const vdom = {
diff --git a/frontend_tests/node_tests/recent_topics.js b/frontend_tests/node_tests/recent_topics.js
index 6eecc9ce001..64d9abfa034 100644
--- a/frontend_tests/node_tests/recent_topics.js
+++ b/frontend_tests/node_tests/recent_topics.js
@@ -33,7 +33,7 @@ rewiremock("../../static/js/timerender").with({
time: "time",
}),
});
-set_global("unread", {
+rewiremock("../../static/js/unread").with({
unread_topic_counter: {
get: (stream_id, topic) => {
if (stream_id === 1 && topic === "topic-1") {
diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js
index 0b23ecf79c0..8e34d4a2482 100644
--- a/frontend_tests/node_tests/search_suggestion.js
+++ b/frontend_tests/node_tests/search_suggestion.js
@@ -29,7 +29,6 @@ const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
-zrequire("unread");
const search = zrequire("search_suggestion");
search.__Rewire__("max_num_of_search_results", 15);
diff --git a/frontend_tests/node_tests/search_suggestion_legacy.js b/frontend_tests/node_tests/search_suggestion_legacy.js
index 2d78872791b..96a426faff8 100644
--- a/frontend_tests/node_tests/search_suggestion_legacy.js
+++ b/frontend_tests/node_tests/search_suggestion_legacy.js
@@ -27,7 +27,6 @@ const narrow_state = zrequire("narrow_state");
const stream_data = zrequire("stream_data");
const stream_topic_history = zrequire("stream_topic_history");
const people = zrequire("people");
-zrequire("unread");
const search = zrequire("search_suggestion");
search.__Rewire__("max_num_of_search_results", 15);
diff --git a/frontend_tests/node_tests/topic_generator.js b/frontend_tests/node_tests/topic_generator.js
index 497a8294f02..12947eec8f5 100644
--- a/frontend_tests/node_tests/topic_generator.js
+++ b/frontend_tests/node_tests/topic_generator.js
@@ -100,8 +100,9 @@ run_test("topics", () => {
stream_data.__Rewire__("is_stream_muted_by_name", (stream_name) => stream_name === "muted");
- unread.topic_has_any_unread = (stream_id) =>
- [devel_stream_id, muted_stream_id].includes(stream_id);
+ unread.__Rewire__("topic_has_any_unread", (stream_id) =>
+ [devel_stream_id, muted_stream_id].includes(stream_id),
+ );
muting.__Rewire__("is_topic_muted", (stream_name, topic) => topic === "muted");
@@ -121,7 +122,7 @@ run_test("topics", () => {
run_test("get_next_unread_pm_string", () => {
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
- unread.num_unread_for_person = (user_ids_string) => {
+ unread.__Rewire__("num_unread_for_person", (user_ids_string) => {
if (user_ids_string === "unk") {
return undefined;
}
@@ -131,7 +132,7 @@ run_test("get_next_unread_pm_string", () => {
}
return 5; // random non-zero value
- };
+ });
assert.equal(tg.get_next_unread_pm_string(), "1");
assert.equal(tg.get_next_unread_pm_string("4"), "1");
@@ -141,7 +142,7 @@ run_test("get_next_unread_pm_string", () => {
assert.equal(tg.get_next_unread_pm_string("read"), "2,3");
assert.equal(tg.get_next_unread_pm_string("2,3"), "4");
- unread.num_unread_for_person = () => 0;
+ unread.__Rewire__("num_unread_for_person", () => 0);
assert.equal(tg.get_next_unread_pm_string("2,3"), undefined);
});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index a8f090f9bbf..886589c1b7f 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -111,7 +111,6 @@ rewiremock.enable();
const util = zrequire("util");
-zrequire("unread");
const upload = zrequire("upload");
const compose = zrequire("compose");
zrequire("composebox_typeahead");
diff --git a/static/js/buddy_data.js b/static/js/buddy_data.js
index 4d7f682ffc5..9c5f862b631 100644
--- a/static/js/buddy_data.js
+++ b/static/js/buddy_data.js
@@ -3,6 +3,7 @@ import * as hash_util from "./hash_util";
import * as people from "./people";
import * as presence from "./presence";
import * as timerender from "./timerender";
+import * as unread from "./unread";
import * as user_status from "./user_status";
import * as util from "./util";
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 354eff2ccc6..f64df8a0212 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";
import "../stream_list";
import "../widgetize";
import "../message_list";
diff --git a/static/js/filter.js b/static/js/filter.js
index 16e1e73b82f..d540c289231 100644
--- a/static/js/filter.js
+++ b/static/js/filter.js
@@ -5,6 +5,7 @@ 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 unread from "./unread";
import * as util from "./util";
function zephyr_stream_name_match(message, operand) {
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 94905d3eb87..d082dd9bfd4 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -21,7 +21,6 @@ declare let settings_profile_fields: any;
declare let stream_list: any;
declare let subs: any;
declare let ui: any;
-declare let unread: any;
declare let widgetize: any;
declare let zulip_test: any;
diff --git a/static/js/message_events.js b/static/js/message_events.js
index d665f1eb7e7..0bf4e37ad4f 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 = require("./unread");
const unread_ops = require("./unread_ops");
const unread_ui = require("./unread_ui");
const util = require("./util");
diff --git a/static/js/message_list_data.js b/static/js/message_list_data.js
index bfe6ee11ed6..1a1c833a7e7 100644
--- a/static/js/message_list_data.js
+++ b/static/js/message_list_data.js
@@ -3,6 +3,7 @@ import _ from "lodash";
import {FetchStatus} from "./fetch_status";
import {Filter} from "./filter";
import * as muting from "./muting";
+import * as unread from "./unread";
import * as util from "./util";
export class MessageListData {
diff --git a/static/js/message_util.js b/static/js/message_util.js
index 4db20a921ab..59ff9bac65d 100644
--- a/static/js/message_util.js
+++ b/static/js/message_util.js
@@ -1,6 +1,7 @@
import * as loading from "./loading";
import * as message_store from "./message_store";
import * as resize from "./resize";
+import * as unread from "./unread";
import * as unread_ui from "./unread_ui";
export function do_unread_count_updates(messages) {
diff --git a/static/js/narrow.js b/static/js/narrow.js
index e23807d93b8..6851af01209 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 = require("./unread");
const unread_ops = require("./unread_ops");
const util = require("./util");
diff --git a/static/js/narrow_state.js b/static/js/narrow_state.js
index 791107845ef..2a6adb598f8 100644
--- a/static/js/narrow_state.js
+++ b/static/js/narrow_state.js
@@ -1,6 +1,7 @@
import {Filter} from "./filter";
import * as people from "./people";
import * as stream_data from "./stream_data";
+import * as unread from "./unread";
let current_filter;
diff --git a/static/js/notifications.js b/static/js/notifications.js
index 4549eb655d9..d7308fec5c7 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 from "./unread";
import * as unread_ops from "./unread_ops";
const notice_memory = new Map();
diff --git a/static/js/pm_list.js b/static/js/pm_list.js
index d96a3a4d49a..e6ff87965eb 100644
--- a/static/js/pm_list.js
+++ b/static/js/pm_list.js
@@ -5,6 +5,7 @@ import * as people from "./people";
import * as pm_conversations from "./pm_conversations";
import * as pm_list_dom from "./pm_list_dom";
import * as stream_popover from "./stream_popover";
+import * as unread from "./unread";
import * as unread_ui from "./unread_ui";
import * as vdom from "./vdom";
diff --git a/static/js/recent_topics.js b/static/js/recent_topics.js
index 73e15a7dff6..074ab768ec2 100644
--- a/static/js/recent_topics.js
+++ b/static/js/recent_topics.js
@@ -18,6 +18,7 @@ import * as recent_senders from "./recent_senders";
import * as stream_data from "./stream_data";
import * as timerender from "./timerender";
import * as top_left_corner from "./top_left_corner";
+import * as unread from "./unread";
const topics = new Map(); // Key is stream-id:topic.
let topics_widget;
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index 975a9e01143..d37a85b842a 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -18,6 +18,7 @@ const stream_popover = require("./stream_popover");
const stream_sort = require("./stream_sort");
const topic_list = require("./topic_list");
const topic_zoom = require("./topic_zoom");
+const unread = require("./unread");
let has_scrolled = false;
diff --git a/static/js/stream_topic_history.js b/static/js/stream_topic_history.js
index dcfb2c23a59..aea7855723e 100644
--- a/static/js/stream_topic_history.js
+++ b/static/js/stream_topic_history.js
@@ -2,6 +2,7 @@ import * as channel from "./channel";
import {FoldDict} from "./fold_dict";
import * as message_util from "./message_util";
import * as stream_data from "./stream_data";
+import * as unread from "./unread";
const stream_dict = new Map(); // stream_id -> PerStreamHistory object
const fetched_stream_ids = new Set();
diff --git a/static/js/topic_generator.js b/static/js/topic_generator.js
index c3ab08913f4..35bf97ff5f7 100644
--- a/static/js/topic_generator.js
+++ b/static/js/topic_generator.js
@@ -3,6 +3,7 @@ import * as pm_conversations from "./pm_conversations";
import * as stream_data from "./stream_data";
import * as stream_sort from "./stream_sort";
import * as stream_topic_history from "./stream_topic_history";
+import * as unread from "./unread";
export function next_topic(streams, get_topics, has_unread_messages, curr_stream, curr_topic) {
const curr_stream_index = streams.indexOf(curr_stream); // -1 if not found
diff --git a/static/js/topic_list_data.js b/static/js/topic_list_data.js
index 676b3c4d229..34d7115bf8d 100644
--- a/static/js/topic_list_data.js
+++ b/static/js/topic_list_data.js
@@ -2,6 +2,7 @@ import * as hash_util from "./hash_util";
import * as muting from "./muting";
import * as narrow_state from "./narrow_state";
import * as stream_topic_history from "./stream_topic_history";
+import * as unread from "./unread";
const max_topics = 5;
const max_topics_with_unread = 8;
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index ae495ad1f07..265951da6fd 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -62,6 +62,7 @@ import * as topic_zoom from "./topic_zoom";
import * as tutorial from "./tutorial";
import * as typing from "./typing";
import * as ui_util from "./ui_util";
+import * as unread from "./unread";
import * as unread_ui from "./unread_ui";
import * as user_groups from "./user_groups";
import * as user_status from "./user_status";
diff --git a/static/js/unread.js b/static/js/unread.js
index aa0ea3cae21..d1df3047924 100644
--- a/static/js/unread.js
+++ b/static/js/unread.js
@@ -1,12 +1,10 @@
-"use strict";
-
-const {FoldDict} = require("./fold_dict");
-const message_store = require("./message_store");
-const muting = require("./muting");
-const people = require("./people");
-const settings_notifications = require("./settings_notifications");
-const stream_data = require("./stream_data");
-const util = require("./util");
+import {FoldDict} from "./fold_dict";
+import * as message_store from "./message_store";
+import * as muting from "./muting";
+import * as people from "./people";
+import * as settings_notifications from "./settings_notifications";
+import * as stream_data from "./stream_data";
+import * as util from "./util";
// The unread module tracks the message IDs and locations of the
// user's unread messages. The tracking is initialized with
@@ -20,10 +18,11 @@ const util = require("./util");
// See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html
// for more details on how this system is designed.
-exports.messages_read_in_narrow = false;
-exports.set_messages_read_in_narrow = function (value) {
- exports.messages_read_in_narrow = value;
-};
+export let messages_read_in_narrow = false;
+
+export function set_messages_read_in_narrow(value) {
+ messages_read_in_narrow = value;
+}
const unread_messages = new Set();
@@ -184,7 +183,7 @@ class UnreadPMCounter {
return util.sorted_ids(ids);
}
}
-exports.unread_pm_counter = new UnreadPMCounter();
+export const unread_pm_counter = new UnreadPMCounter();
function make_per_stream_bucketer() {
return new Bucketer({
@@ -370,26 +369,25 @@ class UnreadTopicCounter {
return id_set.size !== 0;
}
}
-exports.unread_topic_counter = new UnreadTopicCounter();
-
-exports.unread_mentions_counter = new Set();
+export const unread_topic_counter = new UnreadTopicCounter();
+export const unread_mentions_counter = new Set();
-exports.message_unread = function (message) {
+export function message_unread(message) {
if (message === undefined) {
return false;
}
return message.unread;
-};
+}
-exports.get_unread_message_ids = function (message_ids) {
+export function get_unread_message_ids(message_ids) {
return message_ids.filter((message_id) => unread_messages.has(message_id));
-};
+}
-exports.get_unread_messages = function (messages) {
+export function get_unread_messages(messages) {
return messages.filter((message) => unread_messages.has(message.id));
-};
+}
-exports.update_unread_topics = function (msg, event) {
+export function update_unread_topics(msg, event) {
const new_topic = util.get_edit_event_topic(event);
const {new_stream_id} = event;
@@ -401,16 +399,12 @@ exports.update_unread_topics = function (msg, event) {
return;
}
- exports.unread_topic_counter.delete(msg.id);
+ unread_topic_counter.delete(msg.id);
- exports.unread_topic_counter.add(
- new_stream_id || msg.stream_id,
- new_topic || msg.topic,
- msg.id,
- );
-};
+ unread_topic_counter.add(new_stream_id || msg.stream_id, new_topic || msg.topic, msg.id);
+}
-exports.process_loaded_messages = function (messages) {
+export function process_loaded_messages(messages) {
for (const message of messages) {
if (!message.unread) {
continue;
@@ -419,20 +413,20 @@ exports.process_loaded_messages = function (messages) {
unread_messages.add(message.id);
if (message.type === "private") {
- exports.unread_pm_counter.add(message);
+ unread_pm_counter.add(message);
}
if (message.type === "stream") {
- exports.unread_topic_counter.add(message.stream_id, message.topic, message.id);
+ unread_topic_counter.add(message.stream_id, message.topic, message.id);
}
- exports.update_message_for_mention(message);
+ update_message_for_mention(message);
}
-};
+}
-exports.update_message_for_mention = function (message) {
+export function update_message_for_mention(message) {
if (!message.unread) {
- exports.unread_mentions_counter.delete(message.id);
+ unread_mentions_counter.delete(message.id);
return;
}
@@ -442,58 +436,58 @@ exports.update_message_for_mention = function (message) {
!muting.is_topic_muted(message.stream_id, message.topic);
if (is_unmuted_mention || message.mentioned_me_directly) {
- exports.unread_mentions_counter.add(message.id);
+ unread_mentions_counter.add(message.id);
} else {
- exports.unread_mentions_counter.delete(message.id);
+ unread_mentions_counter.delete(message.id);
}
-};
+}
-exports.mark_as_read = function (message_id) {
+export function mark_as_read(message_id) {
// We don't need to check anything about the message, since all
// the following methods are cheap and work fine even if message_id
// was never set to unread.
- exports.unread_pm_counter.delete(message_id);
- exports.unread_topic_counter.delete(message_id);
- exports.unread_mentions_counter.delete(message_id);
+ unread_pm_counter.delete(message_id);
+ unread_topic_counter.delete(message_id);
+ unread_mentions_counter.delete(message_id);
unread_messages.delete(message_id);
const message = message_store.get(message_id);
if (message) {
message.unread = false;
}
-};
+}
-exports.declare_bankruptcy = function () {
- exports.unread_pm_counter.clear();
- exports.unread_topic_counter.clear();
- exports.unread_mentions_counter.clear();
+export function declare_bankruptcy() {
+ unread_pm_counter.clear();
+ unread_topic_counter.clear();
+ unread_mentions_counter.clear();
unread_messages.clear();
-};
+}
-exports.get_counts = function () {
+export function get_counts() {
const res = {};
// Return a data structure with various counts. This function should be
// pretty cheap, even if you don't care about all the counts, and you
// should strive to keep it free of side effects on globals or DOM.
res.private_message_count = 0;
- res.mentioned_message_count = exports.unread_mentions_counter.size;
+ res.mentioned_message_count = unread_mentions_counter.size;
// This sets stream_count, topic_count, and home_unread_messages
- const topic_res = exports.unread_topic_counter.get_counts();
+ const topic_res = unread_topic_counter.get_counts();
res.home_unread_messages = topic_res.stream_unread_messages;
res.stream_count = topic_res.stream_count;
- const pm_res = exports.unread_pm_counter.get_counts();
+ const pm_res = unread_pm_counter.get_counts();
res.pm_count = pm_res.pm_dict;
res.private_message_count = pm_res.total_count;
res.home_unread_messages += pm_res.total_count;
return res;
-};
+}
// Saves us from calling to get_counts() when we can avoid it.
-exports.calculate_notifiable_count = function (res) {
+export function calculate_notifiable_count(res) {
let new_message_count = 0;
const only_show_notifiable =
@@ -513,78 +507,78 @@ exports.calculate_notifiable_count = function (res) {
new_message_count = res.home_unread_messages;
}
return new_message_count;
-};
+}
-exports.get_notifiable_count = function () {
- const res = exports.get_counts();
- return exports.calculate_notifiable_count(res);
-};
+export function get_notifiable_count() {
+ const res = get_counts();
+ return calculate_notifiable_count(res);
+}
-exports.num_unread_for_stream = function (stream_id) {
- return exports.unread_topic_counter.get_stream_count(stream_id);
-};
+export function num_unread_for_stream(stream_id) {
+ return unread_topic_counter.get_stream_count(stream_id);
+}
-exports.num_unread_for_topic = function (stream_id, topic_name) {
- return exports.unread_topic_counter.get(stream_id, topic_name);
-};
+export function num_unread_for_topic(stream_id, topic_name) {
+ return unread_topic_counter.get(stream_id, topic_name);
+}
-exports.topic_has_any_unread = function (stream_id, topic) {
- return exports.unread_topic_counter.topic_has_any_unread(stream_id, topic);
-};
+export function topic_has_any_unread(stream_id, topic) {
+ return unread_topic_counter.topic_has_any_unread(stream_id, topic);
+}
-exports.num_unread_for_person = function (user_ids_string) {
- return exports.unread_pm_counter.num_unread(user_ids_string);
-};
+export function num_unread_for_person(user_ids_string) {
+ return unread_pm_counter.num_unread(user_ids_string);
+}
-exports.get_msg_ids_for_stream = function (stream_id) {
- return exports.unread_topic_counter.get_msg_ids_for_stream(stream_id);
-};
+export function get_msg_ids_for_stream(stream_id) {
+ return unread_topic_counter.get_msg_ids_for_stream(stream_id);
+}
-exports.get_msg_ids_for_topic = function (stream_id, topic_name) {
- return exports.unread_topic_counter.get_msg_ids_for_topic(stream_id, topic_name);
-};
+export function get_msg_ids_for_topic(stream_id, topic_name) {
+ return unread_topic_counter.get_msg_ids_for_topic(stream_id, topic_name);
+}
-exports.get_msg_ids_for_person = function (user_ids_string) {
- return exports.unread_pm_counter.get_msg_ids_for_person(user_ids_string);
-};
+export function get_msg_ids_for_person(user_ids_string) {
+ return unread_pm_counter.get_msg_ids_for_person(user_ids_string);
+}
-exports.get_msg_ids_for_private = function () {
- return exports.unread_pm_counter.get_msg_ids();
-};
+export function get_msg_ids_for_private() {
+ return unread_pm_counter.get_msg_ids();
+}
-exports.get_msg_ids_for_mentions = function () {
- const ids = Array.from(exports.unread_mentions_counter);
+export function get_msg_ids_for_mentions() {
+ const ids = Array.from(unread_mentions_counter);
return util.sorted_ids(ids);
-};
+}
-exports.get_all_msg_ids = function () {
+export function get_all_msg_ids() {
const ids = Array.from(unread_messages);
return util.sorted_ids(ids);
-};
+}
-exports.get_missing_topics = function (opts) {
- return exports.unread_topic_counter.get_missing_topics(opts);
-};
+export function get_missing_topics(opts) {
+ return unread_topic_counter.get_missing_topics(opts);
+}
-exports.get_msg_ids_for_starred = function () {
+export function get_msg_ids_for_starred() {
// This is here for API consistency sake--we never
// have unread starred messages. (Some day we may ironically
// want to make starring the same as mark-as-unread, but
// for now starring === reading.)
return [];
-};
+}
-exports.initialize = function () {
+export function initialize() {
const unread_msgs = page_params.unread_msgs;
- exports.unread_pm_counter.set_huddles(unread_msgs.huddles);
- exports.unread_pm_counter.set_pms(unread_msgs.pms);
- exports.unread_topic_counter.set_streams(unread_msgs.streams);
+ unread_pm_counter.set_huddles(unread_msgs.huddles);
+ unread_pm_counter.set_pms(unread_msgs.pms);
+ unread_topic_counter.set_streams(unread_msgs.streams);
for (const message_id of unread_msgs.mentions) {
- exports.unread_mentions_counter.add(message_id);
+ unread_mentions_counter.add(message_id);
}
for (const obj of unread_msgs.huddles) {
@@ -608,6 +602,4 @@ exports.initialize = function () {
for (const message_id of unread_msgs.mentions) {
unread_messages.add(message_id);
}
-};
-
-window.unread = exports;
+}
diff --git a/static/js/unread_ops.js b/static/js/unread_ops.js
index 3c7905adcfa..bf9a348da84 100644
--- a/static/js/unread_ops.js
+++ b/static/js/unread_ops.js
@@ -6,6 +6,7 @@ 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 from "./unread";
import * as unread_ui from "./unread_ui";
export function mark_all_as_read() {
diff --git a/static/js/unread_ui.js b/static/js/unread_ui.js
index 62f0be22b69..85084bb18f1 100644
--- a/static/js/unread_ui.js
+++ b/static/js/unread_ui.js
@@ -3,6 +3,7 @@ import * as notifications from "./notifications";
import * as pm_list from "./pm_list";
import * as top_left_corner from "./top_left_corner";
import * as topic_list from "./topic_list";
+import * as unread from "./unread";
let last_mention_count = 0;