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 local_id;
let locally_echoed; let locally_echoed;
local_id = echo.try_deliver_locally(request); const message = echo.try_deliver_locally(request);
if (local_id) { if (message) {
// We are rendering this message locally with an id // We are rendering this message locally with an id
// like 92l99.01 that corresponds to a reasonable // like 92l99.01 that corresponds to a reasonable
// approximation of the id we'll get from the server // approximation of the id we'll get from the server
// in terms of sorting messages. // in terms of sorting messages.
local_id = message.local_id;
locally_echoed = true; locally_echoed = true;
} else { } else {
// We are not rendering this message locally, but we // 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); message.display_recipient = echo.build_display_recipient(message);
local_message.insert_message(message); local_message.insert_message(message);
return message.local_id; return message;
}; };
exports.is_slash_command = function (content) { exports.is_slash_command = function (content) {
@ -174,7 +174,8 @@ exports.try_deliver_locally = function (message_request) {
return; 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) { exports.edit_locally = function (message, request) {