mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
narrows: Use dataclasses in a couple internal functions.
This is a first step toward two goals:
* support dictionary-like narrows when registering events
* use readable dataclasses internally
This is gonna be a somewhat complicated exercise due to how
events get serialized, but fortunately this interim step
doesn't require any serious shims, so it improves the codebase
even if the long-term goals may take a while to get sorted
out.
The two places where we have to use a helper to convert narrows
from tuples to dataclasses will eventually rely on their callers
to do the conversion, but I don't want to re-work the entire
codepath yet.
Note that the new NarrowTerm dataclass makes it more explicit
that the internal functions currently either don't care about
negated flags or downright don't support them. This way mypy
protects us from assuming that we can just add negated support
at the outer edges.
OTOH I do make a tiny effort here to slightly restructure
narrow_filter in a way that paves the way for negation support.
The bigger goal by far, though, is to at least support the
dictionary format.
This commit is contained in:
@@ -39,7 +39,7 @@ from tornado import autoreload
|
||||
from version import API_FEATURE_LEVEL, ZULIP_MERGE_BASE, ZULIP_VERSION
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.message import MessageDict
|
||||
from zerver.lib.narrow import build_narrow_filter
|
||||
from zerver.lib.narrow import build_narrow_filter, narrow_dataclasses_from_tuples
|
||||
from zerver.lib.notification_data import UserMessageNotificationsData
|
||||
from zerver.lib.queue import queue_json_publish, retry_event
|
||||
from zerver.middleware import async_request_timer_restart
|
||||
@@ -97,6 +97,10 @@ class ClientDescriptor:
|
||||
pronouns_field_type_supported: bool = True,
|
||||
linkifier_url_template: bool = False,
|
||||
) -> None:
|
||||
# TODO: We eventually want to upstream this code to the caller, but
|
||||
# serialization concerns make it a bit difficult.
|
||||
modern_narrow = narrow_dataclasses_from_tuples(narrow)
|
||||
|
||||
# These objects are serialized on shutdown and restored on restart.
|
||||
# If fields are added or semantics are changed, temporary code must be
|
||||
# added to load_event_queues() to update the restored objects.
|
||||
@@ -115,7 +119,7 @@ class ClientDescriptor:
|
||||
self.client_type_name = client_type_name
|
||||
self._timeout_handle: Any = None # TODO: should be return type of ioloop.call_later
|
||||
self.narrow = narrow
|
||||
self.narrow_filter = build_narrow_filter(narrow)
|
||||
self.narrow_filter = build_narrow_filter(modern_narrow)
|
||||
self.bulk_message_deletion = bulk_message_deletion
|
||||
self.stream_typing_notifications = stream_typing_notifications
|
||||
self.user_settings_object = user_settings_object
|
||||
|
||||
Reference in New Issue
Block a user