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_suggestions: Remove filters unusable by spectator.

Aman Agrawal0ac8f053a6b6
diff --git a/frontend_tests/node_tests/search_suggestion.js b/frontend_tests/node_tests/search_suggestion.js
index 1f4c930bc71..16056954c3e 100644
--- a/frontend_tests/node_tests/search_suggestion.js
+++ b/frontend_tests/node_tests/search_suggestion.js
@@ -101,20 +101,7 @@ test("basic_get_suggestions_for_spectator", ({override_rewire}) => {
const query = "";
const suggestions = get_suggestions("", query);
- assert.deepEqual(suggestions.strings, [
- "",
- "streams:public",
- "is:private",
- "is:starred",
- "is:mentioned",
- "is:alerted",
- "is:unread",
- "is:resolved",
- "has:link",
- "has:image",
- "has:attachment",
- // "sender:[email protected]",
- ]);
+ assert.deepEqual(suggestions.strings, ["", "has:link", "has:image", "has:attachment"]);
page_params.is_spectator = false;
});
diff --git a/static/js/search_suggestion.js b/static/js/search_suggestion.js
index 91e430eb8c2..58027e49215 100644
--- a/static/js/search_suggestion.js
+++ b/static/js/search_suggestion.js
@@ -543,10 +543,6 @@ function get_has_filter_suggestions(last, operators) {
}
function get_sent_by_me_suggestions(last, operators) {
- if (page_params.is_spectator) {
- return [];
- }
-
const last_string = Filter.unparse([last]).toLowerCase();
const negated = last.negated || (last.operator === "search" && last.operand[0] === "-");
const negated_symbol = negated ? "-" : "";
@@ -721,7 +717,8 @@ export function get_search_result(base_query, query) {
};
}
- const filterers = [
+ // Remember to update the spectator list when changing this.
+ let filterers = [
get_streams_filter_suggestions,
get_is_filter_suggestions,
get_sent_by_me_suggestions,
@@ -736,6 +733,17 @@ export function get_search_result(base_query, query) {
get_has_filter_suggestions,
];
+ if (page_params.is_spectator) {
+ filterers = [
+ get_stream_suggestions,
+ get_people("sender"),
+ get_people("from"),
+ get_topic_suggestions,
+ get_operator_suggestions,
+ get_has_filter_suggestions,
+ ];
+ }
+
if (!page_params.search_pills_enabled) {
all_operators = search_operators;
}