types: Better types for API fields.

Signed-off-by: Zixuan James Li <359101898@qq.com>
This commit is contained in:
Zixuan James Li
2022-05-25 20:51:35 -04:00
committed by Tim Abbott
parent e6e975b470
commit 44ecd66eae
6 changed files with 135 additions and 26 deletions

View File

@@ -221,6 +221,49 @@ class NeverSubscribedStreamDict(TypedDict):
subscribers: NotRequired[List[int]]
class APIStreamDict(TypedDict):
"""Stream information provided to Zulip clients as a dictionary via API.
It should contain all the fields specified in `zerver.models.Stream.API_FIELDS`
with few exceptions and possible additional fields.
"""
date_created: int
description: str
first_message_id: Optional[int]
history_public_to_subscribers: bool
invite_only: bool
is_web_public: bool
message_retention_days: Optional[int]
name: str
rendered_description: str
stream_id: int # `stream_id`` represents `id` of the `Stream` object in `API_FIELDS`
stream_post_policy: int
# Computed fields not specified in `Stream.API_FIELDS`
is_announcement_only: bool
is_default: NotRequired[bool]
class APISubscriptionDict(APIStreamDict):
"""Similar to StreamClientDict, it should contain all the fields specified in
`zerver.models.Subscription.API_FIELDS` and several additional fields.
"""
audible_notifications: Optional[bool]
color: str
desktop_notifications: Optional[bool]
email_notifications: Optional[bool]
is_muted: bool
pin_to_top: bool
push_notifications: Optional[bool]
role: int
wildcard_mentions_notify: Optional[bool]
# Computed fields not specified in `Subscription.API_FIELDS`
email_address: str
in_home_view: bool
stream_weekly_traffic: Optional[int]
subscribers: List[int]
@dataclass
class SubscriptionInfo:
subscriptions: List[SubscriptionStreamDict]