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_events: Fetch messages when stream subscription is confirmed.

Aadithya-J9318ad47d752
diff --git a/web/src/stream_events.ts b/web/src/stream_events.ts
index 9129b959903..ee0b71f3544 100644
--- a/web/src/stream_events.ts
+++ b/web/src/stream_events.ts
@@ -316,19 +316,32 @@ export function mark_subscribed(
}
}
+ // We may trigger narrow-refreshing UI code paths below (e.g. via
+ // `message_view.show`) that expect the newly subscribed stream to already
+ // exist in the left sidebar.
+ stream_list.add_sidebar_row(sub);
+ stream_list.update_subscribe_to_more_streams_link();
+ user_profile.update_user_profile_streams_list_for_users([people.my_current_user_id()]);
+
if (narrow_state.narrowed_to_stream_id(sub.stream_id)) {
assert(message_lists.current !== undefined);
message_lists.current.update_trailing_bookend(true);
+ const then_select_id =
+ typeof message_lists.current.selected_id === "function"
+ ? message_lists.current.selected_id()
+ : undefined;
+ message_view.show(message_lists.current.data.filter.terms(), {
+ then_select_id,
+ then_select_offset: browser_history.current_scroll_offset(),
+ force_rerender: true,
+ trigger: "subscription confirmed refresh",
+ });
activity_ui.build_user_sidebar();
}
// The new stream in sidebar might need its unread counts
// re-calculated.
unread_ui.update_unread_counts();
-
- stream_list.add_sidebar_row(sub);
- stream_list.update_subscribe_to_more_streams_link();
- user_profile.update_user_profile_streams_list_for_users([people.my_current_user_id()]);
}
export function mark_unsubscribed(sub: StreamSubscription): void {
diff --git a/web/tests/stream_events.test.cjs b/web/tests/stream_events.test.cjs
index 32c7665ce8b..c67f002776a 100644
--- a/web/tests/stream_events.test.cjs
+++ b/web/tests/stream_events.test.cjs
@@ -15,6 +15,7 @@ const color_data = mock_esm("../src/color_data");
const compose_recipient = mock_esm("../src/compose_recipient");
const dialog_widget = mock_esm("../src/dialog_widget");
const message_live_update = mock_esm("../src/message_live_update");
+const message_view = mock_esm("../src/message_view");
const settings_streams = mock_esm("../src/settings_streams");
const stream_color_events = mock_esm("../src/stream_color_events");
const stream_list = mock_esm("../src/stream_list");
@@ -112,6 +113,7 @@ function narrow_to_frontend() {
data: {
filter,
},
+ update_trailing_bookend: noop,
};
}
@@ -477,10 +479,15 @@ test("marked_subscribed (normal)", ({override}) => {
let list_updated = false;
+ const then_select_offset = 17;
+ override(browser_history, "current_scroll_offset", () => then_select_offset);
+
const stream_list_stub = make_stub();
const message_view_header_stub = make_stub();
+ const show_stub = make_stub();
+
+ let sidebar_row_added = false;
- override(stream_list, "add_sidebar_row", stream_list_stub.f);
override(stream_list, "update_subscribe_to_more_streams_link", noop);
override(unread_ui, "update_unread_counts", noop);
override(
@@ -491,6 +498,14 @@ test("marked_subscribed (normal)", ({override}) => {
override(message_lists.current, "update_trailing_bookend", () => {
list_updated = true;
});
+ override(stream_list, "add_sidebar_row", (sub) => {
+ sidebar_row_added = true;
+ stream_list_stub.f(sub);
+ });
+ override(message_view, "show", (terms, opts) => {
+ assert.equal(sidebar_row_added, true);
+ show_stub.f(terms, opts);
+ });
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -502,6 +517,12 @@ test("marked_subscribed (normal)", ({override}) => {
assert.equal(message_view_header_stub.num_calls, 1);
assert.equal(list_updated, true);
+ assert.equal(show_stub.num_calls, 1);
+ const show_args = show_stub.get_args("terms", "opts");
+ assert.equal(show_args.terms, message_lists.current.data.filter.terms());
+ assert.equal(show_args.opts.then_select_offset, then_select_offset);
+ assert.equal(show_args.opts.force_rerender, true);
+ assert.equal(show_args.opts.trigger, "subscription confirmed refresh");
assert.equal(sub.color, "blue");
message_lists.current = undefined;