From 1563c85573cbe3605f114445dc46d0b04ca656da Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Sat, 17 Dec 2022 19:32:15 +0000 Subject: [PATCH] streams_list: Don't zoom out user when stream list rearranges. Fixes #23588 When a new message arrives in an inactive stream, it will lead to stream being marked as active from inactive which leads to stream list being rearranged which zooms out the user since the active stream is reset momentarily. To avoid this, we delay the stream list redraw until user zooms out and only update the topics list. --- static/js/stream_list.js | 12 ++++++++++++ static/js/topic_zoom.js | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 1e1dc01258..b0a183c254 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -409,6 +409,18 @@ function set_stream_unread_count(stream_id, count, stream_has_any_unread_mention } export function update_streams_sidebar(force_rerender) { + if (!force_rerender && topic_zoom.is_zoomed_in()) { + // We do our best to update topics that are displayed + // in case user zoomed in. Streams list will be updated, + // once the user zooms out. This avoids user being zoomed out + // when a new message causes streams to re-arrange. + const filter = narrow_state.filter(); + update_stream_sidebar_for_narrow(filter); + topic_zoom.set_pending_stream_list_rerender(true); + return; + } + topic_zoom.set_pending_stream_list_rerender(false); + build_stream_list(force_rerender); stream_cursor.redraw(); diff --git a/static/js/topic_zoom.js b/static/js/topic_zoom.js index 375dc48089..f87d333265 100644 --- a/static/js/topic_zoom.js +++ b/static/js/topic_zoom.js @@ -4,6 +4,7 @@ import * as popovers from "./popovers"; import * as stream_list from "./stream_list"; import * as topic_list from "./topic_list"; +let pending_stream_list_rerender = false; let zoomed_in = false; export function is_zoomed_in() { @@ -22,7 +23,14 @@ function zoom_in() { zoomed_in = true; } +export function set_pending_stream_list_rerender(value) { + pending_stream_list_rerender = value; +} + export function zoom_out() { + if (pending_stream_list_rerender) { + stream_list.update_streams_sidebar(true); + } const $stream_li = topic_list.get_stream_li(); popovers.hide_all_except_sidebars();