Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
search: Don't show -1 in the search box for an unknown user.
Aman Agrawalfac50fc7ce5f
diff --git a/web/src/filter.ts b/web/src/filter.tsindex fdb8557933e..2a2404e30ca 100644--- a/web/src/filter.ts+++ b/web/src/filter.ts@@ -545,9 +545,14 @@ export class Filter {}static convert_term_to_suggestion(term: NarrowCanonicalTerm): NarrowTermSuggestion {+ // There is no search syntax for an unknown user, so the+ // operand is left for the user to fill in.+ const has_unknown_user =+ term.operand === filter_util.UNKNOWN_USER_ID ||+ (Array.isArray(term.operand) && term.operand.includes(filter_util.UNKNOWN_USER_ID));return {operator: term.operator,- operand: String(term.operand),+ operand: has_unknown_user ? "" : String(term.operand),negated: term.negated,};}diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex 2cac4ed7c76..d380642d286 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -2439,6 +2439,16 @@ test("convert_suggestion_to_term", () => {);});+test("convert_term_to_suggestion", () => {+ function suggested_operand(operator, operand) {+ return Filter.convert_term_to_suggestion({operator, operand}).operand;+ }++ assert.equal(suggested_operand("topic", "-1"), "-1");+ assert.equal(suggested_operand("dm", [joe.user_id, 9999]), `${joe.user_id},9999`);+ assert.equal(suggested_operand("dm", [joe.user_id, filter_util.UNKNOWN_USER_ID]), "");+});+test("try_adjusting_for_moved_with_target", () => {const scotland_id = new_stream_id();make_sub("Scotland", scotland_id);diff --git a/web/tests/search.test.cjs b/web/tests/search.test.cjsindex bac2aeb20d3..5649f7c8056 100644--- a/web/tests/search.test.cjs+++ b/web/tests/search.test.cjs@@ -10,6 +10,8 @@ const {$} = require("./lib/zjquery.cjs");const bootstrap_typeahead = mock_esm("../src/bootstrap_typeahead");+const {Filter} = zrequire("filter");+const {UNKNOWN_USER_ID} = zrequire("filter_util");const people = zrequire("people");const search = zrequire("search");const search_pill = zrequire("search_pill");@@ -462,6 +464,34 @@ run_test("generate_pills_html for general chat suggestions", ({mock_template, ovassert_suggests_general_chat(`channel:${verona.stream_id} topic: has:link`, "to");});+run_test("set_search_bar_contents with an unknown user", () => {+ function search_bar_text(terms) {+ let text;+ search_pill.set_search_bar_contents(+ terms.map((term) => Filter.convert_term_to_suggestion(term)),+ search.search_pill_widget,+ false,+ (new_text) => {+ text = new_text;+ },+ );+ return text;+ }+ const mentions_unknown_user = {operator: "mentions", operand: UNKNOWN_USER_ID, negated: false};+ const dm_including_unknown_user = {+ operator: "dm-including",+ operand: [UNKNOWN_USER_ID, zoe.user_id],+ negated: false,+ };+ const search_lunch = {operator: "search", operand: "lunch", negated: false};++ assert.equal(search_bar_text([mentions_unknown_user]), "mentions:");+ assert.equal(search_bar_text([dm_including_unknown_user]), "dm-including:");+ // A term that isn't last is invalid input, which goes after the search text.+ assert.equal(search_bar_text([mentions_unknown_user, search_lunch]), "lunch mentions:");+ assert.equal(search.search_pill_widget._get_pills_for_testing().length, 0);+});+run_test("set_search_bar_contents with duplicate pills", () => {const duplicate_attachment_terms = [{