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.

buddy_list: Fix incorrect user count in the right sidebar.

arthurzenggbfde6909ccd5
diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts
index c17622b3b13..ddb08f3bb84 100644
--- a/web/src/buddy_list.ts
+++ b/web/src/buddy_list.ts
@@ -167,6 +167,8 @@ export class BuddyList extends BuddyListConf {
current_filter: Filter | undefined | "unset" = "unset";
initialize_tooltips(): void {
+ const non_participant_users_matching_view_count = (): number =>
+ this.non_participant_users_matching_view_count();
const total_human_subscribers_count = (): number =>
this.render_data.total_human_subscribers_count;
@@ -215,21 +217,15 @@ export class BuddyList extends BuddyListConf {
{N: participant_count},
);
} else if (elem_id === "buddy-list-users-matching-view-section-heading") {
- if (participant_count) {
+ const users_matching_view_count =
+ non_participant_users_matching_view_count();
+ if (narrow_state.stream_sub()) {
tooltip_text = $t(
{
defaultMessage:
"{N, plural, one {# other subscriber} other {# other subscribers}}",
},
- {N: total_human_subscribers_count() - participant_count},
- );
- } else if (narrow_state.stream_sub()) {
- tooltip_text = $t(
- {
- defaultMessage:
- "{N, plural, one {# subscriber} other {# subscribers}}",
- },
- {N: total_human_subscribers_count()},
+ {N: users_matching_view_count},
);
} else {
tooltip_text = $t(
@@ -237,7 +233,7 @@ export class BuddyList extends BuddyListConf {
defaultMessage:
"{N, plural, one {# participant} other {# participants}}",
},
- {N: total_human_subscribers_count()},
+ {N: users_matching_view_count},
);
}
} else {
@@ -262,15 +258,23 @@ export class BuddyList extends BuddyListConf {
);
}
- subscribed_participant_ids(): number[] {
- const {current_sub, pm_ids_set, get_all_participant_ids} = this.render_data;
+ non_participant_users_matching_view_count(): number {
+ const {current_sub, get_all_participant_ids} = this.render_data;
+ // We don't show "participants" for DMs, we just show the
+ // "in this narrow" section (i.e. everyone in the conversation).
+ // Confusingly, we do call this "participants" in the UI.
+ if (current_sub === undefined) {
+ return this.render_data.total_human_subscribers_count;
+ }
const participant_ids_list = [...get_all_participant_ids()];
- return participant_ids_list.filter((user_id) => {
- if (current_sub) {
- return peer_data.is_user_subscribed(current_sub.stream_id, user_id);
- }
- return pm_ids_set.has(user_id);
- });
+ const subscribed_human_participant_ids = participant_ids_list.filter(
+ (user_id) =>
+ peer_data.is_user_subscribed(current_sub.stream_id, user_id) &&
+ !people.is_valid_bot_user(user_id),
+ );
+ return (
+ this.render_data.total_human_subscribers_count - subscribed_human_participant_ids.length
+ );
}
populate(opts: {all_user_ids: number[]}): void {
@@ -377,8 +381,8 @@ export class BuddyList extends BuddyListConf {
return;
}
- const {get_all_participant_ids, total_human_subscribers_count} = this.render_data;
- if (total_human_subscribers_count - this.subscribed_participant_ids().length > 0) {
+ const {get_all_participant_ids} = this.render_data;
+ if (this.non_participant_users_matching_view_count() > 0) {
// There are more subscribers, so we don't need an empty list message.
$("#buddy-list-users-matching-view .empty-list-message").remove();
} else if (get_all_participant_ids().size > 0) {
@@ -397,13 +401,13 @@ export class BuddyList extends BuddyListConf {
}
update_section_header_counts(): void {
- const {total_human_subscribers_count, other_users_count} = this.render_data;
+ const {other_users_count} = this.render_data;
const all_participant_ids = this.render_data.get_all_participant_ids();
- const subscriber_section_user_count =
- total_human_subscribers_count - all_participant_ids.size;
const formatted_participants_count = get_formatted_user_count(all_participant_ids.size);
- const formatted_matching_users_count = get_formatted_user_count(subscriber_section_user_count);
+ const formatted_matching_users_count = get_formatted_user_count(
+ this.non_participant_users_matching_view_count(),
+ );
const formatted_other_users_count = get_formatted_user_count(other_users_count);
$("#buddy-list-participants-container .buddy-list-heading-user-count").text(
@@ -422,7 +426,7 @@ export class BuddyList extends BuddyListConf {
);
$("#buddy-list-users-matching-view-section-heading").attr(
"data-user-count",
- subscriber_section_user_count,
+ this.non_participant_users_matching_view_count(),
);
$("#buddy-list-users-other-users-section-heading").attr(
"data-user-count",
@@ -443,7 +447,7 @@ export class BuddyList extends BuddyListConf {
}
this.current_filter = narrow_state.filter();
- const {current_sub, total_human_subscribers_count, other_users_count} = this.render_data;
+ const {current_sub, other_users_count} = this.render_data;
$(".buddy-list-subsection-header").empty();
$(".buddy-list-subsection-header").toggleClass("no-display", hide_headers);
if (hide_headers) {
@@ -469,7 +473,7 @@ export class BuddyList extends BuddyListConf {
? $t({defaultMessage: "THIS CHANNEL"})
: $t({defaultMessage: "THIS CONVERSATION"}),
user_count: get_formatted_user_count(
- total_human_subscribers_count - all_participant_ids.size,
+ this.non_participant_users_matching_view_count(),
),
is_collapsed: this.users_matching_view_is_collapsed,
}),
@@ -639,10 +643,9 @@ export class BuddyList extends BuddyListConf {
}
render_view_user_list_links(): void {
- const {current_sub, total_human_subscribers_count, other_users_count} = this.render_data;
+ const {current_sub, other_users_count} = this.render_data;
const has_inactive_users_matching_view =
- total_human_subscribers_count >
- this.users_matching_view_ids.length + this.participant_user_ids.length;
+ this.non_participant_users_matching_view_count() > this.users_matching_view_ids.length;
const has_inactive_other_users = other_users_count > this.other_user_ids.length;
// For stream views, we show a link at the bottom of the list of subscribed users that