2013-12-04 17:16:08 +01:00
|
|
|
var echo = (function () {
|
2018-11-30 00:48:13 +01:00
|
|
|
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
|
2013-12-04 17:16:08 +01:00
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
var waiting_for_id = {};
|
|
|
|
var waiting_for_ack = {};
|
|
|
|
|
2014-01-03 20:39:12 +01:00
|
|
|
function resend_message(message, row) {
|
|
|
|
message.content = message.raw_content;
|
|
|
|
var retry_spinner = row.find('.refresh-failed-message');
|
|
|
|
retry_spinner.toggleClass('rotating', true);
|
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.
2017-07-30 12:56:46 +02:00
|
|
|
|
2014-01-03 20:39:12 +01:00
|
|
|
// Always re-set queue_id if we've gotten a new one
|
|
|
|
// since the time when the message object was initially created
|
2017-04-24 21:40:16 +02:00
|
|
|
message.queue_id = page_params.queue_id;
|
2014-01-03 20:39:12 +01: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.
2017-07-30 12:56:46 +02:00
|
|
|
var local_id = message.local_id;
|
|
|
|
|
|
|
|
function on_success(data) {
|
2014-01-03 20:39:12 +01:00
|
|
|
var message_id = data.id;
|
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.
2017-07-30 12:56:46 +02:00
|
|
|
var locally_echoed = true;
|
2014-01-03 20:39:12 +01:00
|
|
|
|
|
|
|
retry_spinner.toggleClass('rotating', false);
|
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.
2017-07-30 12:56:46 +02:00
|
|
|
|
|
|
|
compose.send_message_success(local_id, message_id, locally_echoed);
|
2014-01-03 20:39:12 +01:00
|
|
|
|
|
|
|
// Resend succeeded, so mark as no longer failed
|
2014-01-31 22:14:57 +01:00
|
|
|
message_store.get(message_id).failed_request = false;
|
2014-01-03 20:39:12 +01:00
|
|
|
ui.show_failed_message_success(message_id);
|
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.
2017-07-30 12:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function on_error(response) {
|
|
|
|
exports.message_send_error(local_id, response);
|
2019-03-19 21:29:53 +01:00
|
|
|
setTimeout(function () {
|
|
|
|
retry_spinner.toggleClass('rotating', false);
|
|
|
|
}, 300);
|
2014-01-03 20:39:12 +01:00
|
|
|
blueslip.log("Manual resend of message failed");
|
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.
2017-07-30 12:56:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sent_messages.start_resend(local_id);
|
2018-02-20 13:08:50 +01:00
|
|
|
transmit.send_message(message, on_success, on_error);
|
2014-01-03 20:39:12 +01:00
|
|
|
}
|
|
|
|
|
2014-01-16 20:18:55 +01:00
|
|
|
function insert_local_message(message_request, local_id) {
|
2013-12-19 17:03:08 +01:00
|
|
|
// Shallow clone of message request object that is turned into something suitable
|
|
|
|
// for zulip.js:add_message
|
|
|
|
// Keep this in sync with changes to compose.create_message_object
|
|
|
|
var message = $.extend({}, message_request);
|
2017-01-20 16:40:45 +01:00
|
|
|
|
|
|
|
// Locally delivered messages cannot be unread (since we sent them), nor
|
|
|
|
// can they alert the user.
|
2017-08-04 16:29:35 +02:00
|
|
|
message.unread = false;
|
2017-01-20 16:40:45 +01:00
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
message.raw_content = message.content;
|
2017-05-09 18:01:43 +02:00
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
// NOTE: This will parse synchronously. We're not using the async pipeline
|
2017-05-09 18:01:43 +02:00
|
|
|
markdown.apply_markdown(message);
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
message.content_type = 'text/html';
|
2017-01-20 18:37:46 +01:00
|
|
|
message.sender_email = people.my_current_email();
|
2017-01-20 23:49:20 +01:00
|
|
|
message.sender_full_name = people.my_full_name();
|
2013-12-19 17:03:08 +01:00
|
|
|
message.avatar_url = page_params.avatar_url;
|
2018-02-24 13:42:27 +01:00
|
|
|
message.timestamp = local_message.now();
|
2014-01-16 20:18:55 +01:00
|
|
|
message.local_id = local_id;
|
2017-07-17 16:52:57 +02:00
|
|
|
message.locally_echoed = true;
|
2013-12-19 17:03:08 +01:00
|
|
|
message.id = message.local_id;
|
2018-11-13 16:19:59 +01:00
|
|
|
markdown.add_topic_links(message);
|
2013-12-19 17:03:08 +01:00
|
|
|
|
|
|
|
waiting_for_id[message.local_id] = message;
|
|
|
|
waiting_for_ack[message.local_id] = message;
|
|
|
|
|
|
|
|
if (message.type === 'stream') {
|
|
|
|
message.display_recipient = message.stream;
|
|
|
|
} else {
|
2016-11-15 06:40:19 +01:00
|
|
|
// Build a display recipient with the full names of each
|
|
|
|
// recipient. Note that it's important that use
|
|
|
|
// util.extract_pm_recipients, which filters out any spurious
|
|
|
|
// ", " at the end of the recipient list
|
|
|
|
var emails = util.extract_pm_recipients(message_request.private_message_recipient);
|
2013-12-19 17:03:08 +01:00
|
|
|
message.display_recipient = _.map(emails, function (email) {
|
|
|
|
email = email.trim();
|
2014-01-30 22:42:19 +01:00
|
|
|
var person = people.get_by_email(email);
|
2016-11-03 20:12:38 +01:00
|
|
|
if (person === undefined) {
|
|
|
|
// For unknown users, we return a skeleton object.
|
2019-06-23 19:54:30 +02:00
|
|
|
return {
|
|
|
|
email: email,
|
|
|
|
full_name: email,
|
|
|
|
unknown_local_echo_user: true,
|
|
|
|
};
|
2013-12-19 17:03:08 +01:00
|
|
|
}
|
2019-06-23 19:54:30 +02:00
|
|
|
|
2016-12-02 21:34:35 +01:00
|
|
|
// NORMAL PATH
|
2019-06-23 19:54:30 +02:00
|
|
|
//
|
|
|
|
// This should match the format of display_recipient
|
|
|
|
// objects generated by the backend code in models.py,
|
|
|
|
// which is why we create a new object with a `.id` field
|
|
|
|
// rather than a `.user_id` field.
|
|
|
|
return {
|
|
|
|
id: person.user_id,
|
|
|
|
email: person.email,
|
|
|
|
full_name: person.full_name,
|
|
|
|
};
|
2013-12-19 17:03:08 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-24 13:42:27 +01:00
|
|
|
local_message.insert_message(message);
|
|
|
|
|
2019-08-06 04:24:43 +02:00
|
|
|
return message.local_id.toString();
|
2014-01-16 20:18:55 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 22:05:11 +02:00
|
|
|
exports.is_slash_command = function (content) {
|
|
|
|
return !content.startsWith('/me') && content.startsWith('/');
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-01-16 20:18:55 +01:00
|
|
|
exports.try_deliver_locally = function try_deliver_locally(message_request) {
|
2017-07-29 02:51:33 +02:00
|
|
|
if (markdown.contains_backend_only_syntax(message_request.content)) {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2014-01-16 20:18:55 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 22:25:25 +02:00
|
|
|
if (narrow_state.active() && !narrow_state.filter().can_apply_locally()) {
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2014-01-16 20:18:55 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 22:05:11 +02:00
|
|
|
if (exports.is_slash_command(message_request.content)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-24 13:42:27 +01:00
|
|
|
var next_local_id = local_message.get_next_id();
|
2017-07-17 22:25:25 +02:00
|
|
|
|
|
|
|
if (!next_local_id) {
|
|
|
|
// This can happen for legit reasons.
|
2018-03-13 13:04:16 +01:00
|
|
|
return;
|
2014-01-24 17:15:35 +01:00
|
|
|
}
|
|
|
|
|
2014-01-16 20:18:55 +01:00
|
|
|
return insert_local_message(message_request, next_local_id);
|
2013-12-19 17:03:08 +01:00
|
|
|
};
|
|
|
|
|
2014-01-02 19:39:22 +01:00
|
|
|
exports.edit_locally = function edit_locally(message, raw_content, new_topic) {
|
2018-05-03 21:12:39 +02:00
|
|
|
var message_content_edited = raw_content !== undefined && message.raw_content !== raw_content;
|
|
|
|
|
2014-01-02 19:39:22 +01:00
|
|
|
if (new_topic !== undefined) {
|
2017-07-26 14:05:25 +02:00
|
|
|
topic_data.remove_message({
|
|
|
|
stream_id: message.stream_id,
|
2018-12-23 16:01:30 +01:00
|
|
|
topic_name: util.get_message_topic(message),
|
2017-07-26 14:05:25 +02:00
|
|
|
});
|
|
|
|
|
2018-12-22 18:44:54 +01:00
|
|
|
util.set_message_topic(message, new_topic);
|
2017-07-26 14:05:25 +02:00
|
|
|
|
|
|
|
topic_data.add_message({
|
|
|
|
stream_id: message.stream_id,
|
2018-12-23 16:01:30 +01:00
|
|
|
topic_name: util.get_message_topic(message),
|
2017-07-26 14:05:25 +02:00
|
|
|
message_id: message.id,
|
|
|
|
});
|
2014-01-02 19:39:22 +01:00
|
|
|
}
|
|
|
|
|
2018-05-03 21:12:39 +02:00
|
|
|
if (message_content_edited) {
|
|
|
|
message.raw_content = raw_content;
|
|
|
|
markdown.apply_markdown(message);
|
|
|
|
}
|
2017-01-20 15:21:28 +01:00
|
|
|
|
2014-01-02 19:39:22 +01:00
|
|
|
// We don't handle unread counts since local messages must be sent by us
|
|
|
|
|
2014-03-04 16:47:44 +01:00
|
|
|
home_msg_list.view.rerender_messages([message]);
|
2016-04-25 23:45:25 +02:00
|
|
|
if (current_msg_list === message_list.narrowed) {
|
|
|
|
message_list.narrowed.view.rerender_messages([message]);
|
2014-01-02 19:39:22 +01:00
|
|
|
}
|
|
|
|
stream_list.update_streams_sidebar();
|
2016-11-29 16:53:43 +01:00
|
|
|
pm_list.update_private_messages();
|
2014-01-02 19:39:22 +01:00
|
|
|
};
|
|
|
|
|
2013-12-19 17:03:08 +01:00
|
|
|
exports.reify_message_id = function reify_message_id(local_id, server_id) {
|
|
|
|
var message = waiting_for_id[local_id];
|
|
|
|
delete waiting_for_id[local_id];
|
|
|
|
|
|
|
|
// reify_message_id is called both on receiving a self-sent message
|
|
|
|
// from the server, and on receiving the response to the send request
|
|
|
|
// Reification is only needed the first time the server id is found
|
|
|
|
if (message === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
message.id = server_id;
|
2017-07-17 16:52:57 +02:00
|
|
|
message.locally_echoed = false;
|
2013-12-19 17:03:08 +01:00
|
|
|
|
2019-08-06 04:24:43 +02:00
|
|
|
var opts = {old_id: parseFloat(local_id), new_id: server_id};
|
2017-07-19 12:49:49 +02:00
|
|
|
|
|
|
|
message_store.reify_message_id(opts);
|
2017-07-19 14:39:28 +02:00
|
|
|
notifications.reify_message_id(opts);
|
2013-12-19 17:03:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.process_from_server = function process_from_server(messages) {
|
2014-02-11 16:19:42 +01:00
|
|
|
var msgs_to_rerender = [];
|
2017-09-26 19:22:52 +02:00
|
|
|
var non_echo_messages = [];
|
|
|
|
|
|
|
|
_.each(messages, function (message) {
|
2013-12-19 17:03:08 +01:00
|
|
|
// In case we get the sent message before we get the send ACK, reify here
|
|
|
|
|
|
|
|
var client_message = waiting_for_ack[message.local_id];
|
2017-09-26 19:22:52 +02:00
|
|
|
if (client_message === undefined) {
|
|
|
|
// For messages that weren't locally echoed, we go through
|
|
|
|
// the "main" codepath that doesn't have to id reconciliation.
|
|
|
|
// We simply return non-echo messages to our caller.
|
|
|
|
non_echo_messages.push(message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.reify_message_id(message.local_id, message.id);
|
|
|
|
|
|
|
|
if (client_message.content !== message.content) {
|
|
|
|
client_message.content = message.content;
|
|
|
|
sent_messages.mark_disparity(message.local_id);
|
2013-12-19 17:03:08 +01:00
|
|
|
}
|
2017-09-26 21:12:27 +02:00
|
|
|
|
2017-12-16 23:25:31 +01:00
|
|
|
message_store.update_booleans(client_message, message.flags);
|
2017-10-12 22:11:43 +02:00
|
|
|
|
|
|
|
// We don't try to highlight alert words locally, so we have to
|
|
|
|
// do it now. (Note that we will indeed highlight alert words in
|
|
|
|
// messages that we sent to ourselves, since we might want to test
|
|
|
|
// that our alert words are set up correctly.)
|
|
|
|
alert_words.process_message(client_message);
|
|
|
|
|
2017-09-26 22:01:39 +02:00
|
|
|
// Previously, the message had the "local echo" timestamp set
|
|
|
|
// by the browser; if there was some round-trip delay to the
|
|
|
|
// server, the actual server-side timestamp could be slightly
|
|
|
|
// different. This corrects the frontend timestamp to match
|
|
|
|
// the backend.
|
2017-09-26 21:12:27 +02:00
|
|
|
client_message.timestamp = message.timestamp;
|
|
|
|
|
2019-07-20 23:38:52 +02:00
|
|
|
util.set_topic_links(client_message, util.get_topic_links(message));
|
2019-06-21 06:31:52 +02:00
|
|
|
client_message.is_me_message = message.is_me_message;
|
2018-02-12 15:12:40 +01:00
|
|
|
client_message.submessages = message.submessages;
|
|
|
|
|
2017-09-26 19:22:52 +02:00
|
|
|
msgs_to_rerender.push(client_message);
|
|
|
|
delete waiting_for_ack[client_message.id];
|
2013-12-19 17:03:08 +01:00
|
|
|
});
|
|
|
|
|
2017-09-26 21:04:23 +02:00
|
|
|
if (msgs_to_rerender.length > 0) {
|
2017-09-26 22:01:39 +02:00
|
|
|
// In theory, we could just rerender messages where there were
|
|
|
|
// changes in either the rounded timestamp we display or the
|
|
|
|
// message content, but in practice, there's no harm to just
|
|
|
|
// doing it unconditionally.
|
2014-02-11 16:19:42 +01:00
|
|
|
home_msg_list.view.rerender_messages(msgs_to_rerender);
|
2016-04-25 23:45:25 +02:00
|
|
|
if (current_msg_list === message_list.narrowed) {
|
|
|
|
message_list.narrowed.view.rerender_messages(msgs_to_rerender);
|
2013-12-19 17:03:08 +01:00
|
|
|
}
|
|
|
|
}
|
2017-09-26 21:04:23 +02:00
|
|
|
|
2017-09-26 19:22:52 +02:00
|
|
|
return non_echo_messages;
|
2013-12-19 17:03:08 +01:00
|
|
|
};
|
|
|
|
|
2019-06-21 07:33:02 +02:00
|
|
|
exports._patch_waiting_for_awk = function _patch_waiting_for_awk(data) {
|
|
|
|
// Only for testing
|
|
|
|
waiting_for_ack = data;
|
|
|
|
};
|
|
|
|
|
2014-01-02 17:34:16 +01:00
|
|
|
exports.message_send_error = function message_send_error(local_id, error_response) {
|
2013-12-19 17:03:08 +01:00
|
|
|
// Error sending message, show inline
|
2014-01-31 22:14:57 +01:00
|
|
|
message_store.get(local_id).failed_request = true;
|
2014-01-02 17:34:16 +01:00
|
|
|
ui.show_message_failed(local_id, error_response);
|
2013-12-19 17:03:08 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function abort_message(message) {
|
|
|
|
// Remove in all lists in which it exists
|
2016-04-21 22:49:23 +02:00
|
|
|
_.each([message_list.all, home_msg_list, current_msg_list], function (msg_list) {
|
2013-12-19 17:03:08 +01:00
|
|
|
msg_list.remove_and_rerender([message]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-15 22:03:14 +02:00
|
|
|
exports.initialize = function () {
|
2013-12-19 17:03:08 +01:00
|
|
|
function on_failed_action(action, callback) {
|
|
|
|
$("#main_div").on("click", "." + action + "-failed-message", function (e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
popovers.hide_all();
|
2014-01-03 20:39:12 +01:00
|
|
|
var row = $(this).closest(".message_row");
|
|
|
|
var message_id = rows.id(row);
|
2013-12-19 17:03:08 +01:00
|
|
|
// Message should be waiting for ack and only have a local id,
|
|
|
|
// otherwise send would not have failed
|
|
|
|
var message = waiting_for_ack[message_id];
|
|
|
|
if (message === undefined) {
|
2014-02-05 05:07:13 +01:00
|
|
|
blueslip.warn("Got resend or retry on failure request but did not find message in ack list " + message_id);
|
2013-12-19 17:03:08 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-01-03 20:39:12 +01:00
|
|
|
callback(message, row);
|
2013-12-19 17:03:08 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
on_failed_action('remove', abort_message);
|
|
|
|
on_failed_action('refresh', resend_message);
|
2018-05-15 22:03:14 +02:00
|
|
|
};
|
2013-12-19 17:03:08 +01:00
|
|
|
|
2013-12-04 17:16:08 +01:00
|
|
|
return exports;
|
|
|
|
|
|
|
|
}());
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = echo;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.echo = echo;
|