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: Avoid showing topic suggestions from negated channels.

apoorvapendse0947ba041636
diff --git a/web/src/search_suggestion.ts b/web/src/search_suggestion.ts
index 243594c8c77..67ce502800d 100644
--- a/web/src/search_suggestion.ts
+++ b/web/src/search_suggestion.ts
@@ -563,8 +563,15 @@ function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestio
return [];
}
+ // We don't want to show topic suggestions from negated channels
+ const excluded_channel_ids = new Set(
+ terms
+ .filter((term) => term.negated && term.operator === "channel")
+ .map((term) => term.operand),
+ );
+
const current_channel_topic_entries: ChannelTopicEntry[] = [];
- if (channel_id_str) {
+ if (channel_id_str && !excluded_channel_ids.has(channel_id_str)) {
// We do this outside the stream_data.subscribed_stream_ids loop,
// since we could be viewing a channel we can't read.
const sub = stream_data.get_sub_by_id_string(channel_id_str)!;
@@ -585,7 +592,10 @@ function get_topic_suggestions(last: NarrowTerm, terms: NarrowTerm[]): Suggestio
const other_channel_topic_entries: ChannelTopicEntry[] = [];
for (const subscribed_channel_id of stream_data.subscribed_stream_ids()) {
- if (subscribed_channel_id.toString() === channel_id_str) {
+ if (
+ subscribed_channel_id.toString() === channel_id_str ||
+ excluded_channel_ids.has(subscribed_channel_id.toString())
+ ) {
continue;
} else if (!show_topics_from_other_channels) {
continue;
diff --git a/web/tests/search_suggestion.test.cjs b/web/tests/search_suggestion.test.cjs
index 4658735b158..95a1966b33e 100644
--- a/web/tests/search_suggestion.test.cjs
+++ b/web/tests/search_suggestion.test.cjs
@@ -712,6 +712,17 @@ test("topic_suggestions", ({override, mock_template}) => {
];
assert.deepEqual(suggestions.strings, expected);
+ suggestions = get_suggestions("topic:", `-channel:${office_id}`);
+ expected = [
+ `-channel:${office_id} topic:`,
+ `-channel:${office_id} channel:${devel_id} topic:REXX`,
+ ];
+ assert.deepEqual(suggestions.strings, expected);
+
+ suggestions = get_suggestions("topic:", `-channel:${office_id} -channel:${devel_id}`);
+ expected = [`-channel:${office_id} -channel:${devel_id} topic:`];
+ assert.deepEqual(suggestions.strings, expected);
+
suggestions = get_suggestions(`is:alerted channel:${devel_id} is:starred topic:`);
expected = [
`is:alerted channel:${devel_id} is:starred topic:`,