Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search: Match people suggestions against typed text, not resolved id.
Shubham Padiadb97a96b144b
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.tsindex a81b0952af9..46b420fdaac 100644--- a/web/src/search_suggestion.ts+++ b/web/src/search_suggestion.ts@@ -391,7 +391,11 @@ function make_people_getter(last: NarrowCanonicalTermSuggestion): () => User[] {if (last.operator === "is" && last.operand === "dm") {query = "";} else {- query = last.operand;+ // We match people against the text the user actually typed+ // (`raw_operand`), not `last.operand`, since that may have+ // been canonicalized from a name to a user id (e.g. `dm:John`+ // becomes `dm:50` when "John" is a unique full name).+ query = last.raw_operand;}persons = people.get_people_for_search_bar(query);@@ -407,7 +411,7 @@ function get_person_suggestions(autocomplete_operator: "dm" | "sender" | "dm-including" | "mentions",): Suggestion[] {if (last.operator === "is" && last.operand === "dm") {- last = {operator: "dm", operand: "", negated: false};+ last = {operator: "dm", operand: "", raw_operand: "", negated: false};}const valid = ["search", autocomplete_operator];@@ -1093,12 +1097,14 @@ export let get_suggestions = function (return {operator: canonical_term.operator,operand: String(canonical_term.operand),+ raw_operand: term.operand,negated: canonical_term.negated,};}return {operator: filter_util.canonicalize_operator(term.operator),operand: term.operand,+ raw_operand: term.operand,negated: term.negated,};},@@ -1110,7 +1116,12 @@ export let get_suggestions = function (// `last` will always be a text term, not a pill term. If there is no// text, then `last` is this default empty term.- let last: NarrowCanonicalTermSuggestion = {operator: "", operand: "", negated: false};+ let last: NarrowCanonicalTermSuggestion = {+ operator: "",+ operand: "",+ raw_operand: "",+ negated: false,+ };if (text_search_terms.length > 0) {last = text_search_terms.at(-1)!;}@@ -1131,6 +1142,7 @@ export let get_suggestions = function (last = {operator: person_op.operator,operand: person_op.operand + " " + last.operand,+ raw_operand: person_op.raw_operand + " " + last.raw_operand,negated: person_op.negated,};text_search_terms.splice(-2);diff --git a/web/src/state_data.ts b/web/src/state_data.tsindex 43bfc3bb43c..52eb50bfb06 100644--- a/web/src/state_data.ts+++ b/web/src/state_data.ts@@ -31,6 +31,12 @@ export type NarrowTermSuggestion = {export type NarrowCanonicalTermSuggestion = {operator: NarrowCanonicalTerm["operator"];operand: string;+ // The operand as the user actually typed it, before any+ // canonicalization from a name to a user id (e.g. `dm:John`+ // becomes `dm:50` when "John" is a unique full name). People+ // suggestions match against this so that completing a unique name+ // does not hide other name matches like "John Doe".+ raw_operand: string;negated?: boolean | undefined;};diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjsindex 81f1d096a3b..68f25e93aef 100644--- a/web/tests/search_suggestion.test.cjs+++ b/web/tests/search_suggestion.test.cjs@@ -327,6 +327,39 @@ test("dm_suggestions", ({override}) => {assert.deepEqual(suggestions, expected);});+test("dm_suggestions_for_exact_full_name", () => {+ // When the typed text exactly matches a unique full name, it is+ // resolved to that user's id internally. We must still suggest other+ // users whose names match the typed text as a prefix, rather than+ // collapsing to just the exactly-named user.+ const john = make_user({+ email: "[email protected]",+ user_id: 200,+ full_name: "John",+ });+ const john_doe = make_user({+ email: "[email protected]",+ user_id: 201,+ full_name: "John Doe",+ });+ people.add_active_user(john, "server_events");+ people.add_active_user(john_doe, "server_events");++ // A partial query matches both users by name prefix.+ let suggestions = get_suggestions("dm:joh");+ assert.deepEqual(suggestions, [`dm:${john.user_id}`, `dm:${john_doe.user_id}`]);++ // Completing the unique full name "John" must still suggest "John Doe",+ // not collapse to just "John".+ suggestions = get_suggestions("dm:John");+ assert.deepEqual(suggestions, [`dm:${john.user_id}`, `dm:${john_doe.user_id}`]);++ // A multi-word continuation after the resolved name still matches by+ // name, narrowing to "John Doe".+ suggestions = get_suggestions("dm:John Do");+ assert.deepEqual(suggestions, [`dm:${john_doe.user_id}`]);+});+test("group_suggestions", () => {// If there's an existing completed user pill right before// the input string, we suggest a user group as one of the