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.

user_profile: Update the streams list dynamically.

palashb01485d307b649d
diff --git a/web/src/server_events_dispatch.js b/web/src/server_events_dispatch.js
index 214207db367..5204081a486 100644
--- a/web/src/server_events_dispatch.js
+++ b/web/src/server_events_dispatch.js
@@ -589,7 +589,7 @@ export function dispatch_normal_event(event) {
const user_ids = people.validate_user_ids(event.user_ids);
peer_data.bulk_add_subscribers({stream_ids, user_ids});
- stream_events.process_subscriber_update(stream_ids);
+ stream_events.process_subscriber_update(user_ids, stream_ids);
break;
}
case "peer_remove": {
@@ -597,7 +597,7 @@ export function dispatch_normal_event(event) {
const user_ids = people.validate_user_ids(event.user_ids);
peer_data.bulk_remove_subscribers({stream_ids, user_ids});
- stream_events.process_subscriber_update(stream_ids);
+ stream_events.process_subscriber_update(user_ids, stream_ids);
break;
}
case "remove":
diff --git a/web/src/stream_events.js b/web/src/stream_events.js
index a72e7d99dc9..b08341b06fc 100644
--- a/web/src/stream_events.js
+++ b/web/src/stream_events.js
@@ -9,6 +9,7 @@ import * as message_view_header from "./message_view_header";
import * as narrow_state from "./narrow_state";
import * as overlays from "./overlays";
import * as peer_data from "./peer_data";
+import * as people from "./people";
import * as recent_topics_ui from "./recent_topics_ui";
import * as settings_notifications from "./settings_notifications";
import * as stream_color from "./stream_color";
@@ -18,6 +19,7 @@ import * as stream_muting from "./stream_muting";
import * as stream_settings_ui from "./stream_settings_ui";
import * as sub_store from "./sub_store";
import * as unread_ui from "./unread_ui";
+import * as user_profile from "./user_profile";
// In theory, this function should apply the account-level defaults,
// however, they are only called after a manual override, so
@@ -152,6 +154,7 @@ export function mark_subscribed(sub, subscribers, color) {
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) {
@@ -186,6 +189,7 @@ export function mark_unsubscribed(sub) {
stream_list.remove_sidebar_row(sub.stream_id);
stream_list.update_subscribe_to_more_streams_link();
+ user_profile.update_user_profile_streams_list_for_users([people.my_current_user_id()]);
}
export function remove_deactivated_user_from_all_streams(user_id) {
@@ -199,10 +203,11 @@ export function remove_deactivated_user_from_all_streams(user_id) {
}
}
-export function process_subscriber_update(stream_ids) {
+export function process_subscriber_update(user_ids, stream_ids) {
for (const stream_id of stream_ids) {
const sub = sub_store.get(stream_id);
stream_settings_ui.update_subscribers_ui(sub);
}
compose_fade.update_faded_users();
+ user_profile.update_user_profile_streams_list_for_users(user_ids);
}
diff --git a/web/src/user_profile.js b/web/src/user_profile.js
index 180e7d73942..726d3c188a6 100644
--- a/web/src/user_profile.js
+++ b/web/src/user_profile.js
@@ -28,6 +28,8 @@ import * as user_groups from "./user_groups";
import * as user_pill from "./user_pill";
import * as util from "./util";
+let user_streams_list_widget;
+
function compare_by_name(a, b) {
return util.strcmp(a.name, b.name);
}
@@ -40,6 +42,14 @@ export function get_user_id_if_user_profile_modal_open() {
return undefined;
}
+export function update_user_profile_streams_list_for_users(user_ids) {
+ const user_id = get_user_id_if_user_profile_modal_open();
+ if (user_id && user_ids.includes(user_id) && user_streams_list_widget !== undefined) {
+ const user_streams = stream_data.get_streams_for_user(user_id).subscribed;
+ user_streams_list_widget.replace_list_data(user_streams);
+ }
+}
+
function initialize_bot_owner(element_id, bot_id) {
const user_pills = new Map();
const bot = people.get_by_user_id(bot_id);
@@ -89,7 +99,7 @@ function render_user_stream_list(streams, user) {
streams.sort(compare_by_name);
const $container = $("#user-profile-modal .user-stream-list");
$container.empty();
- ListWidget.create($container, streams, {
+ user_streams_list_widget = ListWidget.create($container, streams, {
name: `user-${user.user_id}-stream-list`,
get_item: ListWidget.default_get_item,
modifier(item) {
@@ -172,6 +182,7 @@ export function get_custom_profile_field_data(user, field, field_types) {
}
export function hide_user_profile() {
+ user_streams_list_widget = undefined;
overlays.close_modal_if_open("user-profile-modal");
}
diff --git a/web/tests/stream_events.test.js b/web/tests/stream_events.test.js
index 3e2e1bc2082..acd8f173cc7 100644
--- a/web/tests/stream_events.test.js
+++ b/web/tests/stream_events.test.js
@@ -33,7 +33,9 @@ mock_esm("../src/settings_notifications", {
update_page() {},
});
-mock_esm("../src/overlays", {streams_open: () => true});
+mock_esm("../src/overlays", {
+ streams_open: () => true,
+});
const {Filter} = zrequire("../src/filter");
const narrow_state = zrequire("narrow_state");
@@ -43,6 +45,7 @@ const stream_data = zrequire("stream_data");
const stream_events = zrequire("stream_events");
const compose_recipient = zrequire("compose_recipient");
const compose_fade = zrequire("compose_fade");
+const user_profile = mock_esm("../src/user_profile");
const george = {
@@ -304,6 +307,7 @@ test("marked_subscribed (normal)", ({override}) => {
override(message_lists.current, "update_trailing_bookend", () => {
list_updated = true;
});
+ override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -334,6 +338,7 @@ test("marked_subscribed (color)", ({override}) => {
stream_data.add_sub(sub);
override(color_data, "pick_color", () => "green");
+ override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -364,6 +369,7 @@ test("marked_subscribed (emails)", ({override}) => {
const subs_stub = make_stub();
override(stream_settings_ui, "update_settings_for_subscribed", subs_stub.f);
+ override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -390,6 +396,7 @@ test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override}) => {
override(stream_list, "remove_sidebar_row", noop);
override(stream_list, "update_subscribe_to_more_streams_link", noop);
override(unread_ui, "update_unread_counts", noop);
+ override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -416,6 +423,7 @@ test("mark_unsubscribed (render_title_area)", ({override}) => {
override(stream_list, "update_subscribe_to_more_streams_link", noop);
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);
$("#streams_overlay_container .stream-row:not(.notdisplayed)").length = 0;
@@ -444,18 +452,21 @@ test("remove_deactivated_user_from_all_streams", () => {
assert.equal(subs_stub.num_calls, 1);
});
-test("process_subscriber_update", () => {
+test("process_subscriber_update", ({override}) => {
const subsStub = make_stub();
stream_settings_ui.update_subscribers_ui = subsStub.f;
const fadedUsersStub = make_stub();
compose_fade.update_faded_users = fadedUsersStub.f;
+ override(user_profile, "update_user_profile_streams_list_for_users", noop);
+ // Sample user IDs
+ const userIds = [104, 2, 3];
// Sample stream IDs
const streamIds = [1, 2, 3];
// Call the function being tested
- stream_events.process_subscriber_update(streamIds);
+ stream_events.process_subscriber_update(userIds, streamIds);
// Assert that update_subscribers_ui is called for each stream ID
assert.equal(subsStub.num_calls, streamIds.length);