From 8356a9d9e488c876811119b9e2dc740ee6da0f8e Mon Sep 17 00:00:00 2001 From: whilstsomebody <185982038+whilstsomebody@users.noreply.github.com> Date: Fri, 15 Nov 2024 04:40:01 +0530 Subject: [PATCH] narrow_filter: Add negation support for in:home narrow filter. The in:home narrow filter is used to filter messages that appear in the home view, i.e., messages that are not muted. Conversely, `-in:home` should filter messages that are not in the home view, i.e., muted messages. However, `-in:home` did not work as expected because this filter lacked negation support, unlike similar code paths. This commit adds negation support for the in:home filter. For more information, see: . --- zerver/lib/narrow.py | 6 ++++-- zerver/tests/test_message_fetch.py | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py index fe6ca5879a..d5f1ec4f3e 100644 --- a/zerver/lib/narrow.py +++ b/zerver/lib/narrow.py @@ -371,8 +371,10 @@ class NarrowBuilder: assert self.user_profile is not None if operand == "home": - conditions = exclude_muting_conditions(self.user_profile, []) - return query.where(and_(*conditions)) + conditions = exclude_muting_conditions( + self.user_profile, [NarrowParameter(operator="in", operand="home")] + ) + return query.where(maybe_negate(and_(*conditions))) elif operand == "all": return query diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.py index 6c59a8faaa..75ad2290ab 100644 --- a/zerver/tests/test_message_fetch.py +++ b/zerver/tests/test_message_fetch.py @@ -584,10 +584,9 @@ class NarrowBuilderTest(ZulipTestCase): self._do_add_term_test(term, "WHERE (recipient_id NOT IN (__[POSTCOMPILE_recipient_id_1]))") def test_add_term_using_in_operator_and_negated(self) -> None: - # negated = True should not change anything mute_channel(self.realm, self.user_profile, "Verona") term = NarrowParameter(operator="in", operand="home", negated=True) - self._do_add_term_test(term, "WHERE (recipient_id NOT IN (__[POSTCOMPILE_recipient_id_1]))") + self._do_add_term_test(term, "WHERE recipient_id IN (__[POSTCOMPILE_recipient_id_1])") def test_add_term_using_in_operator_and_all_operand(self) -> None: mute_channel(self.realm, self.user_profile, "Verona")