From 2367c46455110edbd555a3c7c0e0dd845dbd5e57 Mon Sep 17 00:00:00 2001 From: evykassirer Date: Thu, 10 Oct 2024 17:56:06 -0700 Subject: [PATCH] buddy_list: Fix bug where headers weren't being updated often enough. `$(".buddy-list-subsection-header").children()` has length more often than I had thought. Using the narrow filter is more direct way of managing this state. --- web/src/buddy_list.ts | 14 +++++++++++--- web/tests/lib/buddy_list.js | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts index d235be53cd..15c8ce6f64 100644 --- a/web/src/buddy_list.ts +++ b/web/src/buddy_list.ts @@ -13,6 +13,7 @@ import * as blueslip from "./blueslip"; import * as buddy_data from "./buddy_data"; import type {BuddyUserInfo} from "./buddy_data"; import {media_breakpoints_num} from "./css_variables"; +import type {Filter} from "./filter"; import * as hash_util from "./hash_util"; import {$t} from "./i18n"; import * as message_viewport from "./message_viewport"; @@ -166,6 +167,7 @@ export class BuddyList extends BuddyListConf { $participants_list = $(this.participants_list_selector); $users_matching_view_list = $(this.matching_view_list_selector); $other_users_list = $(this.other_user_list_selector); + current_filter: Filter | undefined; initialize_tooltips(): void { $("#right-sidebar").on( @@ -390,14 +392,20 @@ export class BuddyList extends BuddyListConf { render_section_headers(): void { const {hide_headers, participant_ids_set} = this.render_data; - // We only show the participants list if it has members, so updating even if we're updating - // the count, that can affect if we show/hide this section. + // We only show the participants list if it has members, so even if we're not + // changing filters and only updating user counts for the current filter, that + // can affect if we show/hide this section. const show_participants_list = !hide_headers && participant_ids_set.size; $("#buddy-list-participants-container").toggleClass("no-display", !show_participants_list); - if ($(".buddy-list-subsection-header").children().length) { + + // If we're not changing filters, this just means some users were added or + // removed but otherwise everything is the same, so we don't need to do a full + // rerender. + if (this.current_filter === narrow_state.filter()) { this.update_section_header_counts(); return; } + this.current_filter = narrow_state.filter(); const {current_sub, total_human_subscribers_count, other_users_count, total_human_users} = this.render_data; diff --git a/web/tests/lib/buddy_list.js b/web/tests/lib/buddy_list.js index 492994587e..a4c6319535 100644 --- a/web/tests/lib/buddy_list.js +++ b/web/tests/lib/buddy_list.js @@ -44,5 +44,4 @@ exports.stub_buddy_list_elements = () => { $("#buddy-list-other-users-container .view-all-users-link").length = 0; $("#buddy-list-users-matching-view-container .view-all-subscribers-link").remove = noop; $("#buddy-list-other-users-container .view-all-users-link").remove = noop; - $(".buddy-list-subsection-header").children = () => []; };