From 9577dc9da7d85a2d53f3648ccc3ae23f147ef7bb Mon Sep 17 00:00:00 2001 From: Evy Kassirer Date: Thu, 8 May 2025 11:51:12 +0200 Subject: [PATCH] typeahead_helper: Fetch full subscriber list while sorting. Work towards #34244. --- web/src/typeahead_helper.ts | 13 +++++++++++++ web/tests/composebox_typeahead.test.cjs | 3 +++ web/tests/typeahead_helper.test.cjs | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.ts index c05657b8bd..da55e01ba6 100644 --- a/web/src/typeahead_helper.ts +++ b/web/src/typeahead_helper.ts @@ -15,6 +15,7 @@ import type { TopicSuggestion, } from "./composebox_typeahead.ts"; import type {InputPillContainer} from "./input_pill.ts"; +import * as peer_data from "./peer_data.ts"; import * as people from "./people.ts"; import type {PseudoMentionUser, User} from "./people.ts"; import * as pm_conversations from "./pm_conversations.ts"; @@ -302,6 +303,18 @@ export function compare_people_for_relevance( // Now handle actual people users. // give preference to subscribed users first if (current_stream_id !== undefined) { + // Fetch subscriber data if we don't have it yet, but don't wait for it. + // It's fine to use partial data for now, and hopefully on subsequent + // keystrokes, we'll have the full data to show more subscribers at the + // top of the list. + // + // (We will usually have it, since entering a channel triggers a fetch.) + if (!peer_data.has_full_subscriber_data(current_stream_id)) { + void peer_data.maybe_fetch_stream_subscribers(current_stream_id); + } + + // If the client does not yet have complete subscriber data, + // "unknown" and "not subscribed" are both represented as false here. const a_is_sub = stream_data.is_user_subscribed(current_stream_id, person_a.user.user_id); const b_is_sub = stream_data.is_user_subscribed(current_stream_id, person_b.user.user_id); diff --git a/web/tests/composebox_typeahead.test.cjs b/web/tests/composebox_typeahead.test.cjs index 5a2d0ed84f..646824ac8f 100644 --- a/web/tests/composebox_typeahead.test.cjs +++ b/web/tests/composebox_typeahead.test.cjs @@ -34,6 +34,9 @@ const message_user_ids = mock_esm("../src/message_user_ids", { user_ids: () => [], }); const stream_topic_history_util = mock_esm("../src/stream_topic_history_util"); +mock_esm("../src/channel", { + get: () => ({subscribers: []}), +}); let set_timeout_called; set_global("setTimeout", (f, time) => { diff --git a/web/tests/typeahead_helper.test.cjs b/web/tests/typeahead_helper.test.cjs index ab12ebab54..3a31c34df1 100644 --- a/web/tests/typeahead_helper.test.cjs +++ b/web/tests/typeahead_helper.test.cjs @@ -2,7 +2,7 @@ const assert = require("node:assert/strict"); -const {zrequire} = require("./lib/namespace.cjs"); +const {mock_esm, zrequire} = require("./lib/namespace.cjs"); const {run_test} = require("./lib/test.cjs"); const settings_config = zrequire("settings_config"); @@ -24,6 +24,10 @@ const th = zrequire("typeahead_helper"); const user_groups = zrequire("user_groups"); const {initialize_user_settings} = zrequire("user_settings"); +mock_esm("../src/channel", { + get: () => ({subscribers: []}), +}); + const current_user = {}; set_current_user(current_user); const realm = {};