Skip to content

Commit bca1e36

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 d504497 commit bca1e36

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

zulipterminal/api_types.py

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

413413

414+
class RemovedSubscription(TypedDict):
415+
stream_id: int
416+
name: str
417+
418+
414419
# Update of personal properties
415420
class SubscriptionUpdateEvent(SubscriptionSettingChange):
416421
type: Literal["subscription"]

zulipterminal/model.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
PrivateMessageUpdateRequest,
4444
RealmEmojiData,
4545
RealmUser,
46+
RemovedSubscription,
4647
StreamComposition,
4748
StreamMessageUpdateRequest,
4849
Subscription,
@@ -1205,6 +1206,28 @@ def make_reduced_stream_data(stream: Subscription) -> StreamData:
12051206
new_visual_notified_streams
12061207
)
12071208

1209+
def _unsubscribe_from_streams(
1210+
self, subscriptions: List[RemovedSubscription]
1211+
) -> None:
1212+
for subscription in subscriptions:
1213+
stream_id = subscription["stream_id"]
1214+
self.pinned_streams[:] = [
1215+
stream
1216+
for stream in self.pinned_streams
1217+
if stream.get("id") != stream_id
1218+
]
1219+
self.unpinned_streams[:] = [
1220+
stream
1221+
for stream in self.unpinned_streams
1222+
if stream.get("id") != stream_id
1223+
]
1224+
if stream_id in self.muted_streams:
1225+
self.muted_streams.remove(stream_id)
1226+
if stream_id in self.visual_notified_streams:
1227+
self.visual_notified_streams.remove(stream_id)
1228+
if stream_id in self.stream_dict:
1229+
del self.stream_dict[stream_id]
1230+
12081231
def _group_info_from_realm_user_groups(
12091232
self, groups: List[Dict[str, Any]]
12101233
) -> List[str]:

0 commit comments

Comments
 (0)