Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
filter: Enable channels operator for `can_apply_locally`.
Pratik Chanda20889b3f78c7
diff --git a/web/src/filter.ts b/web/src/filter.tsindex 13156ebfb93..40c1b17aea6 100644--- a/web/src/filter.ts+++ b/web/src/filter.ts@@ -212,6 +212,14 @@ function message_matches_search_term(message: Message, operator: string, operandreturn message.stream_id.toString() === operand;}+ case "channels": {+ if (message.type !== "stream") {+ return false;+ }+ const stream_privacy_policy = stream_data.get_stream_privacy_policy(message.stream_id);+ return ["public", "web-public"].includes(stream_privacy_policy) && operand === "public";+ }+case "topic":if (message.type !== "stream") {return false;@@ -1609,12 +1617,6 @@ export class Filter {return false;}- // TODO: It's not clear why `channels:` filters would not be- // applicable locally.- if (this.has_operator("channels") || this.has_negated_operand("channels", "public")) {- return false;- }-// If we get this far, we're good!return true;}diff --git a/web/tests/filter.test.cjs b/web/tests/filter.test.cjsindex 1da45b095ce..c2ab803aa28 100644--- a/web/tests/filter.test.cjs+++ b/web/tests/filter.test.cjs@@ -302,7 +302,7 @@ test("basics", () => {assert.ok(!filter.can_mark_messages_read());assert.ok(filter.contains_no_partial_conversations());assert.ok(filter.has_negated_operand("channels", "public"));- assert.ok(!filter.can_apply_locally());+ assert.ok(filter.can_apply_locally());assert.ok(!filter.is_personal_filter());assert.ok(!filter.is_conversation_view());assert.ok(!filter.is_channel_view());@@ -316,7 +316,7 @@ test("basics", () => {assert.ok(!filter.can_mark_messages_read());assert.ok(filter.contains_no_partial_conversations());assert.ok(!filter.has_negated_operand("channels", "public"));- assert.ok(!filter.can_apply_locally());+ assert.ok(filter.can_apply_locally());assert.ok(filter.includes_full_stream_history());assert.ok(!filter.is_personal_filter());assert.ok(!filter.is_conversation_view());@@ -525,7 +525,7 @@ test("basics", () => {assert.ok(filter.contains_no_partial_conversations());// This next check verifies what is probably a bug; see the// comment in the can_apply_locally implementation.- assert.ok(!filter.can_apply_locally());+ assert.ok(filter.can_apply_locally());assert.ok(!filter.is_personal_filter());assert.ok(!filter.is_conversation_view());assert.ok(filter.may_contain_multiple_conversations());@@ -606,7 +606,7 @@ test("basics", () => {assert.ok(!filter.contains_only_private_messages());assert.ok(!filter.allow_use_first_unread_when_narrowing());assert.ok(filter.includes_full_stream_history());- assert.ok(!filter.can_apply_locally());+ assert.ok(filter.can_apply_locally());assert.ok(!filter.is_personal_filter());assert.ok(!filter.is_conversation_view());assert.ok(!filter.may_contain_multiple_conversations());@@ -1091,12 +1091,23 @@ test("predicate_basics", ({override}) => {// For old channels that we are no longer subscribed to, we may not have// a subscription, but these should still match by channel name.const old_sub_id = new_stream_id();+ const private_sub_id = new_stream_id();const old_sub = {name: "old-subscription",stream_id: old_sub_id,subscribed: false,+ invite_only: false,+ is_web_public: false,+ };+ const private_sub = {+ name: "private-subscription",+ stream_id: private_sub_id,+ subscribed: true,+ invite_only: true,+ is_web_public: false,};stream_data.add_sub(old_sub);+ stream_data.add_sub(private_sub);predicate = get_predicate([["channel", old_sub_id.toString()],["topic", "Bar"],@@ -1116,7 +1127,8 @@ test("predicate_basics", ({override}) => {assert.ok(!predicate({type: stream_message}));predicate = get_predicate([["channels", "public"]]);- assert.ok(predicate({}));+ assert.ok(predicate({type: stream_message, stream_id: old_sub_id}));+ assert.ok(!predicate({type: stream_message, stream_id: private_sub_id}));predicate = get_predicate([["is", "starred"]]);assert.ok(predicate({starred: true}));