diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js index f3f3295be6..b1c392e8af 100644 --- a/frontend_tests/node_tests/stream_list.js +++ b/frontend_tests/node_tests/stream_list.js @@ -239,9 +239,11 @@ function initialize_stream_data() { }); topic_list.set_click_handlers = noop; - topic_list.is_zoomed = return_false; + topic_list.close = noop; topic_list.remove_expanded_topics = noop; topic_list.rebuild = noop; + topic_list.active_stream_id = noop; + stream_list.show_all_streams = noop; stream_list.scroll_element_into_container = noop; var scrollbar_updated = false; diff --git a/static/js/stream_list.js b/static/js/stream_list.js index 9a12cc4de2..c795869fe6 100644 --- a/static/js/stream_list.js +++ b/static/js/stream_list.js @@ -180,7 +180,7 @@ function zoom_in() { function zoom_out(options) { popovers.hide_all(); - topic_list.zoom_out(options); + topic_list.zoom_out(); if (options.stream_li) { exports.scroll_stream_into_view(options.stream_li); @@ -201,14 +201,6 @@ exports.show_all_streams = function () { $("#stream_filters li.narrow-filter").show(); }; -function reset_to_unnarrowed(narrowed_within_same_stream) { - if (topic_list.is_zoomed() && narrowed_within_same_stream !== true) { - zoom_out({clear_topics: true}); - } else { - topic_list.remove_expanded_topics(); - } -} - exports.set_in_home_view = function (stream_id, in_home) { var li = exports.get_stream_li(stream_id); if (!li) { @@ -317,7 +309,7 @@ exports.update_streams_sidebar = function () { var filter = narrow_state.filter(); - exports.maybe_activate_stream_item(filter); + exports.update_stream_sidebar_for_narrow(filter); }; exports.update_dom_with_unread_counts = function (counts) { @@ -379,6 +371,11 @@ exports.refresh_pinned_or_unpinned_stream = function (sub) { } }; +function clear_topics() { + topic_list.close(); + exports.show_all_streams(); +} + exports.get_sidebar_stream_topic_info = function (filter) { var result = { stream_id: undefined, @@ -409,12 +406,13 @@ exports.get_sidebar_stream_topic_info = function (filter) { return result; }; -exports.maybe_activate_stream_item = function (filter) { +exports.update_stream_sidebar_for_narrow = function (filter) { var info = exports.get_sidebar_stream_topic_info(filter); var stream_id = info.stream_id; if (!stream_id) { + clear_topics(); return; } @@ -427,6 +425,7 @@ exports.maybe_activate_stream_item = function (filter) { // evidence that this assumption breaks down for some users, // but we are not clear why it happens. blueslip.error('No stream_li for subscribed stream ' + stream_id); + clear_topics(); return; } @@ -434,6 +433,10 @@ exports.maybe_activate_stream_item = function (filter) { stream_li.addClass('active-filter'); } + if (stream_id !== topic_list.active_stream_id()) { + clear_topics(); + } + topic_list.rebuild(stream_li, stream_id); return stream_li; @@ -489,9 +492,7 @@ exports.initialize = function () { $(document).on('narrow_activated.zulip', function (event) { exports.update_top_left_corner_for_narrow(event.filter); - reset_to_unnarrowed(narrow_state.stream() === zoomed_stream); - - var stream_li = exports.maybe_activate_stream_item(event.filter); + var stream_li = exports.update_stream_sidebar_for_narrow(event.filter); if (stream_li) { exports.scroll_stream_into_view(stream_li); } @@ -501,7 +502,7 @@ exports.initialize = function () { $(document).on('narrow_deactivated.zulip', function () { deselect_top_left_corner_items(); - reset_to_unnarrowed(); + clear_topics(); pm_list.close(); var filter_li = exports.get_global_filter_li('home'); diff --git a/static/js/topic_list.js b/static/js/topic_list.js index 131e2861a4..bc72d3c8be 100644 --- a/static/js/topic_list.js +++ b/static/js/topic_list.js @@ -13,9 +13,20 @@ exports.remove_expanded_topics = function () { if (active_widget) { active_widget.remove(); + active_widget = undefined; } }; +exports.close = function () { + zoomed = false; + exports.remove_expanded_topics(); +}; + +exports.zoom_out = function () { + zoomed = false; + exports.rebuild(active_widget.get_parent(), active_widget.get_stream_id()); +}; + function update_unread_count(unread_count_elem, count) { // unread_count_elem is a jquery element...we expect DOM // to look like this: @@ -198,19 +209,6 @@ exports.zoom_in = function () { } }; -exports.zoom_out = function (options) { - zoomed = false; - if (options && options.clear_topics) { - exports.remove_expanded_topics(); - } else { - exports.rebuild(active_widget.get_parent(), active_widget.get_stream_id()); - } -}; - -exports.is_zoomed = function () { - return zoomed; -}; - exports.set_click_handlers = function (callbacks) { $('#stream_filters').on('click', '.show-more-topics', function (e) { callbacks.zoom_in(); @@ -221,7 +219,6 @@ exports.set_click_handlers = function (callbacks) { $('.show-all-streams').on('click', function (e) { callbacks.zoom_out({ - clear_topics: false, stream_li: active_widget.get_parent(), });