Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
sent_messages: Lift event loop restarting to transmit.
Anders Kaseorg0c991d813fa1
diff --git a/web/src/sent_messages.js b/web/src/sent_messages.jsindex be4f714fece..6bd08b654af 100644--- a/web/src/sent_messages.js+++ b/web/src/sent_messages.js@@ -1,7 +1,6 @@import * as Sentry from "@sentry/browser";import * as blueslip from "./blueslip";-import * as server_events from "./server_events";export let next_local_id;export const messages = new Map();@@ -49,30 +48,9 @@ export class MessageState {this.rendered_changed = true;}- maybe_restart_event_loop() {- if (this.saw_event) {- // We got our event, no need to do anything- return;- }-- blueslip.log(- `Restarting get_events due to delayed receipt of sent message ${this.local_id}`,- );-- server_events.restart_get_events();- }-report_server_ack() {this.server_acked = true;this.maybe_finish_txn();- // We only start our timer for events coming in here,- // since it's plausible the server rejected our message,- // or took a while to process it, but there is nothing- // wrong with our event loop.-- if (!this.saw_event) {- setTimeout(() => this.maybe_restart_event_loop(), 5000);- }}report_event_received() {@@ -137,15 +115,6 @@ export function start_send(local_id) {return state.start_send();}-export function report_server_ack(local_id) {- const state = get_message_state(local_id);- if (!state) {- return;- }-- state.report_server_ack();-}-export function mark_disparity(local_id) {const state = get_message_state(local_id);if (!state) {diff --git a/web/src/transmit.js b/web/src/transmit.jsindex eb628e67743..29658fccfef 100644--- a/web/src/transmit.js+++ b/web/src/transmit.js@@ -7,6 +7,7 @@ import * as people from "./people";import * as reload from "./reload";import * as reload_state from "./reload_state";import * as sent_messages from "./sent_messages";+import * as server_events from "./server_events";import * as stream_data from "./stream_data";export function send_message(request, on_success, error) {@@ -28,7 +29,32 @@ export function send_message(request, on_success, error) {// box and turning off spinners and reifying locally echoed messages.on_success(data);// Once everything is done, get ready to report times to the server.- sent_messages.report_server_ack(request.local_id);+ const state = sent_messages.get_message_state(request.local_id);+ /* istanbul ignore if */+ if (!state) {+ return;+ }+ state.report_server_ack();++ // We only start our timer for events coming in here,+ // since it's plausible the server rejected our message,+ // or took a while to process it, but there is nothing+ // wrong with our event loop.+ /* istanbul ignore if */+ if (!state.saw_event) {+ setTimeout(() => {+ if (state.saw_event) {+ // We got our event, no need to do anything+ return;+ }++ blueslip.log(+ `Restarting get_events due to delayed receipt of sent message ${request.local_id}`,+ );++ server_events.restart_get_events();+ }, 5000);+ }},error(xhr, error_type) {if (error_type !== "timeout" && reload_state.is_pending()) {diff --git a/web/tests/transmit.test.js b/web/tests/transmit.test.jsindex bd30b2d9e7f..9c951fe38d1 100644--- a/web/tests/transmit.test.js+++ b/web/tests/transmit.test.js@@ -14,7 +14,10 @@ const reload = mock_esm("../src/reload");const reload_state = mock_esm("../src/reload_state");const sent_messages = mock_esm("../src/sent_messages", {start_tracking_message: noop,- report_server_ack: noop,+ get_message_state: () => ({+ report_server_ack: noop,+ saw_event: true,+ }),start_send: noop,});