Skip to content

Commit

Permalink
model/api_types: Add data structures to support non-subscribed streams.
Browse files Browse the repository at this point in the history
This commit creates data structures, similar to stream_dict, to support
unsubscribed and never-subscribed streams. These streams are available
in the fetched initial data which is used to populate the new data
structures using the _register_non_subscribed_streams function.
  • Loading branch information
theViz343 committed Aug 26, 2023
1 parent b11ea7b commit 29fe057
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
30 changes: 17 additions & 13 deletions zulipterminal/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,37 +204,26 @@ class Message(TypedDict, total=False):


###############################################################################
# In "subscriptions" response from:
# In "subscriptions", "unsubscribed", and "never_subscribed" responses from:
# https://zulip.com/api/register-queue
# Also directly from:
# https://zulip.com/api/get-events#subscription-add
# https://zulip.com/api/get-subscriptions (unused)


class Subscription(TypedDict):
class Stream(TypedDict):
stream_id: int
name: str
description: str
rendered_description: str
date_created: int # NOTE: new in Zulip 4.0 / ZFL 30
invite_only: bool
subscribers: List[int]
desktop_notifications: Optional[bool]
email_notifications: Optional[bool]
wildcard_mentions_notify: Optional[bool]
push_notifications: Optional[bool]
audible_notifications: Optional[bool]
pin_to_top: bool
email_address: str

is_muted: bool

is_announcement_only: bool # Deprecated in Zulip 3.0 -> stream_post_policy
stream_post_policy: int # NOTE: new in Zulip 3.0 / ZFL 1

is_web_public: bool
role: int # NOTE: new in Zulip 4.0 / ZFL 31
color: str
message_retention_days: Optional[int] # NOTE: new in Zulip 3.0 / ZFL 17
history_public_to_subscribers: bool
first_message_id: Optional[int]
Expand All @@ -244,6 +233,21 @@ class Subscription(TypedDict):
# in_home_view: bool # Replaced by is_muted in Zulip 2.1; still present in updates


class Subscription(Stream):
desktop_notifications: Optional[bool]
email_notifications: Optional[bool]
wildcard_mentions_notify: Optional[bool]
push_notifications: Optional[bool]
audible_notifications: Optional[bool]
pin_to_top: bool
email_address: str

is_muted: bool

role: int # NOTE: new in Zulip 4.0 / ZFL 31
color: str


###############################################################################
# In "custom_profile_fields" response from:
# https://zulip.com/api/register-queue
Expand Down
21 changes: 21 additions & 0 deletions zulipterminal/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
PrivateMessageUpdateRequest,
RealmEmojiData,
RealmUser,
Stream,
StreamComposition,
StreamMessageUpdateRequest,
Subscription,
Expand Down Expand Up @@ -177,11 +178,18 @@ def __init__(self, controller: Any) -> None:
self._update_users_data_from_initial_data()

self.stream_dict: Dict[int, Any] = {}
self._unsubscribed_streams: Dict[int, Subscription] = {}
self._never_subscribed_streams: Dict[int, Stream] = {}
self.muted_streams: Set[int] = set()
self.pinned_streams: List[StreamData] = []
self.unpinned_streams: List[StreamData] = []
self.visual_notified_streams: Set[int] = set()

self._register_non_subscribed_streams(
unsubscribed_streams=self.initial_data["unsubscribed"],
never_subscribed_streams=self.initial_data["never_subscribed"],
)

self._subscribe_to_streams(self.initial_data["subscriptions"])

# NOTE: The date_created field of stream has been added in feature
Expand Down Expand Up @@ -1260,6 +1268,19 @@ def user_name_from_id(self, user_id: int) -> str:

return self.user_dict[user_email]["full_name"]

def _register_non_subscribed_streams(
self,
unsubscribed_streams: List[Subscription],
never_subscribed_streams: List[Stream],
) -> None:
self._unsubscribed_streams = {
subscription["stream_id"]: subscription
for subscription in unsubscribed_streams
}
self._never_subscribed_streams = {
stream["stream_id"]: stream for stream in never_subscribed_streams
}

def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
def make_reduced_stream_data(stream: Subscription) -> StreamData:
# stream_id has been changed to id.
Expand Down

0 comments on commit 29fe057

Please sign in to comment.