Skip to content

Commit ab97a94

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 1225f39 commit ab97a94

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
@@ -438,6 +438,18 @@ class SubscriptionPeerAddRemoveEvent(TypedDict):
438438
user_ids: List[int] # NOTE: replaces 'user_id' in ZFL 35
439439

440440

441+
class SubscriptionAddEvent(TypedDict):
442+
type: Literal["subscription"]
443+
op: Literal["add"]
444+
subscriptions: List[Subscription]
445+
446+
447+
class SubscriptionRemoveEvent(TypedDict):
448+
type: Literal["subscription"]
449+
op: Literal["remove"]
450+
subscriptions: List[RemovedSubscription]
451+
452+
441453
# -----------------------------------------------------------------------------
442454
# See https://zulip.com/api/get-events#typing-start and -stop
443455
class _TypingEventUser(TypedDict):
@@ -532,6 +544,8 @@ class UpdateDisplaySettingsEvent(TypedDict):
532544
UpdateMessagesLocationEvent,
533545
ReactionEvent,
534546
SubscriptionUpdateEvent,
547+
SubscriptionAddEvent,
548+
SubscriptionRemoveEvent,
535549
SubscriptionPeerAddRemoveEvent,
536550
TypingEvent,
537551
UpdateMessageFlagsEvent,

zulipterminal/model.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ def get_stream_by_id(streams: List[StreamData], stream_id: int) -> StreamData:
14821482
self.visual_notified_streams.add(stream_id)
14831483
else:
14841484
self.visual_notified_streams.discard(stream_id)
1485-
elif event["op"] in ("peer_add", "peer_remove"):
1485+
elif event["op"] == "peer_add" or event["op"] == "peer_remove":
14861486
# NOTE: ZFL 35 commit was not atomic with API change
14871487
# (ZFL >=35 can use new plural style)
14881488
if "stream_ids" not in event or "user_ids" not in event:
@@ -1500,6 +1500,18 @@ def get_stream_by_id(streams: List[StreamData], stream_id: int) -> StreamData:
15001500
else:
15011501
for user_id in user_ids:
15021502
subscribers.remove(user_id)
1503+
elif event["op"] == "add":
1504+
self._subscribe_to_streams(event["subscriptions"])
1505+
# print(event["subscriptions"])
1506+
self.normalize_and_cache_message_retention_text()
1507+
self.normalize_date_created_field()
1508+
1509+
self.controller.view.left_panel.update_stream_view()
1510+
self.controller.update_screen()
1511+
elif event["op"] == "remove":
1512+
self._unsubscribe_from_streams(event["subscriptions"])
1513+
self.controller.view.left_panel.update_stream_view()
1514+
self.controller.update_screen()
15031515

15041516
def _handle_typing_event(self, event: Event) -> None:
15051517
"""

0 commit comments

Comments
 (0)