Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
narrow: Rename *narrow_filter to *narrow_predicate.
Steve Howellc38b72c0149f
diff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex b937e338a5b..0956b305b5d 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -1475,7 +1475,7 @@ def do_events_register(modern_narrow = narrow_dataclasses_from_tuples(narrow)# Technically we don't need to check this here because- # build_narrow_filter will check it, but it's nicer from an error+ # build_narrow_predicate will check it, but it's nicer from an error# handling perspective to do it before contacting Tornadocheck_narrow_for_events(modern_narrow)diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.pyindex af401aff4e8..76cb216cce8 100644--- a/zerver/lib/narrow.py+++ b/zerver/lib/narrow.py@@ -153,14 +153,14 @@ class NarrowPredicate(Protocol):...-def build_narrow_filter(+def build_narrow_predicate(narrow: Collection[NarrowTerm],) -> NarrowPredicate:"""Changes to this function should come with corresponding changes toNarrowLibraryTest."""check_narrow_for_events(narrow)- def narrow_filter(*, message: Dict[str, Any], flags: List[str]) -> bool:+ def narrow_predicate(*, message: Dict[str, Any], flags: List[str]) -> bool:def satisfies_operator(*, operator: str, operand: str) -> bool:if operator == "stream":if message["type"] != "stream":@@ -204,7 +204,7 @@ def build_narrow_filter(return True- return narrow_filter+ return narrow_predicateLARGER_THAN_MAX_MESSAGE_ID = 10000000000000000diff --git a/zerver/tests/test_message_fetch.py b/zerver/tests/test_message_fetch.pyindex 030175963d6..efb7d781077 100644--- a/zerver/tests/test_message_fetch.py+++ b/zerver/tests/test_message_fetch.py@@ -31,7 +31,7 @@ from zerver.lib.narrow import (BadNarrowOperatorError,NarrowBuilder,NarrowTerm,- build_narrow_filter,+ build_narrow_predicate,exclude_muting_conditions,find_first_unread_anchor,is_spectator_compatible,@@ -592,24 +592,24 @@ class NarrowBuilderTest(ZulipTestCase):class NarrowLibraryTest(ZulipTestCase):- def test_build_narrow_filter(self) -> None:- narrow_filter = build_narrow_filter([NarrowTerm(operator="stream", operand="devel")])+ def test_build_narrow_predicate(self) -> None:+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="stream", operand="devel")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"display_recipient": "devel", "type": "stream"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"display_recipient": "social", "type": "stream"},flags=[],)@@ -617,35 +617,35 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="topic", operand="bark")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="topic", operand="bark")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"type": "stream", "subject": "BarK"},flags=[],))self.assertTrue(- narrow_filter(+ narrow_predicate(message={"type": "stream", "topic": "bark"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "stream", "subject": "play with tail"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "stream", "topic": "play with tail"},flags=[],)@@ -653,7 +653,7 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter(+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="stream", operand="devel"),NarrowTerm(operator="topic", operand="python"),@@ -661,26 +661,26 @@ class NarrowLibraryTest(ZulipTestCase):)self.assertTrue(- narrow_filter(+ narrow_predicate(message={"display_recipient": "devel", "type": "stream", "subject": "python"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"display_recipient": "devel", "type": "stream", "subject": "java"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"display_recipient": "social", "type": "stream"},flags=[],)@@ -688,19 +688,19 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter(+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="sender", operand="[email protected]")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"sender_email": "[email protected]"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"sender_email": "[email protected]"},flags=[],)@@ -708,17 +708,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="dm")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="dm")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "stream"},flags=[],)@@ -726,17 +726,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="private")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="private")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "stream"},flags=[],)@@ -744,17 +744,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="starred")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="starred")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={},flags=["starred"],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={},flags=["alerted"],)@@ -762,17 +762,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="alerted")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="alerted")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={},flags=["mentioned"],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={},flags=["starred"],)@@ -780,17 +780,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="mentioned")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="mentioned")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={},flags=["mentioned"],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={},flags=["starred"],)@@ -798,17 +798,17 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="unread")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="unread")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={},flags=["read"],)@@ -816,31 +816,31 @@ class NarrowLibraryTest(ZulipTestCase):###- narrow_filter = build_narrow_filter([NarrowTerm(operator="is", operand="resolved")])+ narrow_predicate = build_narrow_predicate([NarrowTerm(operator="is", operand="resolved")])self.assertTrue(- narrow_filter(+ narrow_predicate(message={"type": "stream", "subject": "✔ python"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "private"},flags=[],))self.assertFalse(- narrow_filter(+ narrow_predicate(message={"type": "stream", "subject": "java"},flags=[],))- def test_build_narrow_filter_invalid(self) -> None:+ def test_build_narrow_predicate_invalid(self) -> None:with self.assertRaises(JsonableError):- build_narrow_filter([NarrowTerm(operator="invalid_operator", operand="operand")])+ build_narrow_predicate([NarrowTerm(operator="invalid_operator", operand="operand")])def test_is_spectator_compatible(self) -> None:self.assertTrue(is_spectator_compatible([]))diff --git a/zerver/tornado/event_queue.py b/zerver/tornado/event_queue.pyindex 26addb0bd29..a339f805c0c 100644--- a/zerver/tornado/event_queue.py+++ b/zerver/tornado/event_queue.py@@ -39,7 +39,7 @@ from tornado import autoreloadfrom version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSIONfrom zerver.lib.exceptions import JsonableErrorfrom zerver.lib.message import MessageDict-from zerver.lib.narrow import build_narrow_filter, narrow_dataclasses_from_tuples+from zerver.lib.narrow import build_narrow_predicate, narrow_dataclasses_from_tuplesfrom zerver.lib.notification_data import UserMessageNotificationsDatafrom zerver.lib.queue import queue_json_publish, retry_eventfrom zerver.middleware import async_request_timer_restart@@ -119,7 +119,7 @@ class ClientDescriptor:self.client_type_name = client_type_nameself._timeout_handle: Any = None # TODO: should be return type of ioloop.call_laterself.narrow = narrow- self.narrow_filter = build_narrow_filter(modern_narrow)+ self.narrow_predicate = build_narrow_predicate(modern_narrow)self.bulk_message_deletion = bulk_message_deletionself.stream_typing_notifications = stream_typing_notificationsself.user_settings_object = user_settings_object@@ -230,7 +230,7 @@ class ClientDescriptor:# older servers that don't support user_topic.return Falseif event["type"] == "message":- return self.narrow_filter(message=event["message"], flags=event["flags"])+ return self.narrow_predicate(message=event["message"], flags=event["flags"])if event["type"] == "typing" and "stream_id" in event:# Typing notifications for stream messages are only# delivered if the stream_typing_notifications