diff --git a/web/src/sent_messages.js b/web/src/sent_messages.js index be4f714fec..6bd08b654a 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.js index eb628e6774..29658fccfe 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.js index bd30b2d9e7..9c951fe38d 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, });