mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 05:58:25 +00:00
Encapsulate message_state.maybe_restart_event_loop().
We now set the timer for missing events inside the message_state class, where it's easier for us to know which state we're in.
This commit is contained in:
@@ -239,9 +239,6 @@ exports.transmit_message = function (request, on_success, error) {
|
|||||||
|
|
||||||
// Once everything is done, get ready to report times to the server.
|
// Once everything is done, get ready to report times to the server.
|
||||||
message_state.process_success();
|
message_state.process_success();
|
||||||
|
|
||||||
// TODO: rework the timers
|
|
||||||
sent_messages.set_timer_for_restarting_event_loop(client_message_id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (page_params.use_websockets) {
|
if (page_params.use_websockets) {
|
||||||
|
|||||||
@@ -71,6 +71,19 @@ exports.message_state = function (opts) {
|
|||||||
self.data.send_finished = undefined;
|
self.data.send_finished = undefined;
|
||||||
self.data.rendered_content_disparity = false;
|
self.data.rendered_content_disparity = false;
|
||||||
|
|
||||||
|
self.maybe_restart_event_loop = function () {
|
||||||
|
if (self.data.received) {
|
||||||
|
// We got our event, no need to do anything
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
blueslip.log("Restarting get_events due to " +
|
||||||
|
"delayed receipt of sent message " +
|
||||||
|
self.data.client_message_id);
|
||||||
|
|
||||||
|
server_events.restart_get_events();
|
||||||
|
};
|
||||||
|
|
||||||
self.maybe_report_send_times = function () {
|
self.maybe_report_send_times = function () {
|
||||||
if (!self.ready()) {
|
if (!self.ready()) {
|
||||||
return;
|
return;
|
||||||
@@ -100,6 +113,15 @@ exports.message_state = function (opts) {
|
|||||||
self.process_success = function () {
|
self.process_success = function () {
|
||||||
var send_finished = new Date();
|
var send_finished = new Date();
|
||||||
|
|
||||||
|
// 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 (!self.data.received) {
|
||||||
|
setTimeout(self.maybe_restart_event_loop, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
var send_time = (send_finished - self.data.start);
|
var send_time = (send_finished - self.data.start);
|
||||||
if (feature_flags.log_send_times) {
|
if (feature_flags.log_send_times) {
|
||||||
blueslip.log("send time: " + send_time);
|
blueslip.log("send time: " + send_time);
|
||||||
@@ -169,15 +191,6 @@ exports.report_as_received = function report_as_received(client_message_id) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.set_timer_for_restarting_event_loop = function (client_message_id) {
|
|
||||||
setTimeout(function () {
|
|
||||||
if (!exports.send_times_data[client_message_id].was_received()) {
|
|
||||||
blueslip.log("Restarting get_events due to delayed receipt of sent message " + client_message_id);
|
|
||||||
server_events.restart_get_events();
|
|
||||||
}
|
|
||||||
}, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.initialize = function () {
|
exports.initialize = function () {
|
||||||
exports.reset_id_state();
|
exports.reset_id_state();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user