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/message_scroll.js to ES6 module.

Anders Kaseorg5b2b2924be5c
diff --git a/.eslintrc.json b/.eslintrc.json
index a96b58255f1..73adaae386b 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -163,7 +163,6 @@
"message_fetch": false,
"message_flags": false,
"message_list": false,
- "message_scroll": false,
"message_store": false,
"message_util": false,
"narrow": false,
diff --git a/frontend_tests/node_tests/fetch_status.js b/frontend_tests/node_tests/fetch_status.js
index fc7eaf2765c..4384809ee6d 100644
--- a/frontend_tests/node_tests/fetch_status.js
+++ b/frontend_tests/node_tests/fetch_status.js
@@ -2,16 +2,20 @@
const {strict: assert} = require("assert");
-const {set_global, zrequire} = require("../zjsunit/namespace");
+const rewiremock = require("rewiremock/node");
+
+const {zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-set_global("message_scroll", {
+rewiremock("../../static/js/message_scroll").with({
hide_loading_older: () => {},
show_loading_older: () => {},
hide_loading_newer: () => {},
show_loading_newer: () => {},
});
+rewiremock.enable();
+
const {FetchStatus} = zrequire("fetch_status");
let fetch_status = new FetchStatus();
@@ -176,3 +180,4 @@ run_test("basics", () => {
can_load_older();
blocked_newer();
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/message_fetch.js b/frontend_tests/node_tests/message_fetch.js
index 193c0271c55..636fd6bdc71 100644
--- a/frontend_tests/node_tests/message_fetch.js
+++ b/frontend_tests/node_tests/message_fetch.js
@@ -32,7 +32,7 @@ rewiremock("../../static/js/ui_report").with({
const channel = {__esModule: true};
rewiremock("../../static/js/channel").with(channel);
set_global("document", "document-stub");
-set_global("message_scroll", {
+rewiremock("../../static/js/message_scroll").with({
show_loading_older: noop,
hide_loading_older: noop,
show_loading_newer: noop,
diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.js
index 233209a8ef3..77b5e845eb6 100644
--- a/frontend_tests/node_tests/narrow_activate.js
+++ b/frontend_tests/node_tests/narrow_activate.js
@@ -25,7 +25,8 @@ const message_list = set_global("message_list", {
this.narrowed = value;
},
});
-const message_scroll = set_global("message_scroll", {});
+const message_scroll = {__esModule: true};
+rewiremock("../../static/js/message_scroll").with(message_scroll);
set_global("message_util", {});
const notifications = set_global("notifications", {});
set_global("page_params", {});
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index 2cfd1de1d6d..ad3cf1651c9 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -77,7 +77,7 @@ set_global("hashchange", {initialize() {}});
set_global("hotspots", {initialize() {}});
// Accesses home_msg_list, which is a lot of complexity to set up
set_global("message_fetch", {initialize() {}});
-set_global("message_scroll", {initialize() {}});
+rewiremock("../../static/js/message_scroll").with({initialize() {}});
const message_viewport = {
__esModule: true,
initialize() {},
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 09e14d8fb0c..150b6c9814f 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -26,7 +26,6 @@ import "../narrow";
import "../reload";
import "../compose_actions";
import "../subs";
-import "../message_scroll";
import "../info_overlay";
import "../ui";
import "../night_mode";
diff --git a/static/js/fetch_status.js b/static/js/fetch_status.js
index 702fda48760..003605ac3e2 100644
--- a/static/js/fetch_status.js
+++ b/static/js/fetch_status.js
@@ -1,3 +1,5 @@
+import * as message_scroll from "./message_scroll";
+
function max_id_for_messages(messages) {
let max_id = 0;
for (const msg of messages) {
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index 5d3d98174ef..df8fc50a63f 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -37,7 +37,6 @@ declare let message_events: any;
declare let message_fetch: any;
declare let message_flags: any;
declare let message_list: any;
-declare let message_scroll: any;
declare let message_store: any;
declare let message_util: any;
declare let narrow: any;
diff --git a/static/js/message_fetch.js b/static/js/message_fetch.js
index c93d4764e83..a176901c32d 100644
--- a/static/js/message_fetch.js
+++ b/static/js/message_fetch.js
@@ -3,6 +3,7 @@
const channel = require("./channel");
const {Filter} = require("./filter");
const huddle_data = require("./huddle_data");
+const message_scroll = require("./message_scroll");
const people = require("./people");
const pm_list = require("./pm_list");
const stream_data = require("./stream_data");
diff --git a/static/js/message_scroll.js b/static/js/message_scroll.js
index 741348c493c..d2a2c4aa8ca 100644
--- a/static/js/message_scroll.js
+++ b/static/js/message_scroll.js
@@ -1,11 +1,9 @@
-"use strict";
+import _ from "lodash";
-const _ = require("lodash");
-
-const floating_recipient_bar = require("./floating_recipient_bar");
-const loading = require("./loading");
-const message_viewport = require("./message_viewport");
-const narrow_state = require("./narrow_state");
+import * as floating_recipient_bar from "./floating_recipient_bar";
+import * as loading from "./loading";
+import * as message_viewport from "./message_viewport";
+import * as narrow_state from "./narrow_state";
let actively_scrolling = false;
@@ -13,65 +11,67 @@ let actively_scrolling = false;
// code, not the user, and thus should avoid moving the selected
// message.
let update_selection_on_next_scroll = true;
-exports.suppress_selection_update_on_next_scroll = function () {
+
+export function suppress_selection_update_on_next_scroll() {
update_selection_on_next_scroll = false;
-};
+}
let loading_older_messages_indicator_showing = false;
let loading_newer_messages_indicator_showing = false;
-exports.show_loading_older = function () {
+
+export function show_loading_older() {
if (!loading_older_messages_indicator_showing) {
loading.make_indicator($("#loading_older_messages_indicator"), {abs_positioned: true});
loading_older_messages_indicator_showing = true;
floating_recipient_bar.hide();
}
-};
+}
-exports.hide_loading_older = function () {
+export function hide_loading_older() {
if (loading_older_messages_indicator_showing) {
loading.destroy_indicator($("#loading_older_messages_indicator"));
loading_older_messages_indicator_showing = false;
}
-};
+}
-exports.show_loading_newer = function () {
+export function show_loading_newer() {
if (!loading_newer_messages_indicator_showing) {
$(".bottom-messages-logo").show();
loading.make_indicator($("#loading_newer_messages_indicator"), {abs_positioned: true});
loading_newer_messages_indicator_showing = true;
floating_recipient_bar.hide();
}
-};
+}
-exports.hide_loading_newer = function () {
+export function hide_loading_newer() {
if (loading_newer_messages_indicator_showing) {
$(".bottom-messages-logo").hide();
loading.destroy_indicator($("#loading_newer_messages_indicator"));
loading_newer_messages_indicator_showing = false;
}
-};
+}
-exports.hide_indicators = function () {
- exports.hide_loading_older();
- exports.hide_loading_newer();
-};
+export function hide_indicators() {
+ hide_loading_older();
+ hide_loading_newer();
+}
-exports.show_history_limit_notice = function () {
+export function show_history_limit_notice() {
$(".top-messages-logo").hide();
$(".history-limited-box").show();
narrow.hide_empty_narrow_message();
-};
+}
-exports.hide_history_limit_notice = function () {
+export function hide_history_limit_notice() {
$(".top-messages-logo").show();
$(".history-limited-box").hide();
-};
+}
-exports.hide_end_of_results_notice = function () {
+export function hide_end_of_results_notice() {
$(".all-messages-search-caution").hide();
-};
+}
-exports.show_end_of_results_notice = function () {
+export function show_end_of_results_notice() {
$(".all-messages-search-caution").show();
// Set the link to point to this search with streams:public added.
// It's a bit hacky to use the href, but
@@ -79,9 +79,9 @@ exports.show_end_of_results_notice = function () {
// wasn't already present.
const update_hash = hash_util.search_public_streams_notice_url();
$(".all-messages-search-caution a.search-shared-history").attr("href", update_hash);
-};
+}
-exports.update_top_of_narrow_notices = function (msg_list) {
+export function update_top_of_narrow_notices(msg_list) {
// Assumes that the current state is all notices hidden (i.e. this
// will not hide a notice that should not be there)
if (msg_list !== current_msg_list) {
@@ -105,25 +105,25 @@ exports.update_top_of_narrow_notices = function (msg_list) {
!filter.includes_full_stream_history() &&
!filter.is_personal_filter()
) {
- exports.show_end_of_results_notice();
+ show_end_of_results_notice();
}
}
if (msg_list.data.fetch_status.history_limited()) {
- exports.show_history_limit_notice();
+ show_history_limit_notice();
}
-};
+}
-exports.hide_top_of_narrow_notices = function () {
- exports.hide_end_of_results_notice();
- exports.hide_history_limit_notice();
-};
+export function hide_top_of_narrow_notices() {
+ hide_end_of_results_notice();
+ hide_history_limit_notice();
+}
-exports.is_actively_scrolling = function () {
+export function is_actively_scrolling() {
return actively_scrolling;
-};
+}
-exports.scroll_finished = function () {
+export function scroll_finished() {
actively_scrolling = false;
if (!$("#message_feed_container").hasClass("active")) {
@@ -155,16 +155,16 @@ exports.scroll_finished = function () {
// unread_ops.process_visible will update necessary
// data structures and DOM elements.
setTimeout(unread_ops.process_visible, 0);
-};
+}
let scroll_timer;
function scroll_finish() {
actively_scrolling = true;
clearTimeout(scroll_timer);
- scroll_timer = setTimeout(exports.scroll_finished, 100);
+ scroll_timer = setTimeout(scroll_finished, 100);
}
-exports.initialize = function () {
+export function initialize() {
message_viewport.message_pane.on(
"scroll",
_.throttle(() => {
@@ -192,6 +192,4 @@ exports.initialize = function () {
}
}
});
-};
-
-window.message_scroll = exports;
+}
diff --git a/static/js/message_viewport.js b/static/js/message_viewport.js
index 635248c9ef4..57f508ffb6a 100644
--- a/static/js/message_viewport.js
+++ b/static/js/message_viewport.js
@@ -1,4 +1,5 @@
import {media_breakpoints} from "./css_variables";
+import * as message_scroll from "./message_scroll";
import * as rows from "./rows";
import * as util from "./util";
diff --git a/static/js/narrow.js b/static/js/narrow.js
index fe097bacc3b..6768c0a7f28 100644
--- a/static/js/narrow.js
+++ b/static/js/narrow.js
@@ -8,6 +8,7 @@ const condense = require("./condense");
const {Filter} = require("./filter");
const message_edit = require("./message_edit");
const {MessageListData} = require("./message_list_data");
+const message_scroll = require("./message_scroll");
const narrow_state = require("./narrow_state");
const people = require("./people");
const resize = require("./resize");
diff --git a/static/js/stream_muting.js b/static/js/stream_muting.js
index 97b58c1e324..8cb9800aba9 100644
--- a/static/js/stream_muting.js
+++ b/static/js/stream_muting.js
@@ -1,3 +1,4 @@
+import * as message_scroll from "./message_scroll";
import * as message_viewport from "./message_viewport";
export function update_is_muted(sub, value) {
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index 2fe4822d262..999793ddacc 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -21,6 +21,7 @@ const lightbox = require("./lightbox");
const markdown = require("./markdown");
const markdown_config = require("./markdown_config");
const message_edit = require("./message_edit");
+const message_scroll = require("./message_scroll");
const message_viewport = require("./message_viewport");
const muting = require("./muting");
const people = require("./people");