Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
user_profile: Handle & update user subscribe widget from channel tab.
Evy Kassirer67b6b53b29de
diff --git a/web/src/user_profile.ts b/web/src/user_profile.tsindex f42e9427a28..0b37fcc26f4 100644--- a/web/src/user_profile.ts+++ b/web/src/user_profile.ts@@ -127,6 +127,8 @@ export function update_user_profile_streams_list_for_users(user_ids: number[]):const user_streams = stream_data.get_streams_for_user(user_id).subscribed;user_streams.sort(compare_by_name);user_streams_list_widget.replace_list_data(user_streams);+ const user = people.get_by_user_id(user_id);+ render_or_update_user_streams_tab(user);}}@@ -327,6 +329,37 @@ function format_user_group_list_item_html(group: UserGroup, user: User): string});}+function render_or_update_user_streams_tab(user: User): void {+ if (!user_streams_list_widget) {+ const user_streams = stream_data.get_streams_for_user(user.user_id).subscribed;+ render_user_stream_list(user_streams, user);+ }+ // We only show the subscribe widget if the user is an admin, the user has opened+ // their own profile, or if the user profile belongs to a bot whose owner has opened+ // the user profile. However, we don't want to show the subscribe widget for generic+ // bots since they are system bots and for deactivated users. Therefore, we also check+ // for that condition.+ // We also don't show the widget if there are no channels the user is currently+ // unsubscribed from and could become subscribed to (i.e. nothing to show in the widget).+ const user_unsub_streams = get_user_unsub_streams(user.user_id);+ const show_user_subscribe_widget =+ (people.can_admin_user(user) || current_user.is_admin) &&+ user_unsub_streams.length > 0 &&+ !user.is_system_bot &&+ people.is_person_active(user.user_id);++ if (show_user_subscribe_widget && user_profile_subscribe_widget === undefined) {+ reset_subscribe_widget();+ render_user_profile_subscribe_widget();+ }++ if (show_user_subscribe_widget) {+ $("#user-profile-streams-tab .stream-list-bottom-section").show();+ } else {+ $("#user-profile-streams-tab .stream-list-bottom-section").hide();+ }+}+function render_user_stream_list(streams: StreamSubscription[], user: User): void {streams.sort(compare_by_name);const $container = $("#user-profile-modal .user-stream-list");@@ -633,15 +666,7 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):original_values = {user_id: user.user_id.toString(),};- const user_unsub_streams = get_user_unsub_streams(user.user_id);- // We only show the subscribe widget if the user is an admin, the user has opened their own profile,- // or if the user profile belongs to a bot whose owner has opened the user profile. However, we don't- // want to show the subscribe widget for generic bots since they are system bots and for deactivated users.- // Therefore, we also check for that condition.- const show_user_subscribe_widget =- (people.can_admin_user(user) || user_unsub_streams.length > 0) &&- !user.is_system_bot &&- people.is_person_active(user.user_id);+// We currently have the main UI for editing your own profile in// settings for non-admins, so can_manage_profile is artificially// false for those.@@ -662,7 +687,6 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):last_seen: buddy_data.user_last_seen_time_status(user.user_id),profile_data,should_add_guest_user_indicator: people.should_add_guest_user_indicator(user.user_id),- show_user_subscribe_widget,user_avatar: people.medium_avatar_url_for_person(user),user_circle_class: buddy_data.get_user_circle_class(user.user_id),user_id: user.user_id,@@ -725,15 +749,7 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):break;}case "user-profile-streams-tab": {- if (!user_streams_list_widget) {- const user_streams = stream_data.get_streams_for_user(- user.user_id,- ).subscribed;- if (show_user_subscribe_widget) {- render_user_profile_subscribe_widget();- }- render_user_stream_list(user_streams, user);- }+ render_or_update_user_streams_tab(user);break;}case "manage-profile-tab":@@ -768,9 +784,6 @@ export function show_user_profile(user: User, default_tab_key = "profile-tab"):setTimeout(() => {$(".ind-tab.selected").trigger("focus");}, 0);- if (show_user_subscribe_widget) {- reset_subscribe_widget();- }}function handle_remove_stream_subscription(diff --git a/web/templates/user_profile_modal.hbs b/web/templates/user_profile_modal.hbsindex a20a16a04bc..8018f78b445 100644--- a/web/templates/user_profile_modal.hbs+++ b/web/templates/user_profile_modal.hbs@@ -127,14 +127,12 @@</div></div></div>- {{#if show_user_subscribe_widget}}- <div class="stream-list-bottom-section">- <div class="header-section">- <h3 class="stream-tab-element-header">{{t 'Subscribe {full_name} to channels'}}</h3>- </div>- {{> user_profile_subscribe_widget}}+ <div class="stream-list-bottom-section">+ <div class="header-section">+ <h3 class="stream-tab-element-header">{{t 'Subscribe {full_name} to channels'}}</h3></div>- {{/if}}+ {{> user_profile_subscribe_widget}}+ </div></div><div class="tabcontent" id="user-profile-groups-tab">