Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream_list: Make `$stream_li` an optional parameter.

Aman Agrawalf600f0e74d2f
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index c1e3caa4620..1a599b1c952 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -88,30 +88,20 @@ export function zoom_out(): void {
if (pending_stream_list_rerender) {
update_streams_sidebar(true);
}
- const $stream_li = topic_list.get_stream_li();
-
popovers.hide_all();
topic_list.zoom_out();
zoom_out_topics();
-
- if ($stream_li) {
- scroll_stream_into_view($stream_li);
- }
+ scroll_stream_into_view();
zoomed_in = false;
}
export function clear_topics(): void {
- const $stream_li = topic_list.get_stream_li();
-
topic_list.close();
if (zoomed_in) {
zoom_out_topics();
-
- if ($stream_li) {
- scroll_stream_into_view($stream_li);
- }
+ scroll_stream_into_view();
}
zoomed_in = false;
@@ -1012,16 +1002,15 @@ export function refresh_pinned_or_unpinned_stream(sub: StreamSubscription): void
maybe_hide_topic_bracket(section_id);
}
- // Only scroll pinned topics into view. If we're unpinning
+ // Only scroll pinned topics into view. If we're unpinning
// a topic, we may be literally trying to get it out of
// our sight.
if (sub.pin_to_top) {
- const $stream_li = get_stream_li(sub.stream_id);
- if (!$stream_li) {
+ if (!stream_sidebar.get_row(sub.stream_id)) {
blueslip.error("passed in bad stream id", {stream_id: sub.stream_id});
return;
}
- scroll_stream_into_view($stream_li);
+ scroll_stream_into_view();
}
}
@@ -1464,7 +1453,14 @@ export function clear_search(): void {
$filter.trigger("blur");
}
-export let scroll_stream_into_view = function ($stream_li: JQuery): void {
+export let scroll_stream_into_view = function ($stream_li: JQuery | undefined = undefined): void {
+ if ($stream_li === undefined) {
+ $stream_li = get_current_stream_li();
+ if ($stream_li === undefined) {
+ return;
+ }
+ }
+
const $container = $("#left_sidebar_scroll_container");
if ($stream_li.length !== 1) {
@@ -1496,10 +1492,7 @@ export function maybe_scroll_narrow_into_view(first_messages_fetch_done: boolean
return;
}
- const $stream_li = get_current_stream_li();
- if ($stream_li) {
- scroll_stream_into_view($stream_li);
- }
+ scroll_stream_into_view();
}
export function get_current_stream_li(): JQuery | undefined {
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index 5ec5cb07e31..b6830a70198 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -660,7 +660,7 @@ test_ui("rename_stream", ({mock_template, override, override_rewire}) => {
develSub.name = "devel"; // Resets
});
-test_ui("refresh_pin", ({override_rewire, mock_template}) => {
+test_ui("refresh_pin", ({override_rewire}) => {
override_rewire(stream_list, "update_stream_section_mention_indicators", noop);
override_rewire(stream_list, "update_dom_with_unread_counts", noop);
override_rewire(stream_list, "maybe_hide_topic_bracket", noop);
@@ -687,19 +687,14 @@ test_ui("refresh_pin", ({override_rewire, mock_template}) => {
pin_to_top: true,
};
- const $li_stub = $.create("li stub");
- $li_stub.length = 1;
-
- mock_template("stream_sidebar_row.hbs", false, () => ({to_$: () => $li_stub}));
-
override_rewire(stream_list, "update_count_in_dom", noop);
$("#stream_filters").append = noop;
let scrolled;
- override_rewire(stream_list, "scroll_stream_into_view", ($li) => {
- if ($li === $li_stub) {
- scrolled = true;
- }
+ override_rewire(stream_list, "scroll_stream_into_view", () => {
+ // We already passed the test of `stream_sidebar.get_row` to
+ // reach this point.
+ scrolled = true;
});
stream_list.refresh_pinned_or_unpinned_stream(pinned_sub);