refactor: Have try_deliver_locally() return a message.

This will allow us access to the float version of the
message's id in an upcoming commit, without us having
to do possibly brittle string-to-float translations.
This commit is contained in:
Steve Howell 2020-04-09 17:22:30 +00:00 committed by Tim Abbott
parent dccbb25a49
commit f4f403decb
2 changed files with 6 additions and 4 deletions

View File

@ -305,12 +305,13 @@ exports.send_message = function send_message(request) {
let local_id;
let locally_echoed;
local_id = echo.try_deliver_locally(request);
if (local_id) {
const message = echo.try_deliver_locally(request);
if (message) {
// We are rendering this message locally with an id
// like 92l99.01 that corresponds to a reasonable
// approximation of the id we'll get from the server
// in terms of sorting messages.
local_id = message.local_id;
locally_echoed = true;
} else {
// We are not rendering this message locally, but we

View File

@ -133,7 +133,7 @@ exports.insert_local_message = function (message_request, local_id_float) {
message.display_recipient = echo.build_display_recipient(message);
local_message.insert_message(message);
return message.local_id;
return message;
};
exports.is_slash_command = function (content) {
@ -174,7 +174,8 @@ exports.try_deliver_locally = function (message_request) {
return;
}
return exports.insert_local_message(message_request, local_id_float);
const message = exports.insert_local_message(message_request, local_id_float);
return message;
};
exports.edit_locally = function (message, request) {