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:
<https://chat.zulip.org/#narrow/channel/378-api-design/topic/mark.20muted-topic.20messages.20as.20read/near/1980534>.
This commit is contained in:
whilstsomebody 2024-11-15 04:40:01 +05:30 committed by GitHub
parent 743d0dbaa2
commit 8356a9d9e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -371,8 +371,10 @@ class NarrowBuilder:
assert self.user_profile is not None assert self.user_profile is not None
if operand == "home": if operand == "home":
conditions = exclude_muting_conditions(self.user_profile, []) conditions = exclude_muting_conditions(
return query.where(and_(*conditions)) self.user_profile, [NarrowParameter(operator="in", operand="home")]
)
return query.where(maybe_negate(and_(*conditions)))
elif operand == "all": elif operand == "all":
return query return query

View File

@ -584,10 +584,9 @@ class NarrowBuilderTest(ZulipTestCase):
self._do_add_term_test(term, "WHERE (recipient_id NOT IN (__[POSTCOMPILE_recipient_id_1]))") 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: 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") mute_channel(self.realm, self.user_profile, "Verona")
term = NarrowParameter(operator="in", operand="home", negated=True) 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: def test_add_term_using_in_operator_and_all_operand(self) -> None:
mute_channel(self.realm, self.user_profile, "Verona") mute_channel(self.realm, self.user_profile, "Verona")