Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

search: Remove is:dm suggestion from get_operator_suggestions.

Joy Chen8a1a41e1ac38
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 66b766f0a70..10645f9ef78 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -622,7 +622,17 @@ function get_is_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugge
],
},
];
- return get_special_filter_suggestions(last, terms, suggestions);
+ const special_filtered_suggestions = get_special_filter_suggestions(last, terms, suggestions);
+ // Suggest "is:dm" to anyone with "is:private" in their muscle memory
+ const other_suggestions = [];
+ if (last.operator === "is" && common.phrase_match(last.operand, "private")) {
+ const is_dm = format_as_suggestion([
+ {operator: last.operator, operand: "dm", negated: last.negated},
+ ]);
+ other_suggestions.push(is_dm);
+ }
+ const all_suggestions = [...special_filtered_suggestions, ...other_suggestions];
+ return all_suggestions;
}
function get_has_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestion[] {
@@ -688,14 +698,6 @@ function get_sent_by_me_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Sugg
}
function get_operator_suggestions(last: NarrowTerm): Suggestion[] {
- // Suggest "is:dm" to anyone with "is:private" in their muscle memory
- if (last.operator === "is" && common.phrase_match(last.operand, "private")) {
- const is_dm = format_as_suggestion([
- {operator: last.operator, operand: "dm", negated: last.negated},
- ]);
- return [is_dm];
- }
-
if (!(last.operator === "search")) {
return [];
}
diff --git a/web/tests/common.test.js b/web/tests/common.test.js
index bec35e5529a..c6fe86f9aa5 100644
--- a/web/tests/common.test.js
+++ b/web/tests/common.test.js
@@ -23,6 +23,7 @@ run_test("phrase_match", () => {
assert.ok(common.phrase_match("Tes", "test"));
assert.ok(common.phrase_match("Tes", "Test"));
assert.ok(common.phrase_match("tes", "Stream Test"));
+ assert.ok(common.phrase_match("", "test"));
assert.ok(!common.phrase_match("tests", "test"));
assert.ok(!common.phrase_match("tes", "hostess"));
diff --git a/web/tests/search_suggestion.test.js b/web/tests/search_suggestion.test.js
index 0f8264ca8f9..07795169759 100644
--- a/web/tests/search_suggestion.test.js
+++ b/web/tests/search_suggestion.test.js
@@ -104,6 +104,16 @@ test("basic_get_suggestions_for_spectator", () => {
page_params.is_spectator = false;
});
+test("get_is_suggestions_for_spectator", () => {
+ page_params.is_spectator = true;
+
+ const query = "is:";
+ const suggestions = get_suggestions(query);
+ // The list of suggestions should be empty for a spectator
+ assert.deepEqual(suggestions.strings, []);
+ page_params.is_spectator = false;
+});
+
test("subset_suggestions", ({mock_template}) => {
mock_template("search_description.hbs", true, (_data, html) => html);