message_edit: Fix rendering bug when topic-editing single messages.

If you topic-edited a single message within a narrow, we would update
all our unreads/sidebar/etc. data structures, and would rerender the
message if appropriate.  However, for the corner case of being inside
a topic narrow when you did this, we didn't have logic to remove the
message from the narrow (which is the appropriate situation when you
just topic-edited a message in a narrow).

When topic-editing multiple messages including the currently selected
message (the more common case), we would end up changing the narrow,
resulting in this issue being masked.

Fixes #11601.
This commit is contained in:
Tim Abbott 2019-02-27 13:57:45 -08:00
parent da043f163d
commit 7717337b1e
1 changed files with 13 additions and 2 deletions

View File

@ -157,12 +157,11 @@ exports.update_messages = function update_messages(events) {
} }
} }
var current_filter = narrow_state.filter();
if (going_forward_change) { if (going_forward_change) {
var current_id = current_msg_list.selected_id(); var current_id = current_msg_list.selected_id();
var selection_changed_topic = _.indexOf(event.message_ids, current_id) >= 0; var selection_changed_topic = _.indexOf(event.message_ids, current_id) >= 0;
if (selection_changed_topic) { if (selection_changed_topic) {
var current_filter = narrow_state.filter();
if (current_filter && stream_name) { if (current_filter && stream_name) {
if (current_filter.has_topic(stream_name, orig_topic)) { if (current_filter.has_topic(stream_name, orig_topic)) {
var new_filter = current_filter.filter_with_new_topic(new_topic); var new_filter = current_filter.filter_with_new_topic(new_topic);
@ -205,6 +204,18 @@ exports.update_messages = function update_messages(events) {
topic_name: util.get_message_topic(msg), topic_name: util.get_message_topic(msg),
message_id: msg.id, message_id: msg.id,
}); });
if (!changed_narrow && current_filter && current_filter.can_apply_locally() &&
!current_filter.predicate()(msg)) {
// This topic edit makes this message leave the
// current narrow, which is not being changed as
// part of processing this event. So we should
// remove the message from the current/narrowed message list.
var cur_row = current_msg_list.get_row(id);
if (cur_row !== undefined) {
current_msg_list.remove_and_rerender([{id: id}]);
}
}
}); });
} }