From 7d8d9c1bf945b051a1e5355405ede72234a17a2e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 21 Apr 2017 11:27:45 -0700 Subject: [PATCH] Fix message-edit animations being displayed after sending. This fixes a regression in 30414806008f4d80841fdced34449eb937fbb842 that would cause anything rendered on the backend differently than on the frontend to experience this animation. We actually only want to do the animation when the message content was changed in a way that generates an edit history event, i.e. a user-facing edit, not in cases where we're either transparently swapping in post-backend-rendering content (e.g. with link previews) or cases where there's a discrepancy between the exact HTML from the frontend and backend markdown processes (e.g. mentions). --- static/js/message_events.js | 7 +++++-- static/js/message_list_view.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/static/js/message_events.js b/static/js/message_events.js index c2097229b7..2240b396b9 100644 --- a/static/js/message_events.js +++ b/static/js/message_events.js @@ -111,6 +111,7 @@ exports.update_messages = function update_messages(events) { var msgs_to_rerender = []; var topic_edited = false; var changed_narrow = false; + var message_content_edited = false; _.each(events, function (event) { var msg = message_store.get(event.message_id); @@ -213,6 +214,7 @@ exports.update_messages = function update_messages(events) { msg.edit_history = []; } msg.edit_history = [edit_history_entry].concat(msg.edit_history); + message_content_edited = true; } msg.last_edit_timestamp = event.edit_timestamp; @@ -233,9 +235,10 @@ exports.update_messages = function update_messages(events) { message_list.narrowed.rerender(); } } else { - home_msg_list.view.rerender_messages(msgs_to_rerender); + // If the content of the message was edited, we do a special animation. + current_msg_list.view.rerender_messages(msgs_to_rerender, message_content_edited); if (current_msg_list === message_list.narrowed) { - message_list.narrowed.view.rerender_messages(msgs_to_rerender); + home_msg_list.view.rerender_messages(msgs_to_rerender); } } unread_ui.update_unread_counts(); diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index fccb1a299d..8a083e6162 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -812,7 +812,8 @@ MessageListView.prototype = { header.replaceWith(rendered_recipient_row); }, - _rerender_message: function MessageListView___rerender_message(message_container) { + _rerender_message: function MessageListView___rerender_message(message_container, + message_content_edited) { var row = this.get_row(message_container.msg.id); var was_selected = this.list.selected_message() === message_container.msg; @@ -821,7 +822,9 @@ MessageListView.prototype = { this._maybe_format_me_message(message_container); var rendered_msg = $(this._get_message_template(message_container)); - rendered_msg.addClass("fade-in-message"); + if (message_content_edited) { + rendered_msg.addClass("fade-in-message"); + } this._post_process_dom_messages(rendered_msg.get()); row.replaceWith(rendered_msg); @@ -830,7 +833,8 @@ MessageListView.prototype = { } }, - rerender_messages: function MessageListView__rerender_messages(messages) { + rerender_messages: function MessageListView__rerender_messages(messages, + message_content_edited) { var self = this; // Convert messages to list messages @@ -852,13 +856,13 @@ MessageListView.prototype = { message_groups.push(current_group); current_group = []; } - self._rerender_message(message_container); + self._rerender_message(message_container, message_content_edited); }); if (current_group.length !== 0) { message_groups.push(current_group); } _.each(message_groups, function (messages_in_group) { - self._rerender_header(messages_in_group); + self._rerender_header(messages_in_group, message_content_edited); }); },