mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
js: Convert static/js/server_events.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
21c6a3d87a
commit
19bb5fa7ad
@@ -166,7 +166,6 @@
|
|||||||
"recent_topics": false,
|
"recent_topics": false,
|
||||||
"reminder": false,
|
"reminder": false,
|
||||||
"search_pill_widget": false,
|
"search_pill_widget": false,
|
||||||
"server_events": false,
|
|
||||||
"settings": false,
|
"settings": false,
|
||||||
"settings_account": false,
|
"settings_account": false,
|
||||||
"settings_bots": false,
|
"settings_bots": false,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ rewiremock("../../static/js/resize").with(_resize);
|
|||||||
rewiremock("../../static/js/scroll_util").with(_scroll_util);
|
rewiremock("../../static/js/scroll_util").with(_scroll_util);
|
||||||
rewiremock("../../static/js/stream_popover").with(_stream_popover);
|
rewiremock("../../static/js/stream_popover").with(_stream_popover);
|
||||||
set_global("ui", _ui);
|
set_global("ui", _ui);
|
||||||
set_global("server_events", {
|
rewiremock("../../static/js/server_events").with({
|
||||||
check_for_unsuspend() {},
|
check_for_unsuspend() {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -735,7 +735,7 @@ test_ui("send_message", () => {
|
|||||||
set_global("setTimeout", (func) => {
|
set_global("setTimeout", (func) => {
|
||||||
func();
|
func();
|
||||||
});
|
});
|
||||||
set_global("server_events", {
|
rewiremock("../../static/js/server_events").with({
|
||||||
assert_get_events_running() {
|
assert_get_events_running() {
|
||||||
stub_state.get_events_running_called += 1;
|
stub_state.get_events_running_called += 1;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ const narrow_state = {__esModule: true};
|
|||||||
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
rewiremock("../../static/js/narrow_state").with(narrow_state);
|
||||||
const pm_list = {__esModule: true};
|
const pm_list = {__esModule: true};
|
||||||
rewiremock("../../static/js/pm_list").with(pm_list);
|
rewiremock("../../static/js/pm_list").with(pm_list);
|
||||||
const server_events = set_global("server_events", {});
|
const server_events = {__esModule: true};
|
||||||
|
rewiremock("../../static/js/server_events").with(server_events);
|
||||||
const stream_list = set_global("stream_list", {
|
const stream_list = set_global("stream_list", {
|
||||||
maybe_scroll_narrow_into_view: () => {},
|
maybe_scroll_narrow_into_view: () => {},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ const {strict: assert} = require("assert");
|
|||||||
|
|
||||||
const rewiremock = require("rewiremock/node");
|
const rewiremock = require("rewiremock/node");
|
||||||
|
|
||||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
const {zrequire} = require("../zjsunit/namespace");
|
||||||
const {run_test} = require("../zjsunit/test");
|
const {run_test} = require("../zjsunit/test");
|
||||||
|
|
||||||
const server_events = set_global("server_events", {});
|
const server_events = {__esModule: true};
|
||||||
|
rewiremock("../../static/js/server_events").with(server_events);
|
||||||
const reload_state = {
|
const reload_state = {
|
||||||
__esModule: true,
|
__esModule: true,
|
||||||
is_in_progress: () => false,
|
is_in_progress: () => false,
|
||||||
|
|||||||
@@ -87,7 +87,11 @@ set_global("panels", {initialize() {}});
|
|||||||
rewiremock("../../static/js/popovers").with({initialize() {}});
|
rewiremock("../../static/js/popovers").with({initialize() {}});
|
||||||
rewiremock("../../static/js/reload").with({initialize() {}});
|
rewiremock("../../static/js/reload").with({initialize() {}});
|
||||||
rewiremock("../../static/js/scroll_bar").with({initialize() {}});
|
rewiremock("../../static/js/scroll_bar").with({initialize() {}});
|
||||||
const server_events = set_global("server_events", {initialize() {}});
|
const server_events = {
|
||||||
|
__esModule: true,
|
||||||
|
initialize() {},
|
||||||
|
};
|
||||||
|
rewiremock("../../static/js/server_events").with(server_events);
|
||||||
set_global("settings_sections", {initialize() {}});
|
set_global("settings_sections", {initialize() {}});
|
||||||
rewiremock("../../static/js/settings_panel_menu").with({initialize() {}});
|
rewiremock("../../static/js/settings_panel_menu").with({initialize() {}});
|
||||||
rewiremock("../../static/js/settings_toggle").with({initialize() {}});
|
rewiremock("../../static/js/settings_toggle").with({initialize() {}});
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const {ListCursor} = require("./list_cursor");
|
|||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const pm_list = require("./pm_list");
|
const pm_list = require("./pm_list");
|
||||||
const popovers = require("./popovers");
|
const popovers = require("./popovers");
|
||||||
|
const server_events = require("./server_events");
|
||||||
const {UserSearch} = require("./user_search");
|
const {UserSearch} = require("./user_search");
|
||||||
const user_status = require("./user_status");
|
const user_status = require("./user_status");
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import * as notifications from "./notifications";
|
|||||||
import * as overlays from "./overlays";
|
import * as overlays from "./overlays";
|
||||||
import * as popovers from "./popovers";
|
import * as popovers from "./popovers";
|
||||||
import * as rows from "./rows";
|
import * as rows from "./rows";
|
||||||
|
import * as server_events from "./server_events";
|
||||||
import * as settings_panel_menu from "./settings_panel_menu";
|
import * as settings_panel_menu from "./settings_panel_menu";
|
||||||
import * as settings_toggle from "./settings_toggle";
|
import * as settings_toggle from "./settings_toggle";
|
||||||
import * as stream_edit from "./stream_edit";
|
import * as stream_edit from "./stream_edit";
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import * as rendered_markdown from "./rendered_markdown";
|
|||||||
import * as resize from "./resize";
|
import * as resize from "./resize";
|
||||||
import * as rtl from "./rtl";
|
import * as rtl from "./rtl";
|
||||||
import * as sent_messages from "./sent_messages";
|
import * as sent_messages from "./sent_messages";
|
||||||
|
import * as server_events from "./server_events";
|
||||||
import * as settings_config from "./settings_config";
|
import * as settings_config from "./settings_config";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as stream_edit from "./stream_edit";
|
import * as stream_edit from "./stream_edit";
|
||||||
|
|||||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -38,7 +38,6 @@ declare let realm_logo: any;
|
|||||||
declare let recent_topics: any;
|
declare let recent_topics: any;
|
||||||
declare let reminder: any;
|
declare let reminder: any;
|
||||||
declare let search_pill_widget: any;
|
declare let search_pill_widget: any;
|
||||||
declare let server_events: any;
|
|
||||||
declare let settings: any;
|
declare let settings: any;
|
||||||
declare let settings_account: any;
|
declare let settings_account: any;
|
||||||
declare let settings_bots: any;
|
declare let settings_bots: any;
|
||||||
|
|||||||
@@ -6,6 +6,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 pm_list from "./pm_list";
|
import * as pm_list from "./pm_list";
|
||||||
|
import * as server_events from "./server_events";
|
||||||
import * as stream_data from "./stream_data";
|
import * as stream_data from "./stream_data";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
const people = require("./people");
|
const people = require("./people");
|
||||||
const reload_state = require("./reload_state");
|
const reload_state = require("./reload_state");
|
||||||
|
const server_events = require("./server_events");
|
||||||
|
|
||||||
// This module just manages data. See activity.js for
|
// This module just manages data. See activity.js for
|
||||||
// the UI of our buddy list.
|
// the UI of our buddy list.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import * as hashchange from "./hashchange";
|
|||||||
import {localstorage} from "./localstorage";
|
import {localstorage} from "./localstorage";
|
||||||
import * as narrow_state from "./narrow_state";
|
import * as narrow_state from "./narrow_state";
|
||||||
import * as reload_state from "./reload_state";
|
import * as reload_state from "./reload_state";
|
||||||
|
import * as server_events from "./server_events";
|
||||||
import * as ui_report from "./ui_report";
|
import * as ui_report from "./ui_report";
|
||||||
import * as util from "./util";
|
import * as util from "./util";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import * as channel from "./channel";
|
import * as channel from "./channel";
|
||||||
|
import * as server_events from "./server_events";
|
||||||
|
|
||||||
export let next_local_id;
|
export let next_local_id;
|
||||||
export const messages = new Map();
|
export const messages = new Map();
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
"use strict";
|
import _ from "lodash";
|
||||||
|
|
||||||
const _ = require("lodash");
|
import * as channel from "./channel";
|
||||||
|
import * as echo from "./echo";
|
||||||
|
import * as message_store from "./message_store";
|
||||||
|
import * as reload from "./reload";
|
||||||
|
import * as reload_state from "./reload_state";
|
||||||
|
import * as sent_messages from "./sent_messages";
|
||||||
|
import * as server_events_dispatch from "./server_events_dispatch";
|
||||||
|
import * as ui_report from "./ui_report";
|
||||||
|
|
||||||
const channel = require("./channel");
|
|
||||||
const echo = require("./echo");
|
|
||||||
const message_store = require("./message_store");
|
|
||||||
const reload = require("./reload");
|
|
||||||
const reload_state = require("./reload_state");
|
|
||||||
const sent_messages = require("./sent_messages");
|
|
||||||
const server_events_dispatch = require("./server_events_dispatch");
|
|
||||||
const ui_report = require("./ui_report");
|
|
||||||
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
|
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/events-system.html
|
||||||
|
|
||||||
let waiting_on_homeview_load = true;
|
let waiting_on_homeview_load = true;
|
||||||
@@ -25,7 +24,7 @@ const get_events_params = {};
|
|||||||
// force-reconnect to the events server due to suspecting we are
|
// force-reconnect to the events server due to suspecting we are
|
||||||
// offline. It is important for avoiding races with the presence
|
// offline. It is important for avoiding races with the presence
|
||||||
// system when coming back from unsuspend.
|
// system when coming back from unsuspend.
|
||||||
exports.suspect_offline = false;
|
export let suspect_offline = false;
|
||||||
|
|
||||||
function get_events_success(events) {
|
function get_events_success(events) {
|
||||||
let messages = [];
|
let messages = [];
|
||||||
@@ -192,7 +191,7 @@ function get_events(options) {
|
|||||||
// that means it's fairly likely that this client has been off
|
// that means it's fairly likely that this client has been off
|
||||||
// the Internet and thus may have stale state (which is
|
// the Internet and thus may have stale state (which is
|
||||||
// important for potential presence issues).
|
// important for potential presence issues).
|
||||||
exports.suspect_offline = true;
|
suspect_offline = true;
|
||||||
}
|
}
|
||||||
if (get_events_params.queue_id === undefined) {
|
if (get_events_params.queue_id === undefined) {
|
||||||
get_events_params.queue_id = page_params.queue_id;
|
get_events_params.queue_id = page_params.queue_id;
|
||||||
@@ -216,7 +215,7 @@ function get_events(options) {
|
|||||||
idempotent: true,
|
idempotent: true,
|
||||||
timeout: page_params.poll_timeout,
|
timeout: page_params.poll_timeout,
|
||||||
success(data) {
|
success(data) {
|
||||||
exports.suspect_offline = false;
|
suspect_offline = false;
|
||||||
try {
|
try {
|
||||||
get_events_xhr = undefined;
|
get_events_xhr = undefined;
|
||||||
get_events_failures = 0;
|
get_events_failures = 0;
|
||||||
@@ -279,29 +278,30 @@ function get_events(options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.assert_get_events_running = function assert_get_events_running(error_message) {
|
export function assert_get_events_running(error_message) {
|
||||||
if (get_events_xhr === undefined && get_events_timeout === undefined) {
|
if (get_events_xhr === undefined && get_events_timeout === undefined) {
|
||||||
exports.restart_get_events({dont_block: true});
|
restart_get_events({dont_block: true});
|
||||||
blueslip.error(error_message);
|
blueslip.error(error_message);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.restart_get_events = function restart_get_events(options) {
|
export function restart_get_events(options) {
|
||||||
get_events(options);
|
get_events(options);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.force_get_events = function force_get_events() {
|
export function force_get_events() {
|
||||||
get_events_timeout = setTimeout(get_events, 0);
|
get_events_timeout = setTimeout(get_events, 0);
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.home_view_loaded = function home_view_loaded() {
|
export function home_view_loaded() {
|
||||||
waiting_on_homeview_load = false;
|
waiting_on_homeview_load = false;
|
||||||
get_events_success([]);
|
get_events_success([]);
|
||||||
$(document).trigger("home_view_loaded.zulip");
|
$(document).trigger("home_view_loaded.zulip");
|
||||||
};
|
}
|
||||||
|
|
||||||
let watchdog_time = $.now();
|
let watchdog_time = $.now();
|
||||||
exports.check_for_unsuspend = function () {
|
|
||||||
|
export function check_for_unsuspend() {
|
||||||
const new_time = $.now();
|
const new_time = $.now();
|
||||||
if (new_time - watchdog_time > 20000) {
|
if (new_time - watchdog_time > 20000) {
|
||||||
// 20 seconds.
|
// 20 seconds.
|
||||||
@@ -313,20 +313,21 @@ exports.check_for_unsuspend = function () {
|
|||||||
$(document).trigger("unsuspend");
|
$(document).trigger("unsuspend");
|
||||||
}
|
}
|
||||||
watchdog_time = new_time;
|
watchdog_time = new_time;
|
||||||
};
|
}
|
||||||
setInterval(exports.check_for_unsuspend, 5000);
|
|
||||||
|
|
||||||
exports.initialize = function () {
|
setInterval(check_for_unsuspend, 5000);
|
||||||
|
|
||||||
|
export function initialize() {
|
||||||
$(document).on("unsuspend", () => {
|
$(document).on("unsuspend", () => {
|
||||||
// Immediately poll for new events on unsuspend
|
// Immediately poll for new events on unsuspend
|
||||||
blueslip.log("Restarting get_events due to unsuspend");
|
blueslip.log("Restarting get_events due to unsuspend");
|
||||||
get_events_failures = 0;
|
get_events_failures = 0;
|
||||||
exports.restart_get_events({dont_block: true});
|
restart_get_events({dont_block: true});
|
||||||
});
|
});
|
||||||
get_events();
|
get_events();
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.cleanup_event_queue = function cleanup_event_queue() {
|
export function cleanup_event_queue() {
|
||||||
// Submit a request to the server to cleanup our event queue
|
// Submit a request to the server to cleanup our event queue
|
||||||
if (page_params.event_queue_expired === true || page_params.no_event_queue === true) {
|
if (page_params.event_queue_expired === true || page_params.no_event_queue === true) {
|
||||||
return;
|
return;
|
||||||
@@ -339,13 +340,11 @@ exports.cleanup_event_queue = function cleanup_event_queue() {
|
|||||||
data: {queue_id: page_params.queue_id},
|
data: {queue_id: page_params.queue_id},
|
||||||
ignore_reload: true,
|
ignore_reload: true,
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
exports.cleanup_event_queue();
|
cleanup_event_queue();
|
||||||
});
|
});
|
||||||
|
|
||||||
// For unit testing
|
// For unit testing
|
||||||
exports._get_events_success = get_events_success;
|
export const _get_events_success = get_events_success;
|
||||||
|
|
||||||
window.server_events = exports;
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const rows = require("./rows");
|
|||||||
const scroll_bar = require("./scroll_bar");
|
const scroll_bar = require("./scroll_bar");
|
||||||
const search = require("./search");
|
const search = require("./search");
|
||||||
const sent_messages = require("./sent_messages");
|
const sent_messages = require("./sent_messages");
|
||||||
|
const server_events = require("./server_events");
|
||||||
const settings_panel_menu = require("./settings_panel_menu");
|
const settings_panel_menu = require("./settings_panel_menu");
|
||||||
const settings_toggle = require("./settings_toggle");
|
const settings_toggle = require("./settings_toggle");
|
||||||
const spoilers = require("./spoilers");
|
const spoilers = require("./spoilers");
|
||||||
|
|||||||
Reference in New Issue
Block a user