mirror of https://github.com/zulip/zulip.git
js: Convert static/js/unread.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
9997e13032
commit
727208b84c
|
@ -152,7 +152,6 @@
|
||||||
"subs": false,
|
"subs": false,
|
||||||
"ui": false,
|
"ui": false,
|
||||||
"ui_init": false,
|
"ui_init": false,
|
||||||
"unread": false,
|
|
||||||
"widgetize": false,
|
"widgetize": false,
|
||||||
"zxcvbn": false
|
"zxcvbn": false
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ rewiremock.enable();
|
||||||
|
|
||||||
const huddle_data = zrequire("huddle_data");
|
const huddle_data = zrequire("huddle_data");
|
||||||
const compose_fade = zrequire("compose_fade");
|
const compose_fade = zrequire("compose_fade");
|
||||||
zrequire("unread");
|
|
||||||
const narrow = zrequire("narrow");
|
const narrow = zrequire("narrow");
|
||||||
const presence = zrequire("presence");
|
const presence = zrequire("presence");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
|
|
|
@ -111,7 +111,6 @@ rewiremock.enable();
|
||||||
|
|
||||||
// For data-oriented modules, just use them, don't stub them.
|
// For data-oriented modules, just use them, don't stub them.
|
||||||
const alert_words = zrequire("alert_words");
|
const alert_words = zrequire("alert_words");
|
||||||
zrequire("unread");
|
|
||||||
const stream_topic_history = zrequire("stream_topic_history");
|
const stream_topic_history = zrequire("stream_topic_history");
|
||||||
const stream_list = zrequire("stream_list");
|
const stream_list = zrequire("stream_list");
|
||||||
const message_store = zrequire("message_store");
|
const message_store = zrequire("message_store");
|
||||||
|
|
|
@ -14,7 +14,6 @@ const page_params = set_global("page_params", {});
|
||||||
|
|
||||||
rewiremock.enable();
|
rewiremock.enable();
|
||||||
|
|
||||||
zrequire("unread");
|
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const {Filter} = zrequire("Filter", "js/filter");
|
const {Filter} = zrequire("Filter", "js/filter");
|
||||||
|
|
|
@ -14,7 +14,6 @@ rewiremock("../../static/js/starred_messages").with({
|
||||||
|
|
||||||
rewiremock.enable();
|
rewiremock.enable();
|
||||||
|
|
||||||
zrequire("unread");
|
|
||||||
const message_flags = zrequire("message_flags");
|
const message_flags = zrequire("message_flags");
|
||||||
|
|
||||||
const ui = set_global("ui", {});
|
const ui = set_global("ui", {});
|
||||||
|
|
|
@ -13,7 +13,6 @@ set_global("setTimeout", (f, delay) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
const muting = zrequire("muting");
|
const muting = zrequire("muting");
|
||||||
zrequire("unread");
|
|
||||||
const {MessageListData} = zrequire("MessageListData", "js/message_list_data");
|
const {MessageListData} = zrequire("MessageListData", "js/message_list_data");
|
||||||
|
|
||||||
function make_msg(msg_id) {
|
function make_msg(msg_id) {
|
||||||
|
|
|
@ -16,7 +16,7 @@ const page_params = set_global("page_params", {
|
||||||
twenty_four_hour_time: false,
|
twenty_four_hour_time: false,
|
||||||
});
|
});
|
||||||
set_global("home_msg_list", "stub");
|
set_global("home_msg_list", "stub");
|
||||||
set_global("unread", {message_unread() {}});
|
rewiremock("../../static/js/unread").with({message_unread() {}});
|
||||||
// timerender calls setInterval when imported
|
// timerender calls setInterval when imported
|
||||||
rewiremock("../../static/js/timerender").with({
|
rewiremock("../../static/js/timerender").with({
|
||||||
render_date(time1, time2) {
|
render_date(time1, time2) {
|
||||||
|
|
|
@ -67,7 +67,6 @@ rewiremock.enable();
|
||||||
const util = zrequire("util");
|
const util = zrequire("util");
|
||||||
const narrow_state = zrequire("narrow_state");
|
const narrow_state = zrequire("narrow_state");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
zrequire("unread");
|
|
||||||
const narrow = zrequire("narrow");
|
const narrow = zrequire("narrow");
|
||||||
|
|
||||||
const denmark = {
|
const denmark = {
|
||||||
|
|
|
@ -16,7 +16,8 @@ set_global("ui", {
|
||||||
rewiremock("../../static/js/stream_popover").with({
|
rewiremock("../../static/js/stream_popover").with({
|
||||||
hide_topic_popover() {},
|
hide_topic_popover() {},
|
||||||
});
|
});
|
||||||
const unread = set_global("unread", {});
|
const unread = {__esModule: true};
|
||||||
|
rewiremock("../../static/js/unread").with(unread);
|
||||||
const unread_ui = {__esModule: true};
|
const unread_ui = {__esModule: true};
|
||||||
rewiremock("../../static/js/unread_ui").with(unread_ui);
|
rewiremock("../../static/js/unread_ui").with(unread_ui);
|
||||||
const vdom = {
|
const vdom = {
|
||||||
|
|
|
@ -33,7 +33,7 @@ rewiremock("../../static/js/timerender").with({
|
||||||
time: "time",
|
time: "time",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
set_global("unread", {
|
rewiremock("../../static/js/unread").with({
|
||||||
unread_topic_counter: {
|
unread_topic_counter: {
|
||||||
get: (stream_id, topic) => {
|
get: (stream_id, topic) => {
|
||||||
if (stream_id === 1 && topic === "topic-1") {
|
if (stream_id === 1 && topic === "topic-1") {
|
||||||
|
|
|
@ -29,7 +29,6 @@ const narrow_state = zrequire("narrow_state");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const stream_topic_history = zrequire("stream_topic_history");
|
const stream_topic_history = zrequire("stream_topic_history");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
zrequire("unread");
|
|
||||||
const search = zrequire("search_suggestion");
|
const search = zrequire("search_suggestion");
|
||||||
|
|
||||||
search.__Rewire__("max_num_of_search_results", 15);
|
search.__Rewire__("max_num_of_search_results", 15);
|
||||||
|
|
|
@ -27,7 +27,6 @@ const narrow_state = zrequire("narrow_state");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
const stream_topic_history = zrequire("stream_topic_history");
|
const stream_topic_history = zrequire("stream_topic_history");
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
zrequire("unread");
|
|
||||||
const search = zrequire("search_suggestion");
|
const search = zrequire("search_suggestion");
|
||||||
|
|
||||||
search.__Rewire__("max_num_of_search_results", 15);
|
search.__Rewire__("max_num_of_search_results", 15);
|
||||||
|
|
|
@ -100,8 +100,9 @@ run_test("topics", () => {
|
||||||
|
|
||||||
stream_data.__Rewire__("is_stream_muted_by_name", (stream_name) => stream_name === "muted");
|
stream_data.__Rewire__("is_stream_muted_by_name", (stream_name) => stream_name === "muted");
|
||||||
|
|
||||||
unread.topic_has_any_unread = (stream_id) =>
|
unread.__Rewire__("topic_has_any_unread", (stream_id) =>
|
||||||
[devel_stream_id, muted_stream_id].includes(stream_id);
|
[devel_stream_id, muted_stream_id].includes(stream_id),
|
||||||
|
);
|
||||||
|
|
||||||
muting.__Rewire__("is_topic_muted", (stream_name, topic) => topic === "muted");
|
muting.__Rewire__("is_topic_muted", (stream_name, topic) => topic === "muted");
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ run_test("topics", () => {
|
||||||
run_test("get_next_unread_pm_string", () => {
|
run_test("get_next_unread_pm_string", () => {
|
||||||
pm_conversations.recent.get_strings = () => ["1", "read", "2,3", "4", "unk"];
|
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") {
|
if (user_ids_string === "unk") {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +132,7 @@ run_test("get_next_unread_pm_string", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return 5; // random non-zero value
|
return 5; // random non-zero value
|
||||||
};
|
});
|
||||||
|
|
||||||
assert.equal(tg.get_next_unread_pm_string(), "1");
|
assert.equal(tg.get_next_unread_pm_string(), "1");
|
||||||
assert.equal(tg.get_next_unread_pm_string("4"), "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("read"), "2,3");
|
||||||
assert.equal(tg.get_next_unread_pm_string("2,3"), "4");
|
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);
|
assert.equal(tg.get_next_unread_pm_string("2,3"), undefined);
|
||||||
});
|
});
|
||||||
|
|
|
@ -111,7 +111,6 @@ rewiremock.enable();
|
||||||
|
|
||||||
const util = zrequire("util");
|
const util = zrequire("util");
|
||||||
|
|
||||||
zrequire("unread");
|
|
||||||
const upload = zrequire("upload");
|
const upload = zrequire("upload");
|
||||||
const compose = zrequire("compose");
|
const compose = zrequire("compose");
|
||||||
zrequire("composebox_typeahead");
|
zrequire("composebox_typeahead");
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as hash_util from "./hash_util";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as presence from "./presence";
|
import * as presence from "./presence";
|
||||||
import * as timerender from "./timerender";
|
import * as timerender from "./timerender";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as user_status from "./user_status";
|
import * as user_status from "./user_status";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
|
||||||
import "../i18n";
|
import "../i18n";
|
||||||
import "../fold_dict";
|
import "../fold_dict";
|
||||||
import "../setup";
|
import "../setup";
|
||||||
import "../unread";
|
|
||||||
import "../stream_list";
|
import "../stream_list";
|
||||||
import "../widgetize";
|
import "../widgetize";
|
||||||
import "../message_list";
|
import "../message_list";
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as message_store from "./message_store";
|
||||||
import * as message_util from "./message_util";
|
import * as message_util from "./message_util";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
function zephyr_stream_name_match(message, operand) {
|
function zephyr_stream_name_match(message, operand) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ declare let settings_profile_fields: any;
|
||||||
declare let stream_list: any;
|
declare let stream_list: any;
|
||||||
declare let subs: any;
|
declare let subs: any;
|
||||||
declare let ui: any;
|
declare let ui: any;
|
||||||
declare let unread: any;
|
|
||||||
declare let widgetize: any;
|
declare let widgetize: any;
|
||||||
declare let zulip_test: any;
|
declare let zulip_test: any;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ const recent_topics = require("./recent_topics");
|
||||||
const resize = require("./resize");
|
const resize = require("./resize");
|
||||||
const stream_data = require("./stream_data");
|
const stream_data = require("./stream_data");
|
||||||
const stream_topic_history = require("./stream_topic_history");
|
const stream_topic_history = require("./stream_topic_history");
|
||||||
|
const unread = require("./unread");
|
||||||
const unread_ops = require("./unread_ops");
|
const unread_ops = require("./unread_ops");
|
||||||
const unread_ui = require("./unread_ui");
|
const unread_ui = require("./unread_ui");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|
|
@ -3,6 +3,7 @@ import _ from "lodash";
|
||||||
import {FetchStatus} from "./fetch_status";
|
import {FetchStatus} from "./fetch_status";
|
||||||
import {Filter} from "./filter";
|
import {Filter} from "./filter";
|
||||||
import * as muting from "./muting";
|
import * as muting from "./muting";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
export class MessageListData {
|
export class MessageListData {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as loading from "./loading";
|
import * as loading from "./loading";
|
||||||
import * as message_store from "./message_store";
|
import * as message_store from "./message_store";
|
||||||
import * as resize from "./resize";
|
import * as resize from "./resize";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as unread_ui from "./unread_ui";
|
import * as unread_ui from "./unread_ui";
|
||||||
|
|
||||||
export function do_unread_count_updates(messages) {
|
export function do_unread_count_updates(messages) {
|
||||||
|
|
|
@ -27,6 +27,7 @@ const top_left_corner = require("./top_left_corner");
|
||||||
const topic_generator = require("./topic_generator");
|
const topic_generator = require("./topic_generator");
|
||||||
const typing_events = require("./typing_events");
|
const typing_events = require("./typing_events");
|
||||||
const ui_util = require("./ui_util");
|
const ui_util = require("./ui_util");
|
||||||
|
const unread = require("./unread");
|
||||||
const unread_ops = require("./unread_ops");
|
const unread_ops = require("./unread_ops");
|
||||||
const util = require("./util");
|
const util = require("./util");
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import {Filter} from "./filter";
|
import {Filter} from "./filter";
|
||||||
import * as people from "./people";
|
import * as people from "./people";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
|
||||||
let current_filter;
|
let current_filter;
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import * as settings_config from "./settings_config";
|
||||||
import * as spoilers from "./spoilers";
|
import * as spoilers from "./spoilers";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as stream_ui_updates from "./stream_ui_updates";
|
import * as stream_ui_updates from "./stream_ui_updates";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as unread_ops from "./unread_ops";
|
import * as unread_ops from "./unread_ops";
|
||||||
|
|
||||||
const notice_memory = new Map();
|
const notice_memory = new Map();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import * as people from "./people";
|
||||||
import * as pm_conversations from "./pm_conversations";
|
import * as pm_conversations from "./pm_conversations";
|
||||||
import * as pm_list_dom from "./pm_list_dom";
|
import * as pm_list_dom from "./pm_list_dom";
|
||||||
import * as stream_popover from "./stream_popover";
|
import * as stream_popover from "./stream_popover";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as unread_ui from "./unread_ui";
|
import * as unread_ui from "./unread_ui";
|
||||||
import * as vdom from "./vdom";
|
import * as vdom from "./vdom";
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import * as recent_senders from "./recent_senders";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as timerender from "./timerender";
|
import * as timerender from "./timerender";
|
||||||
import * as top_left_corner from "./top_left_corner";
|
import * as top_left_corner from "./top_left_corner";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
|
||||||
const topics = new Map(); // Key is stream-id:topic.
|
const topics = new Map(); // Key is stream-id:topic.
|
||||||
let topics_widget;
|
let topics_widget;
|
||||||
|
|
|
@ -18,6 +18,7 @@ const stream_popover = require("./stream_popover");
|
||||||
const stream_sort = require("./stream_sort");
|
const stream_sort = require("./stream_sort");
|
||||||
const topic_list = require("./topic_list");
|
const topic_list = require("./topic_list");
|
||||||
const topic_zoom = require("./topic_zoom");
|
const topic_zoom = require("./topic_zoom");
|
||||||
|
const unread = require("./unread");
|
||||||
|
|
||||||
let has_scrolled = false;
|
let has_scrolled = false;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as channel from "./channel";
|
||||||
import {FoldDict} from "./fold_dict";
|
import {FoldDict} from "./fold_dict";
|
||||||
import * as message_util from "./message_util";
|
import * as message_util from "./message_util";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
|
||||||
const stream_dict = new Map(); // stream_id -> PerStreamHistory object
|
const stream_dict = new Map(); // stream_id -> PerStreamHistory object
|
||||||
const fetched_stream_ids = new Set();
|
const fetched_stream_ids = new Set();
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as pm_conversations from "./pm_conversations";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as stream_sort from "./stream_sort";
|
import * as stream_sort from "./stream_sort";
|
||||||
import * as stream_topic_history from "./stream_topic_history";
|
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) {
|
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
|
const curr_stream_index = streams.indexOf(curr_stream); // -1 if not found
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as hash_util from "./hash_util";
|
||||||
import * as muting from "./muting";
|
import * as muting from "./muting";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as stream_topic_history from "./stream_topic_history";
|
import * as stream_topic_history from "./stream_topic_history";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
|
||||||
const max_topics = 5;
|
const max_topics = 5;
|
||||||
const max_topics_with_unread = 8;
|
const max_topics_with_unread = 8;
|
||||||
|
|
|
@ -62,6 +62,7 @@ import * as topic_zoom from "./topic_zoom";
|
||||||
import * as tutorial from "./tutorial";
|
import * as tutorial from "./tutorial";
|
||||||
import * as typing from "./typing";
|
import * as typing from "./typing";
|
||||||
import * as ui_util from "./ui_util";
|
import * as ui_util from "./ui_util";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as unread_ui from "./unread_ui";
|
import * as unread_ui from "./unread_ui";
|
||||||
import * as user_groups from "./user_groups";
|
import * as user_groups from "./user_groups";
|
||||||
import * as user_status from "./user_status";
|
import * as user_status from "./user_status";
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
"use strict";
|
import {FoldDict} from "./fold_dict";
|
||||||
|
import * as message_store from "./message_store";
|
||||||
const {FoldDict} = require("./fold_dict");
|
import * as muting from "./muting";
|
||||||
const message_store = require("./message_store");
|
import * as people from "./people";
|
||||||
const muting = require("./muting");
|
import * as settings_notifications from "./settings_notifications";
|
||||||
const people = require("./people");
|
import * as stream_data from "./stream_data";
|
||||||
const settings_notifications = require("./settings_notifications");
|
import * as util from "./util";
|
||||||
const stream_data = require("./stream_data");
|
|
||||||
const util = require("./util");
|
|
||||||
|
|
||||||
// The unread module tracks the message IDs and locations of the
|
// The unread module tracks the message IDs and locations of the
|
||||||
// user's unread messages. The tracking is initialized with
|
// 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
|
// See https://zulip.readthedocs.io/en/latest/subsystems/pointer.html
|
||||||
// for more details on how this system is designed.
|
// for more details on how this system is designed.
|
||||||
|
|
||||||
exports.messages_read_in_narrow = false;
|
export let messages_read_in_narrow = false;
|
||||||
exports.set_messages_read_in_narrow = function (value) {
|
|
||||||
exports.messages_read_in_narrow = value;
|
export function set_messages_read_in_narrow(value) {
|
||||||
};
|
messages_read_in_narrow = value;
|
||||||
|
}
|
||||||
|
|
||||||
const unread_messages = new Set();
|
const unread_messages = new Set();
|
||||||
|
|
||||||
|
@ -184,7 +183,7 @@ class UnreadPMCounter {
|
||||||
return util.sorted_ids(ids);
|
return util.sorted_ids(ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.unread_pm_counter = new UnreadPMCounter();
|
export const unread_pm_counter = new UnreadPMCounter();
|
||||||
|
|
||||||
function make_per_stream_bucketer() {
|
function make_per_stream_bucketer() {
|
||||||
return new Bucketer({
|
return new Bucketer({
|
||||||
|
@ -370,26 +369,25 @@ class UnreadTopicCounter {
|
||||||
return id_set.size !== 0;
|
return id_set.size !== 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.unread_topic_counter = new UnreadTopicCounter();
|
export const unread_topic_counter = new UnreadTopicCounter();
|
||||||
|
export const unread_mentions_counter = new Set();
|
||||||
|
|
||||||
exports.unread_mentions_counter = new Set();
|
export function message_unread(message) {
|
||||||
|
|
||||||
exports.message_unread = function (message) {
|
|
||||||
if (message === undefined) {
|
if (message === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return message.unread;
|
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));
|
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));
|
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_topic = util.get_edit_event_topic(event);
|
||||||
const {new_stream_id} = event;
|
const {new_stream_id} = event;
|
||||||
|
|
||||||
|
@ -401,16 +399,12 @@ exports.update_unread_topics = function (msg, event) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.unread_topic_counter.delete(msg.id);
|
unread_topic_counter.delete(msg.id);
|
||||||
|
|
||||||
exports.unread_topic_counter.add(
|
unread_topic_counter.add(new_stream_id || msg.stream_id, new_topic || msg.topic, msg.id);
|
||||||
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) {
|
for (const message of messages) {
|
||||||
if (!message.unread) {
|
if (!message.unread) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -419,20 +413,20 @@ exports.process_loaded_messages = function (messages) {
|
||||||
unread_messages.add(message.id);
|
unread_messages.add(message.id);
|
||||||
|
|
||||||
if (message.type === "private") {
|
if (message.type === "private") {
|
||||||
exports.unread_pm_counter.add(message);
|
unread_pm_counter.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === "stream") {
|
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) {
|
if (!message.unread) {
|
||||||
exports.unread_mentions_counter.delete(message.id);
|
unread_mentions_counter.delete(message.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,58 +436,58 @@ exports.update_message_for_mention = function (message) {
|
||||||
!muting.is_topic_muted(message.stream_id, message.topic);
|
!muting.is_topic_muted(message.stream_id, message.topic);
|
||||||
|
|
||||||
if (is_unmuted_mention || message.mentioned_me_directly) {
|
if (is_unmuted_mention || message.mentioned_me_directly) {
|
||||||
exports.unread_mentions_counter.add(message.id);
|
unread_mentions_counter.add(message.id);
|
||||||
} else {
|
} 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
|
// We don't need to check anything about the message, since all
|
||||||
// the following methods are cheap and work fine even if message_id
|
// the following methods are cheap and work fine even if message_id
|
||||||
// was never set to unread.
|
// was never set to unread.
|
||||||
exports.unread_pm_counter.delete(message_id);
|
unread_pm_counter.delete(message_id);
|
||||||
exports.unread_topic_counter.delete(message_id);
|
unread_topic_counter.delete(message_id);
|
||||||
exports.unread_mentions_counter.delete(message_id);
|
unread_mentions_counter.delete(message_id);
|
||||||
unread_messages.delete(message_id);
|
unread_messages.delete(message_id);
|
||||||
|
|
||||||
const message = message_store.get(message_id);
|
const message = message_store.get(message_id);
|
||||||
if (message) {
|
if (message) {
|
||||||
message.unread = false;
|
message.unread = false;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.declare_bankruptcy = function () {
|
export function declare_bankruptcy() {
|
||||||
exports.unread_pm_counter.clear();
|
unread_pm_counter.clear();
|
||||||
exports.unread_topic_counter.clear();
|
unread_topic_counter.clear();
|
||||||
exports.unread_mentions_counter.clear();
|
unread_mentions_counter.clear();
|
||||||
unread_messages.clear();
|
unread_messages.clear();
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_counts = function () {
|
export function get_counts() {
|
||||||
const res = {};
|
const res = {};
|
||||||
|
|
||||||
// Return a data structure with various counts. This function should be
|
// 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
|
// 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.
|
// should strive to keep it free of side effects on globals or DOM.
|
||||||
res.private_message_count = 0;
|
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
|
// 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.home_unread_messages = topic_res.stream_unread_messages;
|
||||||
res.stream_count = topic_res.stream_count;
|
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.pm_count = pm_res.pm_dict;
|
||||||
res.private_message_count = pm_res.total_count;
|
res.private_message_count = pm_res.total_count;
|
||||||
res.home_unread_messages += pm_res.total_count;
|
res.home_unread_messages += pm_res.total_count;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Saves us from calling to get_counts() when we can avoid it.
|
// 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;
|
let new_message_count = 0;
|
||||||
|
|
||||||
const only_show_notifiable =
|
const only_show_notifiable =
|
||||||
|
@ -513,78 +507,78 @@ exports.calculate_notifiable_count = function (res) {
|
||||||
new_message_count = res.home_unread_messages;
|
new_message_count = res.home_unread_messages;
|
||||||
}
|
}
|
||||||
return new_message_count;
|
return new_message_count;
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_notifiable_count = function () {
|
export function get_notifiable_count() {
|
||||||
const res = exports.get_counts();
|
const res = get_counts();
|
||||||
return exports.calculate_notifiable_count(res);
|
return calculate_notifiable_count(res);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.num_unread_for_stream = function (stream_id) {
|
export function num_unread_for_stream(stream_id) {
|
||||||
return exports.unread_topic_counter.get_stream_count(stream_id);
|
return unread_topic_counter.get_stream_count(stream_id);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.num_unread_for_topic = function (stream_id, topic_name) {
|
export function num_unread_for_topic(stream_id, topic_name) {
|
||||||
return exports.unread_topic_counter.get(stream_id, topic_name);
|
return unread_topic_counter.get(stream_id, topic_name);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.topic_has_any_unread = function (stream_id, topic) {
|
export function topic_has_any_unread(stream_id, topic) {
|
||||||
return exports.unread_topic_counter.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) {
|
export function num_unread_for_person(user_ids_string) {
|
||||||
return exports.unread_pm_counter.num_unread(user_ids_string);
|
return unread_pm_counter.num_unread(user_ids_string);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_msg_ids_for_stream = function (stream_id) {
|
export function get_msg_ids_for_stream(stream_id) {
|
||||||
return exports.unread_topic_counter.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) {
|
export function get_msg_ids_for_topic(stream_id, topic_name) {
|
||||||
return exports.unread_topic_counter.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) {
|
export function get_msg_ids_for_person(user_ids_string) {
|
||||||
return exports.unread_pm_counter.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 () {
|
export function get_msg_ids_for_private() {
|
||||||
return exports.unread_pm_counter.get_msg_ids();
|
return unread_pm_counter.get_msg_ids();
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_msg_ids_for_mentions = function () {
|
export function get_msg_ids_for_mentions() {
|
||||||
const ids = Array.from(exports.unread_mentions_counter);
|
const ids = Array.from(unread_mentions_counter);
|
||||||
|
|
||||||
return util.sorted_ids(ids);
|
return util.sorted_ids(ids);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_all_msg_ids = function () {
|
export function get_all_msg_ids() {
|
||||||
const ids = Array.from(unread_messages);
|
const ids = Array.from(unread_messages);
|
||||||
|
|
||||||
return util.sorted_ids(ids);
|
return util.sorted_ids(ids);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.get_missing_topics = function (opts) {
|
export function get_missing_topics(opts) {
|
||||||
return exports.unread_topic_counter.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
|
// This is here for API consistency sake--we never
|
||||||
// have unread starred messages. (Some day we may ironically
|
// have unread starred messages. (Some day we may ironically
|
||||||
// want to make starring the same as mark-as-unread, but
|
// want to make starring the same as mark-as-unread, but
|
||||||
// for now starring === reading.)
|
// for now starring === reading.)
|
||||||
return [];
|
return [];
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.initialize = function () {
|
export function initialize() {
|
||||||
const unread_msgs = page_params.unread_msgs;
|
const unread_msgs = page_params.unread_msgs;
|
||||||
|
|
||||||
exports.unread_pm_counter.set_huddles(unread_msgs.huddles);
|
unread_pm_counter.set_huddles(unread_msgs.huddles);
|
||||||
exports.unread_pm_counter.set_pms(unread_msgs.pms);
|
unread_pm_counter.set_pms(unread_msgs.pms);
|
||||||
exports.unread_topic_counter.set_streams(unread_msgs.streams);
|
unread_topic_counter.set_streams(unread_msgs.streams);
|
||||||
|
|
||||||
for (const message_id of unread_msgs.mentions) {
|
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) {
|
for (const obj of unread_msgs.huddles) {
|
||||||
|
@ -608,6 +602,4 @@ exports.initialize = function () {
|
||||||
for (const message_id of unread_msgs.mentions) {
|
for (const message_id of unread_msgs.mentions) {
|
||||||
unread_messages.add(message_id);
|
unread_messages.add(message_id);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
window.unread = exports;
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import * as notifications from "./notifications";
|
||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
import * as recent_topics from "./recent_topics";
|
import * as recent_topics from "./recent_topics";
|
||||||
import * as reload from "./reload";
|
import * as reload from "./reload";
|
||||||
|
import * as unread from "./unread";
|
||||||
import * as unread_ui from "./unread_ui";
|
import * as unread_ui from "./unread_ui";
|
||||||
|
|
||||||
export function mark_all_as_read() {
|
export function mark_all_as_read() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import * as notifications from "./notifications";
|
||||||
import * as pm_list from "./pm_list";
|
import * as pm_list from "./pm_list";
|
||||||
import * as top_left_corner from "./top_left_corner";
|
import * as top_left_corner from "./top_left_corner";
|
||||||
import * as topic_list from "./topic_list";
|
import * as topic_list from "./topic_list";
|
||||||
|
import * as unread from "./unread";
|
||||||
|
|
||||||
let last_mention_count = 0;
|
let last_mention_count = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue