streams: Fix live update of stream name when renamed.

Currently, the Stream Name change isn't reflected in the streams
sidebar when a stream is renamed if the order of streams in the
sidebar remains unchanged, because the optimization to avoid
rerendering when nothing changes about the order prevents the
rerendering code from running.

We fix by this adding a flag in build_stream_list and
update_streams_sidebar functions to force a rerender, and pass that
when a stream is renamed.

Fixes #16026.
This commit is contained in:
Suyash Vardhan Mathur 2020-08-13 18:06:41 +05:30 committed by Tim Abbott
parent 2d847728a3
commit 6b48fb3c08
1 changed files with 5 additions and 5 deletions

View File

@ -84,7 +84,7 @@ exports.create_initial_sidebar_rows = function () {
} }
}; };
exports.build_stream_list = function () { exports.build_stream_list = function (force_rerender) {
// This function assumes we have already created the individual // This function assumes we have already created the individual
// sidebar rows. Our job here is to build the bigger widget, // sidebar rows. Our job here is to build the bigger widget,
// which largely is a matter of arranging the individual rows in // which largely is a matter of arranging the individual rows in
@ -98,7 +98,7 @@ exports.build_stream_list = function () {
// we get three lists of streams (pinned/normal/dormant). // we get three lists of streams (pinned/normal/dormant).
const stream_groups = stream_sort.sort_groups(streams, get_search_term()); const stream_groups = stream_sort.sort_groups(streams, get_search_term());
if (stream_groups.same_as_before) { if (stream_groups.same_as_before && !force_rerender) {
return; return;
} }
@ -307,9 +307,9 @@ function set_stream_unread_count(stream_id, count) {
exports.update_count_in_dom(unread_count_elem, count); exports.update_count_in_dom(unread_count_elem, count);
} }
exports.update_streams_sidebar = function () { exports.update_streams_sidebar = function (force_rerender) {
const finish = blueslip.start_timing("build_stream_list"); const finish = blueslip.start_timing("build_stream_list");
exports.build_stream_list(); exports.build_stream_list(force_rerender);
finish(); finish();
exports.stream_cursor.redraw(); exports.stream_cursor.redraw();
@ -332,7 +332,7 @@ exports.update_dom_with_unread_counts = function (counts) {
exports.rename_stream = function (sub) { exports.rename_stream = function (sub) {
// The sub object is expected to already have the updated name // The sub object is expected to already have the updated name
build_stream_sidebar_row(sub); build_stream_sidebar_row(sub);
exports.update_streams_sidebar(); // big hammer exports.update_streams_sidebar(true); // big hammer
}; };
exports.refresh_pinned_or_unpinned_stream = function (sub) { exports.refresh_pinned_or_unpinned_stream = function (sub) {