Skip to content

Commit 1225f39

Browse files
theViz343Abhirup-99
andcommitted
model/api_types: Create method in model to handle stream unsubscription.
This commit adds a function named "_unsubscribe_from_streams" to model.py. This function updates subscription data by removing unsubscribed streams from class variables - pinned_streams, unpinned_streams, muted_streams, and visual_notified_streams. Co-authored-by: Abhirup Pal <abhiruppalmethodist@gmail.com> Co-authored-by: Vishwesh Pillai <vishwesh103@gmail.com>
1 parent 197b450 commit 1225f39

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

zulipterminal/api_types.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@ class RealmUserEvent(TypedDict):
415415
# (also -peer_add and -peer_remove; FIXME: -add & -remove are not yet supported)
416416

417417

418+
class RemovedSubscription(TypedDict):
419+
stream_id: int
420+
name: str
421+
422+
418423
# Update of personal properties
419424
class SubscriptionUpdateEvent(SubscriptionSettingChange):
420425
type: Literal["subscription"]

zulipterminal/model.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
RealmEmojiData,
4545
RealmUser,
4646
Stream,
47+
RemovedSubscription,
4748
StreamComposition,
4849
StreamMessageUpdateRequest,
4950
Subscription,
@@ -1277,7 +1278,13 @@ def make_reduced_stream_data(stream: Subscription) -> StreamData:
12771278
# different formats
12781279
subscription["color"] = canonicalize_color(subscription["color"])
12791280

1280-
self._subscribed_streams[subscription["stream_id"]] = subscription
1281+
stream_id = subscription["stream_id"]
1282+
if stream_id in self.unsubscribed_stream_dict:
1283+
del self.unsubscribed_stream_dict[stream_id]
1284+
elif stream_id in self.never_subscribed_stream_dict:
1285+
del self.never_subscribed_stream_dict[stream_id]
1286+
self._subscribed_streams[stream_id] = subscription
1287+
12811288
stream_data = make_reduced_stream_data(subscription)
12821289
if subscription["pin_to_top"]:
12831290
new_pinned_streams.append(stream_data)
@@ -1300,6 +1307,29 @@ def make_reduced_stream_data(stream: Subscription) -> StreamData:
13001307
new_visual_notified_streams
13011308
)
13021309

1310+
def _unsubscribe_from_streams(
1311+
self, subscriptions: List[RemovedSubscription]
1312+
) -> None:
1313+
for subscription in subscriptions:
1314+
stream_id = subscription["stream_id"]
1315+
self.pinned_streams[:] = [
1316+
stream
1317+
for stream in self.pinned_streams
1318+
if stream.get("id") != stream_id
1319+
]
1320+
self.unpinned_streams[:] = [
1321+
stream
1322+
for stream in self.unpinned_streams
1323+
if stream.get("id") != stream_id
1324+
]
1325+
if stream_id in self.muted_streams:
1326+
self.muted_streams.remove(stream_id)
1327+
if stream_id in self.visual_notified_streams:
1328+
self.visual_notified_streams.remove(stream_id)
1329+
if stream_id in self.stream_dict:
1330+
self.unsubscribed_stream_dict[stream_id] = self.stream_dict[stream_id]
1331+
del self.stream_dict[stream_id]
1332+
13031333
def _group_info_from_realm_user_groups(
13041334
self, groups: List[Dict[str, Any]]
13051335
) -> List[str]:

0 commit comments

Comments
 (0)