diff --git a/web/src/reload.js b/web/src/reload.js index e73c4df4a4..f809ed7ba2 100644 --- a/web/src/reload.js +++ b/web/src/reload.js @@ -14,11 +14,23 @@ import * as message_lists from "./message_lists"; import * as narrow_state from "./narrow_state"; import {page_params} from "./page_params"; import * as reload_state from "./reload_state"; -import * as server_events from "./server_events"; import * as ui_report from "./ui_report"; import * as util from "./util"; // Read https://zulip.readthedocs.io/en/latest/subsystems/hashchange-system.html + +const reload_hooks = []; + +export function add_reload_hook(hook) { + reload_hooks.push(hook); +} + +function call_reload_hooks() { + for (const hook of reload_hooks) { + hook(); + } +} + function preserve_state(send_after_reload, save_pointer, save_narrow, save_compose) { if (!localstorage.supported()) { // If local storage is not supported by the browser, we can't @@ -255,7 +267,7 @@ function do_reload_app(send_after_reload, save_pointer, save_narrow, save_compos util.call_function_periodically(retry_reload, 30000); try { - server_events.cleanup_event_queue(); + call_reload_hooks(); } catch (error) { blueslip.error("Failed to clean up before reloading", undefined, error); } diff --git a/web/src/server_events.js b/web/src/server_events.js index 93b569ee3a..81d7f63e15 100644 --- a/web/src/server_events.js +++ b/web/src/server_events.js @@ -269,6 +269,7 @@ export function home_view_loaded() { } export function initialize() { + reload.add_reload_hook(cleanup_event_queue); watchdog.on_unsuspend(() => { // Immediately poll for new events on unsuspend blueslip.log("Restarting get_events due to unsuspend"); @@ -278,7 +279,7 @@ export function initialize() { get_events(); } -export function cleanup_event_queue() { +function cleanup_event_queue() { // Submit a request to the server to clean up our event queue if (page_params.event_queue_expired === true || page_params.no_event_queue === true) { return;