mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
sending messages: Extract sent_messages.js.
This commit extract send_messages.js to clean up code related
to the following things:
* sending data to /json/report_send_time
* restarting the event loop if events don't arrive on time
The code related to /json/report changes the following ways:
* We track the state almost completely in the new
send_messages.js module, with other modules just
making one-line calls.
* We no longer send "displayed" times to the servers, since
we were kind of lying about them anyway.
* We now explicitly track the state of each single sent
message in its own object.
* We now look up data related to the messages by local_id,
instead of message_id. The problem with message_id was
that is was mutable. Now we use local_id, and we extend
the local_id concept to messages that don't get rendered
client side. We no longer need to react to the
'message_id_changed' event to change our hash key.
* The code used to live in many places:
* various big chunks were scattered among compose.js,
and those were all moved or reduced to one-line
calls into the new module
* echo.js continues to make basically one-line calls,
but it no longer calls compose.report_as_received(),
nor does it set the "start" time.
* message_util.js used to report received events, but
only when they finally got drawn in the home view;
this code is gone now
The code related to restarting the event loop if events don't arrive
changes as follows:
* The timer now gets set up from within
send_messages.message_state.report_server_ack,
where we can easily inspect the current state of the
possibly-still-in-flight message.
* The code to confirm that an event was received happens now
in server_events.js, rather than later, so that we don't
falsely blame the event loop for a downstream bug. (Plus
it's easier to just do it one place.)
This change removes a fair amount of code from our node tests. Some
of the removal is good stuff related to us completing killing off
unnecessary code. Other removals are more expediency-driven, and
we should make another sweep at ramping up our coverage on compose.js,
with possibly a little more mocking of the new `send_messages` code
layer, since it's now abstracted better.
There is also some minor cleanup to echo.resend_message() in this
commit.
See #5968 for a detailed breakdown of the changes.
This commit is contained in:
@@ -9,26 +9,34 @@ function resend_message(message, row) {
|
||||
message.content = message.raw_content;
|
||||
var retry_spinner = row.find('.refresh-failed-message');
|
||||
retry_spinner.toggleClass('rotating', true);
|
||||
|
||||
// Always re-set queue_id if we've gotten a new one
|
||||
// since the time when the message object was initially created
|
||||
message.queue_id = page_params.queue_id;
|
||||
var start_time = new Date();
|
||||
compose.transmit_message(message, function success(data) {
|
||||
retry_spinner.toggleClass('rotating', false);
|
||||
|
||||
var local_id = message.local_id;
|
||||
|
||||
function on_success(data) {
|
||||
var message_id = data.id;
|
||||
var locally_echoed = true;
|
||||
|
||||
retry_spinner.toggleClass('rotating', false);
|
||||
compose.send_message_success(message.local_id, message_id, start_time, true);
|
||||
|
||||
compose.send_message_success(local_id, message_id, locally_echoed);
|
||||
|
||||
// Resend succeeded, so mark as no longer failed
|
||||
message_store.get(message_id).failed_request = false;
|
||||
ui.show_failed_message_success(message_id);
|
||||
}, function error(response) {
|
||||
exports.message_send_error(message.local_id, response);
|
||||
}
|
||||
|
||||
function on_error(response) {
|
||||
exports.message_send_error(local_id, response);
|
||||
retry_spinner.toggleClass('rotating', false);
|
||||
blueslip.log("Manual resend of message failed");
|
||||
});
|
||||
}
|
||||
|
||||
sent_messages.start_resend(local_id);
|
||||
compose.transmit_message(message, on_success, on_error);
|
||||
}
|
||||
|
||||
function truncate_precision(float) {
|
||||
@@ -205,18 +213,18 @@ exports.process_from_server = function process_from_server(messages) {
|
||||
var msgs_to_rerender = [];
|
||||
messages = _.filter(messages, function (message) {
|
||||
// In case we get the sent message before we get the send ACK, reify here
|
||||
exports.reify_message_id(message.local_id, message.id);
|
||||
|
||||
var client_message = waiting_for_ack[message.local_id];
|
||||
if (client_message !== undefined) {
|
||||
exports.reify_message_id(message.local_id, message.id);
|
||||
|
||||
if (client_message.content !== message.content) {
|
||||
client_message.content = message.content;
|
||||
updated = true;
|
||||
compose.mark_rendered_content_disparity(message.id, true);
|
||||
sent_messages.mark_disparity(message.local_id);
|
||||
}
|
||||
msgs_to_rerender.push(client_message);
|
||||
locally_processed_ids.push(client_message.id);
|
||||
compose.report_as_received(client_message);
|
||||
delete waiting_for_ack[client_message.id];
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user