Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typeahead_helper: Fetch full subscriber list while sorting.
Evy Kassirer9577dc9da7d8
diff --git a/web/src/typeahead_helper.ts b/web/src/typeahead_helper.tsindex c05657b8bdf..da55e01ba6d 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 firstif (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.cjsindex 5a2d0ed84f3..646824ac8fe 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.cjsindex ab12ebab544..3a31c34df1e 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 = {};