mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
sent_messages: Convert message_state to an ES6 class MessageState.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
daf5a78e98
commit
cd913b7ebc
@@ -40,88 +40,83 @@ exports.start_tracking_message = function (opts) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = exports.message_state(opts);
|
const state = new exports.MessageState(opts);
|
||||||
|
|
||||||
exports.messages.set(local_id, state);
|
exports.messages.set(local_id, state);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.message_state = function (opts) {
|
class MessageState {
|
||||||
const self = {};
|
start = new Date();
|
||||||
self.data = {};
|
|
||||||
|
|
||||||
self.data.start = new Date();
|
received = undefined;
|
||||||
|
send_finished = undefined;
|
||||||
|
rendered_content_disparity = false;
|
||||||
|
|
||||||
self.data.local_id = opts.local_id;
|
constructor(opts) {
|
||||||
self.data.locally_echoed = opts.locally_echoed;
|
this.local_id = opts.local_id;
|
||||||
|
this.locally_echoed = opts.locally_echoed;
|
||||||
|
}
|
||||||
|
|
||||||
self.data.received = undefined;
|
start_resend() {
|
||||||
self.data.send_finished = undefined;
|
this.start = new Date();
|
||||||
self.data.rendered_content_disparity = false;
|
this.received = undefined;
|
||||||
|
this.send_finished = undefined;
|
||||||
|
this.rendered_content_disparity = false;
|
||||||
|
}
|
||||||
|
|
||||||
self.start_resend = function () {
|
maybe_restart_event_loop() {
|
||||||
self.data.start = new Date();
|
if (this.received) {
|
||||||
self.data.received = undefined;
|
|
||||||
self.data.send_finished = undefined;
|
|
||||||
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
|
// We got our event, no need to do anything
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
blueslip.log(
|
blueslip.log(
|
||||||
"Restarting get_events due to " +
|
"Restarting get_events due to " + "delayed receipt of sent message " + this.local_id,
|
||||||
"delayed receipt of sent message " +
|
|
||||||
self.data.local_id,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
server_events.restart_get_events();
|
server_events.restart_get_events();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.maybe_report_send_times = function () {
|
maybe_report_send_times() {
|
||||||
if (!self.ready()) {
|
if (!this.ready()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = self.data;
|
|
||||||
report_send_time(
|
report_send_time(
|
||||||
data.send_finished - data.start,
|
this.send_finished - this.start,
|
||||||
data.received - data.start,
|
this.received - this.start,
|
||||||
data.locally_echoed,
|
this.locally_echoed,
|
||||||
data.rendered_content_disparity,
|
this.rendered_content_disparity,
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
self.report_event_received = function () {
|
report_event_received() {
|
||||||
self.data.received = new Date();
|
this.received = new Date();
|
||||||
self.maybe_report_send_times();
|
this.maybe_report_send_times();
|
||||||
};
|
}
|
||||||
|
|
||||||
self.mark_disparity = function () {
|
mark_disparity() {
|
||||||
self.data.rendered_content_disparity = true;
|
this.rendered_content_disparity = true;
|
||||||
};
|
}
|
||||||
|
|
||||||
self.report_server_ack = function () {
|
report_server_ack() {
|
||||||
self.data.send_finished = new Date();
|
this.send_finished = new Date();
|
||||||
self.maybe_report_send_times();
|
this.maybe_report_send_times();
|
||||||
|
|
||||||
// We only start our timer for events coming in here,
|
// We only start our timer for events coming in here,
|
||||||
// since it's plausible the server rejected our message,
|
// since it's plausible the server rejected our message,
|
||||||
// or took a while to process it, but there is nothing
|
// or took a while to process it, but there is nothing
|
||||||
// wrong with our event loop.
|
// wrong with our event loop.
|
||||||
|
|
||||||
if (!self.data.received) {
|
if (!this.received) {
|
||||||
setTimeout(self.maybe_restart_event_loop, 5000);
|
setTimeout(this.maybe_restart_event_loop, 5000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
self.ready = function () {
|
ready() {
|
||||||
return self.data.send_finished !== undefined && self.data.received !== undefined;
|
return this.send_finished !== undefined && this.received !== undefined;
|
||||||
};
|
}
|
||||||
|
}
|
||||||
return self;
|
exports.MessageState = MessageState;
|
||||||
};
|
|
||||||
|
|
||||||
exports.get_message_state = function (local_id) {
|
exports.get_message_state = function (local_id) {
|
||||||
const state = exports.messages.get(local_id);
|
const state = exports.messages.get(local_id);
|
||||||
|
|||||||
Reference in New Issue
Block a user