Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/message_fetch.js to ES6 module.
Anders Kaseorg21c6a3d87a4d
diff --git a/.eslintrc.json b/.eslintrc.jsonindex b77a6664106..b5874952966 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -152,7 +152,6 @@"localStorage": false,"location": false,"message_events": false,- "message_fetch": false,"message_list": false,"narrow": false,"padded_widget": false,diff --git a/frontend_tests/node_tests/narrow_activate.js b/frontend_tests/node_tests/narrow_activate.jsindex b1a54e7ff45..011627ab536 100644--- a/frontend_tests/node_tests/narrow_activate.js+++ b/frontend_tests/node_tests/narrow_activate.js@@ -20,7 +20,8 @@ set_global("current_msg_list", {});const hashchange = {__esModule: true};rewiremock("../../static/js/hashchange").with(hashchange);set_global("home_msg_list", {});-const message_fetch = set_global("message_fetch", {});+const message_fetch = {__esModule: true};+rewiremock("../../static/js/message_fetch").with(message_fetch);const message_list = set_global("message_list", {set_narrowed(value) {this.narrowed = value;diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.jsindex 8110a691936..0bdbdecda16 100644--- a/frontend_tests/node_tests/ui_init.js+++ b/frontend_tests/node_tests/ui_init.js@@ -76,7 +76,7 @@ rewiremock("../../static/js/gear_menu").with({initialize() {}});rewiremock("../../static/js/hashchange").with({initialize() {}});set_global("hotspots", {initialize() {}});// Accesses home_msg_list, which is a lot of complexity to set up-set_global("message_fetch", {initialize() {}});+rewiremock("../../static/js/message_fetch").with({initialize() {}});rewiremock("../../static/js/message_scroll").with({initialize() {}});const message_viewport = {__esModule: true,diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex b14ef7611d8..8664381cbd0 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -31,7 +31,6 @@ import "../composebox_typeahead";import "../hotkey";import "../notifications";import "../message_events";-import "../message_fetch";import "../server_events";import "../zulip";import "../presence";diff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 9a2c20bc7bc..1979143f85a 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -25,7 +25,6 @@ declare let hotspots: any;declare let i18n: any;declare let input_pill: any;declare let message_events: any;-declare let message_fetch: any;declare let message_list: any;declare let narrow: any;declare let padded_widget: any;diff --git a/static/js/message_fetch.js b/static/js/message_fetch.jsindex 090dc8bf821..37d56bbffd1 100644--- a/static/js/message_fetch.js+++ b/static/js/message_fetch.js@@ -1,15 +1,13 @@-"use strict";--const channel = require("./channel");-const {Filter} = require("./filter");-const huddle_data = require("./huddle_data");-const message_scroll = require("./message_scroll");-const message_store = require("./message_store");-const message_util = require("./message_util");-const people = require("./people");-const pm_list = require("./pm_list");-const stream_data = require("./stream_data");-const ui_report = require("./ui_report");+import * as channel from "./channel";+import {Filter} from "./filter";+import * as huddle_data from "./huddle_data";+import * as message_scroll from "./message_scroll";+import * as message_store from "./message_store";+import * as message_util from "./message_util";+import * as people from "./people";+import * as pm_list from "./pm_list";+import * as stream_data from "./stream_data";+import * as ui_report from "./ui_report";const consts = {backfill_idle_time: 10 * 1000,@@ -128,7 +126,7 @@ function get_messages_success(data, opts) {// The server occasionally returns no data during a// restart. Ignore those responses and try againsetTimeout(() => {- exports.load_messages(opts);+ load_messages(opts);}, 0);return;}@@ -178,7 +176,7 @@ function handle_operators_supporting_id_based_api(data) {return data;}-exports.load_messages = function (opts) {+export function load_messages(opts) {if (typeof opts.anchor === "number") {// Messages that have been locally echoed messages have// floating point temporary IDs, which is intended to be a.@@ -269,25 +267,25 @@ exports.load_messages = function (opts) {// We might want to be more clever here$("#connection-error").addClass("show");setTimeout(() => {- exports.load_messages(opts);+ load_messages(opts);}, consts.error_retry_time);},});-};+}-exports.load_messages_for_narrow = function (opts) {+export function load_messages_for_narrow(opts) {const msg_list = message_list.narrowed;- exports.load_messages({+ load_messages({anchor: opts.anchor,num_before: consts.narrow_before,num_after: consts.narrow_after,msg_list,cont: opts.cont,});-};+}-exports.get_backfill_anchor = function (msg_list) {+export function get_backfill_anchor(msg_list) {if (msg_list === home_msg_list) {msg_list = message_list.all;}@@ -300,9 +298,9 @@ exports.get_backfill_anchor = function (msg_list) {// msg_list is empty, which is an impossible// case, raise a fatal error.throw new Error("There are no message available to backfill.");-};+}-exports.get_frontfill_anchor = function (msg_list) {+export function get_frontfill_anchor(msg_list) {if (msg_list === home_msg_list) {msg_list = message_list.all;}@@ -319,9 +317,9 @@ exports.get_frontfill_anchor = function (msg_list) {// fetch more data, and if user is, then the available data is wrong// and we raise a fatal error.throw new Error("There are no message available to frontfill.");-};+}-exports.maybe_load_older_messages = function (opts) {+export function maybe_load_older_messages(opts) {// This function gets called when you scroll to the top// of your window, and you want to get messages older// than what the browsers originally fetched.@@ -332,17 +330,17 @@ exports.maybe_load_older_messages = function (opts) {return;}- exports.do_backfill({+ do_backfill({msg_list,num_before: consts.backward_batch_size,});-};+}-exports.do_backfill = function (opts) {+export function do_backfill(opts) {const msg_list = opts.msg_list;- const anchor = exports.get_backfill_anchor(msg_list);+ const anchor = get_backfill_anchor(msg_list);- exports.load_messages({+ load_messages({anchor,num_before: opts.num_before,num_after: 0,@@ -353,9 +351,9 @@ exports.do_backfill = function (opts) {}},});-};+}-exports.maybe_load_newer_messages = function (opts) {+export function maybe_load_newer_messages(opts) {// This function gets called when you scroll to the bottom// of your window, and you want to get messages newer// than what the browsers originally fetched.@@ -367,37 +365,37 @@ exports.maybe_load_newer_messages = function (opts) {return;}- const anchor = exports.get_frontfill_anchor(msg_list);+ const anchor = get_frontfill_anchor(msg_list);function load_more(data, args) {if (args.fetch_again && args.msg_list === current_msg_list) {- exports.maybe_load_newer_messages({msg_list: current_msg_list});+ maybe_load_newer_messages({msg_list: current_msg_list});}}- exports.load_messages({+ load_messages({anchor,num_before: 0,num_after: consts.forward_batch_size,msg_list,cont: load_more,});-};+}-exports.start_backfilling_messages = function () {+export function start_backfilling_messages() {// backfill more messages after the user is idle$(document).idle({idle: consts.backfill_idle_time,onIdle() {- exports.do_backfill({+ do_backfill({num_before: consts.backfill_batch_size,msg_list: home_msg_list,});},});-};+}-exports.initialize = function () {+export function initialize() {// get the initial message listfunction load_more(data) {// If we haven't selected a message in the home view yet, and@@ -415,7 +413,7 @@ exports.initialize = function () {if (data.found_newest) {server_events.home_view_loaded();- exports.start_backfilling_messages();+ start_backfilling_messages();return;}@@ -424,7 +422,7 @@ exports.initialize = function () {const messages = data.messages;const latest_id = messages[messages.length - 1].id;- exports.load_messages({+ load_messages({anchor: latest_id,num_before: 0,num_after: consts.catch_up_batch_size,@@ -443,7 +441,7 @@ exports.initialize = function () {// the user's unmuted history as our anchor.anchor = "first_unread";}- exports.load_messages({+ load_messages({anchor,num_before: consts.num_before_home_anchor,num_after: consts.num_after_home_anchor,@@ -476,12 +474,10 @@ exports.initialize = function () {filter: new Filter([{operator: "in", operand: "home"}]),excludes_muted_topics: true,});- exports.load_messages({+ load_messages({anchor: "newest",num_before: consts.recent_topics_initial_fetch_size,num_after: 0,msg_list: recent_topics_message_list,});-};--window.message_fetch = exports;+}diff --git a/static/js/message_scroll.js b/static/js/message_scroll.jsindex 32ffe0a4f95..3fb30fa6843 100644--- a/static/js/message_scroll.js+++ b/static/js/message_scroll.js@@ -3,6 +3,7 @@ import _ from "lodash";import * as floating_recipient_bar from "./floating_recipient_bar";import * as hash_util from "./hash_util";import * as loading from "./loading";+import * as message_fetch from "./message_fetch";import * as message_viewport from "./message_viewport";import * as narrow_state from "./narrow_state";diff --git a/static/js/narrow.js b/static/js/narrow.jsindex 6afaa14e89a..3ffb8dc3981 100644--- a/static/js/narrow.js+++ b/static/js/narrow.js@@ -8,6 +8,7 @@ const condense = require("./condense");const {Filter} = require("./filter");const hashchange = require("./hashchange");const message_edit = require("./message_edit");+const message_fetch = require("./message_fetch");const {MessageListData} = require("./message_list_data");const message_scroll = require("./message_scroll");const message_store = require("./message_store");diff --git a/static/js/ui_init.js b/static/js/ui_init.jsindex 55b56a311d1..5fa7c8e5010 100644--- a/static/js/ui_init.js+++ b/static/js/ui_init.js@@ -24,6 +24,7 @@ const lightbox = require("./lightbox");const markdown = require("./markdown");const markdown_config = require("./markdown_config");const message_edit = require("./message_edit");+const message_fetch = require("./message_fetch");const message_scroll = require("./message_scroll");const message_viewport = require("./message_viewport");const muting = require("./muting");