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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-28 12:30:08 -08:00 committed by Tim Abbott
parent 7ec3fc38fa
commit 9997e13032
20 changed files with 47 additions and 40 deletions

View File

@ -153,7 +153,6 @@
"ui": false,
"ui_init": false,
"unread": false,
"unread_ops": false,
"widgetize": false,
"zxcvbn": false
}

View File

@ -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,
});

View File

@ -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};

View File

@ -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", {});

View File

@ -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: () => {},

View File

@ -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) => {

View File

@ -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";

View File

@ -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";

View File

@ -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");

View File

@ -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;

View File

@ -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");

View File

@ -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({

View File

@ -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;

View File

@ -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;

View File

@ -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});

View File

@ -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();

View File

@ -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";

View File

@ -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";

View File

@ -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.

View File

@ -1,16 +1,14 @@
"use strict";
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";
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 () {
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;
}