Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
buddy_list: Use `participants` data from current message list.
Aman Agrawaldf0d3b25c9b4
diff --git a/web/src/buddy_data.ts b/web/src/buddy_data.tsindex e0bea313371..25665663bb9 100644--- a/web/src/buddy_data.ts+++ b/web/src/buddy_data.ts@@ -1,8 +1,5 @@-import _ from "lodash";import assert from "minimalistic-assert";-import * as blueslip from "./blueslip.ts";-import {ConversationParticipants} from "./conversation_participants.ts";import * as hash_util from "./hash_util.ts";import {$t} from "./i18n.ts";import * as message_lists from "./message_lists.ts";@@ -452,32 +449,18 @@ function get_filtered_user_id_list(return filter_user_ids(user_filter_text, [...user_ids_set]);}-export function get_conversation_participants(): Set<number> {- const participant_ids_set = new Set<number>();- if (!narrow_state.stream_id() || !narrow_state.topic() || !message_lists.current) {- return participant_ids_set;- }- for (const message of message_lists.current.all_messages()) {- if (people.is_displayable_conversation_participant(message.sender_id)) {- participant_ids_set.add(message.sender_id);+export function get_conversation_participants_callback(): () => Set<number> {+ return () => {+ if (!narrow_state.stream_id() || !narrow_state.topic() || !message_lists.current) {+ return new Set<number>();}- }- const conversation_participants = new ConversationParticipants(- message_lists.current.all_messages(),- ).visible();- if (!_.isEqual(participant_ids_set, conversation_participants)) {- /* istanbul ignore next */- blueslip.error("Participants calculations disagree", {- participant_ids_set,- conversation_participants,- });- }- return participant_ids_set;+ return message_lists.current.data.participants.visible();+ };}export function get_filtered_and_sorted_user_ids(user_filter_text: string): number[] {let user_ids;- const conversation_participants = get_conversation_participants();+ const conversation_participants = get_conversation_participants_callback()();user_ids = get_filtered_user_id_list(user_filter_text, conversation_participants);user_ids = maybe_shrink_list(user_ids, user_filter_text, conversation_participants);return sort_users(user_ids, conversation_participants);diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.tsindex c93aa98dbf1..ec6e963107c 100644--- a/web/src/buddy_list.ts+++ b/web/src/buddy_list.ts@@ -78,7 +78,7 @@ type BuddyListRenderData = {total_human_subscribers_count: number;other_users_count: number;hide_headers: boolean;- all_participant_ids: Set<number>;+ get_all_participant_ids: () => Set<number>;};function get_render_data(): BuddyListRenderData {@@ -88,7 +88,7 @@ function get_render_data(): BuddyListRenderData {const total_human_subscribers_count = get_total_human_subscriber_count(current_sub, pm_ids_set);const other_users_count = people.get_active_human_count() - total_human_subscribers_count;const hide_headers = should_hide_headers(current_sub, pm_ids_set);- const all_participant_ids = buddy_data.get_conversation_participants();+ const get_all_participant_ids = buddy_data.get_conversation_participants_callback();return {current_sub,@@ -96,7 +96,7 @@ function get_render_data(): BuddyListRenderData {total_human_subscribers_count,other_users_count,hide_headers,- all_participant_ids,+ get_all_participant_ids,};}@@ -393,8 +393,8 @@ export class BuddyList extends BuddyListConf {}update_section_header_counts(): void {- const {total_human_subscribers_count, other_users_count, all_participant_ids} =- this.render_data;+ const {total_human_subscribers_count, 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;@@ -427,7 +427,8 @@ export class BuddyList extends BuddyListConf {}render_section_headers(): void {- const {hide_headers, all_participant_ids} = this.render_data;+ const {hide_headers} = this.render_data;+ const all_participant_ids = this.render_data.get_all_participant_ids();// 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@@ -549,9 +550,10 @@ export class BuddyList extends BuddyListConf {const other_users = [];const current_sub = this.render_data.current_sub;const pm_ids_set = narrow_state.pm_ids_set();+ const all_participant_ids = this.render_data.get_all_participant_ids();for (const item of items) {- if (this.render_data.all_participant_ids.has(item.user_id)) {+ if (all_participant_ids.has(item.user_id)) {participants.push(item);this.participant_user_ids.push(item.user_id);} else if (@@ -612,12 +614,13 @@ export class BuddyList extends BuddyListConf {}display_or_hide_sections(): void {- const {all_participant_ids, hide_headers, total_human_subscribers_count} = this.render_data;+ const {get_all_participant_ids, hide_headers, total_human_subscribers_count} =+ this.render_data;// If we're in the mode of hiding headers, that means we're only showing the "others"// section, so hide the other two sections.$("#buddy-list-users-matching-view-container").toggleClass("no-display", hide_headers);- const hide_participants_list = hide_headers || all_participant_ids.size === 0;+ const hide_participants_list = hide_headers || get_all_participant_ids().size === 0;$("#buddy-list-participants-container").toggleClass("no-display", hide_participants_list);// This is the case where every subscriber is in the participants list. In this case, we@@ -835,7 +838,7 @@ export class BuddyList extends BuddyListConf {list_user_id,current_sub,pm_ids_set,- this.render_data.all_participant_ids,+ this.render_data.get_all_participant_ids(),) < 0,);return i === -1 ? user_id_list.length : i;@@ -932,7 +935,7 @@ export class BuddyList extends BuddyListConf {// TODO: Further optimize this function by clubbing DOM updates from// multiple insertions/movements into a single update.- const all_participant_ids = this.render_data.all_participant_ids;+ const all_participant_ids = this.render_data.get_all_participant_ids();const users = buddy_data.get_items_for_users(user_ids);for (const user of users) {const user_id = user.user_id;diff --git a/web/tests/buddy_data.test.cjs b/web/tests/buddy_data.test.cjsindex b7f4455e121..f5a8c4dbc71 100644--- a/web/tests/buddy_data.test.cjs+++ b/web/tests/buddy_data.test.cjs@@ -427,23 +427,18 @@ test("get_conversation_participants", ({override_rewire}) => {message_lists.set_current({data: {filter,- },- all_messages() {- return [- {- sender_id: selma.user_id,- id: rome_sub.stream_id,- content: "example content",- topic: "Foo",- type: "stream",- },- ];+ participants: {+ visible: () => new Set([selma.user_id]),+ },},});override_rewire(narrow_state, "stream_id", () => rome_sub.stream_id);override_rewire(narrow_state, "topic", () => "Foo");- assert.deepEqual(buddy_data.get_conversation_participants(), new Set([selma.user_id]));+ assert.deepEqual(+ buddy_data.get_conversation_participants_callback()(),+ new Set([selma.user_id]),+ );});test("level", ({override}) => {diff --git a/web/tests/conversation_participants.test.cjs b/web/tests/conversation_participants.test.cjsindex 0f6cb8ad24c..41eed967bd4 100644--- a/web/tests/conversation_participants.test.cjs+++ b/web/tests/conversation_participants.test.cjs@@ -53,4 +53,10 @@ run_test("Add participants", () => {const participants = new ConversationParticipants(all_messages);assert.ok(_.isEqual(participants.humans, new Set([user1.user_id, user2.user_id])));assert.ok(_.isEqual(participants.bots, new Set([bot1.user_id, bot2.user_id])));+ // None since they were not added as active users.+ assert.equal(participants.visible().size, 0);++ // Add user1 as active user.+ people.add_active_user(user1);+ assert.ok(_.isEqual(participants.visible(), new Set([user1.user_id])));});