echo: Start tracking local messages before updating sidebars.

Previously, when `insert_local_message` was called, the
data structures in the `echo_state` are updated with the new
local messages after calling `insert_new_message`. This would
update the stream sidebar before even updating the `echo_state`
with the new local messages.

This commit introduces `track_local_message`, which basically
updates the `echo_state` data structures with the local
message before actually updating the stream sidebar.

This is a preparatory commit to update stream_topic_history
to only contain acked message ids.
This commit is contained in:
roanster007 2024-08-21 00:42:43 +05:30 committed by Tim Abbott
parent 3f307f5941
commit da75fed5be
3 changed files with 18 additions and 4 deletions

View File

@ -237,6 +237,12 @@ export function build_display_recipient(message: LocalMessage): DisplayRecipient
return display_recipient;
}
export function track_local_message(message: Message): void {
assert(message.local_id !== undefined);
echo_state.set_message_waiting_for_id(message.local_id, message);
echo_state.set_message_waiting_for_ack(message.local_id, message);
}
export function insert_local_message(
message_request: MessageRequest,
local_id_float: number,
@ -273,9 +279,6 @@ export function insert_local_message(
const [message] = insert_new_messages([local_message], true, true);
assert(message !== undefined);
assert(message.local_id !== undefined);
echo_state.set_message_waiting_for_id(message.local_id, message);
echo_state.set_message_waiting_for_ack(message.local_id, message);
return message;
}

View File

@ -11,6 +11,7 @@ import * as compose_state from "./compose_state";
import * as compose_validate from "./compose_validate";
import * as direct_message_group_data from "./direct_message_group_data";
import * as drafts from "./drafts";
import * as echo from "./echo";
import * as message_edit from "./message_edit";
import * as message_edit_history from "./message_edit_history";
import * as message_events_util from "./message_events_util";
@ -239,6 +240,13 @@ export function insert_new_messages(messages, sent_by_this_client, deliver_local
unread_ui.update_unread_counts();
}
// Messages being locally echoed need must be inserted into this
// tracking before we update the stream sidebar, to take advantage
// of how stream_topic_history uses the echo data structures.
if (deliver_locally) {
messages.map((message) => echo.track_local_message(message));
}
unread_ops.process_visible();
message_notifications.received_messages(messages);
stream_list.update_streams_sidebar();

View File

@ -372,7 +372,10 @@ run_test("test reify_message_id", ({override}) => {
sender_id: 123,
draft_id: 100,
};
echo.insert_local_message(message_request, local_id_float, (messages) => messages);
echo.insert_local_message(message_request, local_id_float, (messages) => {
messages.map((message) => echo.track_local_message(message));
return messages;
});
let message_store_reify_called = false;
let notifications_reify_called = false;