stream events: Rebuild buddy list when user is subscribed or unsubscribed.

This commit is contained in:
evykassirer 2023-11-16 16:32:35 -08:00 committed by Tim Abbott
parent 5434130171
commit be033394b1
2 changed files with 25 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import $ from "jquery";
import * as activity_ui from "./activity_ui";
import * as blueslip from "./blueslip";
import * as color_data from "./color_data";
import * as compose_recipient from "./compose_recipient";
@ -146,6 +147,7 @@ export function mark_subscribed(sub, subscribers, color) {
if (narrow_state.is_for_stream_id(sub.stream_id)) {
message_lists.current.update_trailing_bookend();
activity_ui.build_user_sidebar();
}
// The new stream in sidebar might need its unread counts
@ -181,6 +183,8 @@ export function mark_unsubscribed(sub) {
// This update would likely be better implemented by having it
// disappear whenever no unread messages remain.
unread_ui.hide_unread_banner();
activity_ui.build_user_sidebar();
}
// Unread messages in the now-unsubscribe stream need to be
@ -209,4 +213,7 @@ export function process_subscriber_update(user_ids, stream_ids) {
stream_settings_ui.update_subscribers_ui(sub);
}
user_profile.update_user_profile_streams_list_for_users(user_ids);
if (stream_ids.includes(narrow_state.stream_id())) {
activity_ui.build_user_sidebar();
}
}

View File

@ -36,6 +36,8 @@ mock_esm("../src/overlays", {
const user_profile = mock_esm("../src/user_profile");
const {Filter} = zrequire("../src/filter");
const activity_ui = zrequire("activity_ui");
const {buddy_list} = zrequire("buddy_list");
const narrow_state = zrequire("narrow_state");
const peer_data = zrequire("peer_data");
const people = zrequire("people");
@ -285,6 +287,8 @@ test("marked_subscribed (normal)", ({override}) => {
const sub = {...frontend};
stream_data.add_sub(sub);
override(stream_color_events, "update_stream_color", noop);
override(buddy_list, "populate", noop);
activity_ui.set_cursor_and_filter();
narrow_to_frontend();
@ -421,6 +425,7 @@ test("mark_unsubscribed (render_title_area)", ({override}) => {
override(unread_ui, "update_unread_counts", noop);
override(unread_ui, "hide_unread_banner", noop);
override(user_profile, "update_user_profile_streams_list_for_users", noop);
override(buddy_list, "populate", noop);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@ -449,10 +454,14 @@ test("remove_deactivated_user_from_all_streams", () => {
assert.equal(subs_stub.num_calls, 1);
});
test("process_subscriber_update", ({override}) => {
test("process_subscriber_update", ({override, override_rewire}) => {
const subsStub = make_stub();
stream_settings_ui.update_subscribers_ui = subsStub.f;
let build_user_sidebar_called = false;
override_rewire(activity_ui, "build_user_sidebar", () => {
build_user_sidebar_called = true;
});
override(user_profile, "update_user_profile_streams_list_for_users", noop);
// Sample user IDs
const userIds = [104, 2, 3];
@ -464,4 +473,12 @@ test("process_subscriber_update", ({override}) => {
// Assert that update_subscribers_ui is called for each stream ID
assert.equal(subsStub.num_calls, streamIds.length);
assert.ok(!build_user_sidebar_called);
// For a stream the user is currently viewing, we rebuild the user sidebar
// when someone subscribes to that stream.
override_rewire(narrow_state, "stream_id", () => 1);
stream_events.process_subscriber_update(userIds, streamIds);
assert.ok(build_user_sidebar_called);
});