Skip to content

Commit f3ed55e

Browse files
theViz343Abhirup-99
andcommitted
model/api_types: Handle add/remove subscription events.
This commit adds event handling code for newly added/removed subscriptions. To store the stream subscriptions which are being updated in the event, a new field named "subscriptions" is added to the SubscriptionEvent class. Co-authored-by: Abhirup Pal <abhiruppalmethodist@gmail.com> Co-authored-by: Vishwesh Pillai <vishwesh103@gmail.com>
1 parent bca1e36 commit f3ed55e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

zulipterminal/api_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,18 @@ class SubscriptionPeerAddRemoveEvent(TypedDict):
434434
user_ids: List[int] # NOTE: replaces 'user_id' in ZFL 35
435435

436436

437+
class SubscriptionAddEvent(TypedDict):
438+
type: Literal["subscription"]
439+
op: Literal["add"]
440+
subscriptions: List[Subscription]
441+
442+
443+
class SubscriptionRemoveEvent(TypedDict):
444+
type: Literal["subscription"]
445+
op: Literal["remove"]
446+
subscriptions: List[RemovedSubscription]
447+
448+
437449
# -----------------------------------------------------------------------------
438450
# See https://zulip.com/api/get-events#typing-start and -stop
439451
class _TypingEventUser(TypedDict):
@@ -528,6 +540,8 @@ class UpdateDisplaySettingsEvent(TypedDict):
528540
UpdateMessagesLocationEvent,
529541
ReactionEvent,
530542
SubscriptionUpdateEvent,
543+
SubscriptionAddEvent,
544+
SubscriptionRemoveEvent,
531545
SubscriptionPeerAddRemoveEvent,
532546
TypingEvent,
533547
UpdateMessageFlagsEvent,

zulipterminal/model.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def get_stream_by_id(streams: List[StreamData], stream_id: int) -> StreamData:
13811381
self.visual_notified_streams.add(stream_id)
13821382
else:
13831383
self.visual_notified_streams.discard(stream_id)
1384-
elif event["op"] in ("peer_add", "peer_remove"):
1384+
elif event["op"] == "peer_add" or event["op"] == "peer_remove":
13851385
# NOTE: ZFL 35 commit was not atomic with API change
13861386
# (ZFL >=35 can use new plural style)
13871387
if "stream_ids" not in event or "user_ids" not in event:
@@ -1399,6 +1399,18 @@ def get_stream_by_id(streams: List[StreamData], stream_id: int) -> StreamData:
13991399
else:
14001400
for user_id in user_ids:
14011401
subscribers.remove(user_id)
1402+
elif event["op"] == "add":
1403+
self._subscribe_to_streams(event["subscriptions"])
1404+
# print(event["subscriptions"])
1405+
self.normalize_and_cache_message_retention_text()
1406+
self.normalize_date_created_field()
1407+
1408+
self.controller.view.left_panel.update_stream_view()
1409+
self.controller.update_screen()
1410+
elif event["op"] == "remove":
1411+
self._unsubscribe_from_streams(event["subscriptions"])
1412+
self.controller.view.left_panel.update_stream_view()
1413+
self.controller.update_screen()
14021414

14031415
def _handle_typing_event(self, event: Event) -> None:
14041416
"""

0 commit comments

Comments
 (0)