send_message: Fix 'sent_by_this_client' incorrectly set.

Messages that are not delivered locally like slash command messages,
messages with backend only syntax, etc are processed by
'echo.process_from_server' function.

Earlier, in 'echo.process_from_server' we were clearing out
the local IDs of non-echoed messages and then a check to
set 'sent_by_this_client' based on local_id.

This led to 'sent_by_this_client' incorrectly set to False
as the local_id is already deleted.

This commit fixes the incorrect behavior. We first determine
the 'sent_by_this_client' on the basis of local_id and then
we delete.
This commit is contained in:
Prakhar Pratyush 2024-03-21 12:29:32 +05:30 committed by Tim Abbott
parent 7de527f3bc
commit 8d868ec149
2 changed files with 7 additions and 4 deletions

View File

@ -388,7 +388,6 @@ export function process_from_server(messages) {
// the "main" codepath that doesn't have to id reconciliation.
// We simply return non-echo messages to our caller.
non_echo_messages.push(message);
sent_messages.report_event_received(local_id);
continue;
}

View File

@ -106,9 +106,13 @@ function get_events_success(events) {
try {
messages = echo.process_from_server(messages);
if (messages.length > 0) {
const sent_by_this_client = messages.some((msg) =>
sent_messages.messages.has(msg.local_id),
);
let sent_by_this_client = false;
for (const msg of messages) {
if (sent_messages.messages.has(msg.local_id)) {
sent_by_this_client = true;
}
sent_messages.report_event_received(msg.local_id);
}
// If some message in this batch of events was sent by this
// client, almost every time, this message will be the only one
// in messages, because multiple messages being returned by