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: Show correct description string for public channels.

Evy Kassirerfa03c4200911
diff --git a/web/src/filter.ts b/web/src/filter.ts
index 2e9741f7a39..7926be91190 100644
--- a/web/src/filter.ts
+++ b/web/src/filter.ts
@@ -804,6 +804,12 @@ export class Filter {
};
}
}
+ if (canonicalized_operator === "channels" && operand === "public") {
+ return {
+ type: "plain_text",
+ content: this.describe_public_channels(term.negated ?? false),
+ };
+ }
const prefix_for_operator = Filter.operator_to_prefix(
canonicalized_operator,
term.negated,
@@ -864,6 +870,14 @@ export class Filter {
return [...parts, ...more_parts];
}
+ static describe_public_channels(negated: boolean): string {
+ const possible_prefix = negated ? "exclude " : "";
+ if (page_params.is_spectator || current_user.is_guest) {
+ return possible_prefix + "all public channels that you can view";
+ }
+ return possible_prefix + "all public channels";
+ }
+
static search_description_as_html(
terms: NarrowTerm[],
is_operator_suggestion: boolean,
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index e86f4d05c29..7cfa0300318 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -11,7 +11,7 @@ import * as narrow_state from "./narrow_state.ts";
import {page_params} from "./page_params.ts";
import * as people from "./people.ts";
import type {User} from "./people.ts";
-import {type NarrowTerm, current_user} from "./state_data.ts";
+import {type NarrowTerm} from "./state_data.ts";
import * as stream_data from "./stream_data.ts";
import * as stream_topic_history from "./stream_topic_history.ts";
import * as stream_topic_history_util from "./stream_topic_history_util.ts";
@@ -646,12 +646,8 @@ function get_channels_filter_suggestions(last: NarrowTerm, terms: NarrowTerm[]):
if (last.operator === "search" && common.phrase_match(last.operand, "streams")) {
search_string = "streams:public";
}
- let description_html;
- if (page_params.is_spectator || current_user.is_guest) {
- description_html = "All public channels that you can view";
- } else {
- description_html = "All public channels";
- }
+ let description_html = Filter.describe_public_channels(last.negated ?? false);
+ description_html = description_html.charAt(0).toUpperCase() + description_html.slice(1);
const suggestions: SuggestionAndIncompatiblePatterns[] = [
{
search_string,
diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjs
index 61f0589c8f8..4ff9c2aa230 100644
--- a/web/tests/filter.test.cjs
+++ b/web/tests/filter.test.cjs
@@ -1658,13 +1658,19 @@ test("describe", ({mock_template, override}) => {
mock_template("search_description.hbs", true, (_data, html) => html);
narrow = [{operator: "channels", operand: "public"}];
- string = "channels public";
+ string = "all public channels";
assert.equal(Filter.search_description_as_html(narrow, false), string);
narrow = [{operator: "channels", operand: "public", negated: true}];
- string = "exclude channels public";
+ string = "exclude all public channels";
assert.equal(Filter.search_description_as_html(narrow, false), string);
+ page_params.is_spectator = true;
+ narrow = [{operator: "channels", operand: "public"}];
+ string = "all public channels that you can view";
+ assert.equal(Filter.search_description_as_html(narrow, false), string);
+ page_params.is_spectator = false;
+
const devel_id = new_stream_id();
make_sub("devel", devel_id);