mirror of
https://github.com/zulip/zulip.git
synced 2025-11-13 02:17:19 +00:00
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:
@@ -177,65 +177,69 @@ export function update_messages(events) {
|
||||
|
||||
for (const event of events) {
|
||||
const anchor_message = message_store.get(event.message_id);
|
||||
if (anchor_message === undefined) {
|
||||
continue;
|
||||
}
|
||||
if (anchor_message !== undefined) {
|
||||
// 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;
|
||||
|
||||
msgs_to_rerender.push(anchor_message);
|
||||
msgs_to_rerender.push(anchor_message);
|
||||
|
||||
message_store.update_booleans(anchor_message, event.flags);
|
||||
message_store.update_booleans(anchor_message, event.flags);
|
||||
|
||||
condense.un_cache_message_content_height(anchor_message.id);
|
||||
condense.un_cache_message_content_height(anchor_message.id);
|
||||
|
||||
if (event.rendered_content !== undefined) {
|
||||
anchor_message.content = event.rendered_content;
|
||||
}
|
||||
|
||||
if (event.is_me_message !== undefined) {
|
||||
anchor_message.is_me_message = event.is_me_message;
|
||||
}
|
||||
|
||||
// mark the current message edit attempt as complete.
|
||||
message_edit.end_message_edit(event.message_id);
|
||||
|
||||
// Save the content edit to the front end anchor_message.edit_history
|
||||
// before topic edits to ensure that combined topic / content
|
||||
// edits have edit_history logged for both before any
|
||||
// potential narrowing as part of the topic edit loop.
|
||||
if (event.orig_content !== undefined) {
|
||||
if (page_params.realm_allow_edit_history) {
|
||||
// Note that we do this for topic edits separately, below.
|
||||
// If an event changed both content and topic, we'll generate
|
||||
// two client-side events, which is probably good for display.
|
||||
const edit_history_entry = {
|
||||
user_id: event.user_id,
|
||||
prev_content: event.orig_content,
|
||||
prev_rendered_content: event.orig_rendered_content,
|
||||
prev_rendered_content_version: event.prev_rendered_content_version,
|
||||
timestamp: event.edit_timestamp,
|
||||
};
|
||||
// Add message's edit_history in message dict
|
||||
// For messages that are edited, edit_history needs to
|
||||
// be added to message in frontend.
|
||||
if (anchor_message.edit_history === undefined) {
|
||||
anchor_message.edit_history = [];
|
||||
}
|
||||
anchor_message.edit_history = [edit_history_entry, ...anchor_message.edit_history];
|
||||
if (event.rendered_content !== undefined) {
|
||||
anchor_message.content = event.rendered_content;
|
||||
}
|
||||
any_message_content_edited = true;
|
||||
|
||||
// Update raw_content, so that editing a few times in a row is fast.
|
||||
anchor_message.raw_content = event.content;
|
||||
}
|
||||
if (event.is_me_message !== undefined) {
|
||||
anchor_message.is_me_message = event.is_me_message;
|
||||
}
|
||||
|
||||
if (unread.update_message_for_mention(anchor_message, any_message_content_edited)) {
|
||||
const topic_key = recent_topics_util.get_topic_key(
|
||||
anchor_message.stream_id,
|
||||
anchor_message.topic,
|
||||
);
|
||||
recent_topics_ui.inplace_rerender(topic_key);
|
||||
// mark the current message edit attempt as complete.
|
||||
message_edit.end_message_edit(event.message_id);
|
||||
|
||||
// Save the content edit to the front end anchor_message.edit_history
|
||||
// before topic edits to ensure that combined topic / content
|
||||
// edits have edit_history logged for both before any
|
||||
// potential narrowing as part of the topic edit loop.
|
||||
if (event.orig_content !== undefined) {
|
||||
if (page_params.realm_allow_edit_history) {
|
||||
// Note that we do this for topic edits separately, below.
|
||||
// If an event changed both content and topic, we'll generate
|
||||
// two client-side events, which is probably good for display.
|
||||
const edit_history_entry = {
|
||||
user_id: event.user_id,
|
||||
prev_content: event.orig_content,
|
||||
prev_rendered_content: event.orig_rendered_content,
|
||||
prev_rendered_content_version: event.prev_rendered_content_version,
|
||||
timestamp: event.edit_timestamp,
|
||||
};
|
||||
// Add message's edit_history in message dict
|
||||
// For messages that are edited, edit_history needs to
|
||||
// be added to message in frontend.
|
||||
if (anchor_message.edit_history === undefined) {
|
||||
anchor_message.edit_history = [];
|
||||
}
|
||||
anchor_message.edit_history = [
|
||||
edit_history_entry,
|
||||
...anchor_message.edit_history,
|
||||
];
|
||||
}
|
||||
any_message_content_edited = true;
|
||||
|
||||
// Update raw_content, so that editing a few times in a row is fast.
|
||||
anchor_message.raw_content = event.content;
|
||||
}
|
||||
|
||||
if (unread.update_message_for_mention(anchor_message, any_message_content_edited)) {
|
||||
const topic_key = recent_topics_util.get_topic_key(
|
||||
anchor_message.stream_id,
|
||||
anchor_message.topic,
|
||||
);
|
||||
recent_topics_ui.inplace_rerender(topic_key);
|
||||
}
|
||||
}
|
||||
|
||||
// new_topic will be undefined if the topic is unchanged.
|
||||
@@ -469,16 +473,18 @@ export function update_messages(events) {
|
||||
}
|
||||
}
|
||||
|
||||
// Mark the message as edited for the UI. The rendering_only
|
||||
// flag is used to indicated update_message events that are
|
||||
// triggered by server latency optimizations, not user
|
||||
// interactions; these should not generate edit history updates.
|
||||
if (!event.rendering_only) {
|
||||
anchor_message.last_edit_timestamp = event.edit_timestamp;
|
||||
}
|
||||
if (anchor_message !== undefined) {
|
||||
// Mark the message as edited for the UI. The rendering_only
|
||||
// flag is used to indicated update_message events that are
|
||||
// triggered by server latency optimizations, not user
|
||||
// interactions; these should not generate edit history updates.
|
||||
if (!event.rendering_only) {
|
||||
anchor_message.last_edit_timestamp = event.edit_timestamp;
|
||||
}
|
||||
|
||||
notifications.received_messages([anchor_message]);
|
||||
alert_words.process_message(anchor_message);
|
||||
notifications.received_messages([anchor_message]);
|
||||
alert_words.process_message(anchor_message);
|
||||
}
|
||||
|
||||
if (topic_edited || stream_changed) {
|
||||
// if topic is changed
|
||||
@@ -486,7 +492,9 @@ export function update_messages(events) {
|
||||
let post_edit_topic = new_topic;
|
||||
|
||||
if (!topic_edited) {
|
||||
pre_edit_topic = anchor_message.topic;
|
||||
if (anchor_message !== undefined) {
|
||||
pre_edit_topic = anchor_message.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.
|
||||
if (
|
||||
anchor_message !== undefined &&
|
||||
$("#message-edit-history").parents(".micromodal").hasClass("modal--open") &&
|
||||
anchor_message.id === Number.parseInt($("#message-history").attr("data-message-id"), 10)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user