|
27 | 27 |
|
28 | 28 | import zulip
|
29 | 29 | from bs4 import BeautifulSoup
|
30 |
| -from typing_extensions import TypedDict |
| 30 | +from typing_extensions import Literal, TypedDict |
31 | 31 |
|
32 | 32 | from zulipterminal import unicode_emojis
|
33 | 33 | from zulipterminal.api_types import (
|
@@ -1253,6 +1253,53 @@ def _get_all_stream_ids(self) -> List[int]:
|
1253 | 1253 | id_list.extend(stream_id for stream_id in self._never_subscribed_streams)
|
1254 | 1254 | return id_list
|
1255 | 1255 |
|
| 1256 | + STREAM_KEYS = Literal[ |
| 1257 | + "stream_id", |
| 1258 | + "name", |
| 1259 | + "description", |
| 1260 | + "rendered_description", |
| 1261 | + "date_created", |
| 1262 | + "invite_only", |
| 1263 | + "subscribers", |
| 1264 | + "is_announcement_only", |
| 1265 | + "stream_post_policy", |
| 1266 | + "is_web_public", |
| 1267 | + "message_retention_days", |
| 1268 | + "history_public_to_subscribers", |
| 1269 | + "first_message_id", |
| 1270 | + "stream_weekly_traffic", |
| 1271 | + ] |
| 1272 | + SUBSCRIPTION_KEYS = Literal[ |
| 1273 | + STREAM_KEYS, |
| 1274 | + "desktop_notifications", |
| 1275 | + "email_notifications", |
| 1276 | + "wildcard_mentions_notify", |
| 1277 | + "push_notifications", |
| 1278 | + "audible_notifications", |
| 1279 | + "pin_to_top", |
| 1280 | + "email_address", |
| 1281 | + "is_muted", |
| 1282 | + "role", |
| 1283 | + "color,", |
| 1284 | + ] |
| 1285 | + |
| 1286 | + def stream_property( |
| 1287 | + self, stream_id: int, property: STREAM_KEYS |
| 1288 | + ) -> Optional[Union[int, str, bool, List[int]]]: |
| 1289 | + return self._get_stream_from_id(stream_id)[property] |
| 1290 | + |
| 1291 | + def subscription_property( |
| 1292 | + self, stream_id: int, property: SUBSCRIPTION_KEYS |
| 1293 | + ) -> Optional[Union[int, str, bool, List[int]]]: |
| 1294 | + subscription = self._get_stream_from_id(stream_id) |
| 1295 | + if property in subscription: |
| 1296 | + return subscription[property] |
| 1297 | + else: |
| 1298 | + # stream_id is not a subscribed stream. |
| 1299 | + raise RuntimeError( |
| 1300 | + f"Stream with id={stream_id} does not have '{property}' property!" |
| 1301 | + ) |
| 1302 | + |
1256 | 1303 | def _subscribe_to_streams(self, subscriptions: List[Subscription]) -> None:
|
1257 | 1304 | def make_reduced_stream_data(stream: Subscription) -> StreamData:
|
1258 | 1305 | # stream_id has been changed to id.
|
|
0 commit comments