From 52efa3d74c5d5fbaa769f383bada88e8ddaeac70 Mon Sep 17 00:00:00 2001 From: Aditya Kumar Kasaudhan <74228301+Aditya8840@users.noreply.github.com> Date: Wed, 6 Nov 2024 00:06:56 +0530 Subject: [PATCH] filter: Mark messages as read for `-is:dm` search views. This commit updates the behavior of the `-is:dm` search filter, both alone and when combined with channel or topic filters, to mark messages as read, aligning it with the existing behavior of `is:dm`. Fixes: #25113. --- web/src/filter.ts | 16 ++++++++++ web/src/message_view_header.ts | 12 ++++++++ web/tests/filter.test.js | 55 ++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) diff --git a/web/src/filter.ts b/web/src/filter.ts index bab337c349..49c9667ddd 100644 --- a/web/src/filter.ts +++ b/web/src/filter.ts @@ -1151,6 +1151,22 @@ export class Filter { return true; } + if (_.isEqual(term_types, ["not-is-dm"])) { + return true; + } + + if (_.isEqual(term_types, ["channel", "not-is-dm"])) { + return true; + } + + if (_.isEqual(term_types, ["topic", "not-is-dm"])) { + return true; + } + + if (_.isEqual(term_types, ["channel", "topic", "not-is-dm"])) { + return true; + } + if (_.isEqual(term_types, [])) { // Empty filters means we are displaying all possible messages. return true; diff --git a/web/src/message_view_header.ts b/web/src/message_view_header.ts index b4bb89b9b8..e3ef490a11 100644 --- a/web/src/message_view_header.ts +++ b/web/src/message_view_header.ts @@ -70,6 +70,18 @@ function get_message_view_header_context(filter: Filter | undefined): MessageVie // // TODO: This ideally doesn't need a special case, we can just use // `filter.get_description` for it. + + if (filter?.has_negated_operand("is", "dm")) { + return { + title: $t({defaultMessage: "Messages excluding DMs"}), + description: $t({ + defaultMessage: "All messages except direct messages.", + }), + zulip_icon: "all-messages", + link: "/help/combined-feed", + }; + } + if (filter === undefined || filter.is_in_home()) { let description; if (page_params.is_spectator) { diff --git a/web/tests/filter.test.js b/web/tests/filter.test.js index b23dec1c55..7c08f08352 100644 --- a/web/tests/filter.test.js +++ b/web/tests/filter.test.js @@ -378,6 +378,61 @@ test("basics", () => { assert.ok(filter.is_conversation_view()); assert.ok(!filter.is_conversation_view_with_near()); + terms = [{operator: "is", operand: "dm", negated: true}]; + filter = new Filter(terms); + assert.ok(!filter.has_operator("search")); + assert.ok(filter.can_apply_locally()); + assert.ok(filter.supports_collapsing_recipients()); + assert.ok(filter.can_mark_messages_read()); + assert.ok(!filter.is_personal_filter()); + assert.ok(!filter.contains_only_private_messages()); + + terms = [ + {operator: "channel", operand: "channel_name"}, + {operator: "is", operand: "dm", negated: true}, + ]; + filter = new Filter(terms); + assert.ok(filter.has_operator("channel")); + assert.ok(filter.can_apply_locally()); + assert.ok(filter.supports_collapsing_recipients()); + assert.ok(filter.can_mark_messages_read()); + assert.ok(!filter.is_personal_filter()); + assert.ok(!filter.contains_only_private_messages()); + assert.ok(!filter.has_negated_operand("channel", "not-is-dm")); + + terms = [ + {operator: "topic", operand: "topic_name"}, + {operator: "is", operand: "dm", negated: true}, + ]; + filter = new Filter(terms); + assert.ok(filter.has_operator("topic")); + assert.ok(!filter.has_operator("search")); + assert.ok(filter.can_apply_locally()); + assert.ok(filter.supports_collapsing_recipients()); + assert.ok(filter.can_mark_messages_read()); + assert.ok(!filter.is_personal_filter()); + assert.ok(!filter.contains_only_private_messages()); + assert.ok(!filter.has_negated_operand("topic", "topic_name")); + + terms = [ + {operator: "channel", operand: "channel_name"}, + {operator: "topic", operand: "topic_name"}, + {operator: "is", operand: "dm", negated: true}, + ]; + filter = new Filter(terms); + assert.ok(filter.has_operator("channel")); + assert.ok(filter.has_operator("topic")); + assert.ok(!filter.has_operator("search")); + assert.ok(filter.can_apply_locally()); + assert.ok(filter.supports_collapsing_recipients()); + assert.ok(filter.can_mark_messages_read()); + assert.ok(!filter.is_personal_filter()); + assert.ok(!filter.contains_only_private_messages()); + assert.ok(!filter.has_negated_operand("channel", "channel_name")); + assert.ok(!filter.has_negated_operand("topic", "topic_name")); + assert.ok(filter.can_bucket_by("channel")); + assert.ok(filter.can_bucket_by("channel", "topic")); + // "pm-with" was renamed to "dm" terms = [{operator: "pm-with", operand: "joe@example.com"}]; filter = new Filter(terms);