message_events: Update code to handle messages not available locally.

Previously, if the client recieved an "update_messages" event with
"message_id" not present locally, then the event was completely
ignored. But, this can happen when moving messages especially
when doing a partial move due to time limit error.

This commit updates the code to have the code which requires the
message to be present locally run only if it is present instead
of just ignoring the event completely such that the updates for
moving the messages can be done.
This commit is contained in:
Sahil Batra
2023-04-25 20:19:43 +05:30
committed by Tim Abbott
parent 57a89e5228
commit 168680af23

View File

@@ -177,9 +177,9 @@ export function update_messages(events) {
for (const event of events) { for (const event of events) {
const anchor_message = message_store.get(event.message_id); const anchor_message = message_store.get(event.message_id);
if (anchor_message === undefined) { if (anchor_message !== undefined) {
continue; // Logic for updating the specific edited message only
} // needs to run if we had a local copy of the message.
delete anchor_message.local_edit_timestamp; delete anchor_message.local_edit_timestamp;
@@ -222,7 +222,10 @@ export function update_messages(events) {
if (anchor_message.edit_history === undefined) { if (anchor_message.edit_history === undefined) {
anchor_message.edit_history = []; anchor_message.edit_history = [];
} }
anchor_message.edit_history = [edit_history_entry, ...anchor_message.edit_history]; anchor_message.edit_history = [
edit_history_entry,
...anchor_message.edit_history,
];
} }
any_message_content_edited = true; any_message_content_edited = true;
@@ -237,6 +240,7 @@ export function update_messages(events) {
); );
recent_topics_ui.inplace_rerender(topic_key); recent_topics_ui.inplace_rerender(topic_key);
} }
}
// new_topic will be undefined if the topic is unchanged. // new_topic will be undefined if the topic is unchanged.
const new_topic = util.get_edit_event_topic(event); const new_topic = util.get_edit_event_topic(event);
@@ -469,6 +473,7 @@ export function update_messages(events) {
} }
} }
if (anchor_message !== undefined) {
// Mark the message as edited for the UI. The rendering_only // Mark the message as edited for the UI. The rendering_only
// flag is used to indicated update_message events that are // flag is used to indicated update_message events that are
// triggered by server latency optimizations, not user // triggered by server latency optimizations, not user
@@ -479,6 +484,7 @@ export function update_messages(events) {
notifications.received_messages([anchor_message]); notifications.received_messages([anchor_message]);
alert_words.process_message(anchor_message); alert_words.process_message(anchor_message);
}
if (topic_edited || stream_changed) { if (topic_edited || stream_changed) {
// if topic is changed // if topic is changed
@@ -486,7 +492,9 @@ export function update_messages(events) {
let post_edit_topic = new_topic; let post_edit_topic = new_topic;
if (!topic_edited) { if (!topic_edited) {
if (anchor_message !== undefined) {
pre_edit_topic = anchor_message.topic; pre_edit_topic = anchor_message.topic;
}
post_edit_topic = pre_edit_topic; post_edit_topic = pre_edit_topic;
} }
@@ -507,6 +515,7 @@ export function update_messages(events) {
// Rerender "Message edit history" if it was open to the edited message. // Rerender "Message edit history" if it was open to the edited message.
if ( if (
anchor_message !== undefined &&
$("#message-edit-history").parents(".micromodal").hasClass("modal--open") && $("#message-edit-history").parents(".micromodal").hasClass("modal--open") &&
anchor_message.id === Number.parseInt($("#message-history").attr("data-message-id"), 10) anchor_message.id === Number.parseInt($("#message-history").attr("data-message-id"), 10)
) { ) {