File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -495,6 +495,24 @@ class Subscription extends ZulipStream {
495
495
496
496
@override
497
497
Map <String , dynamic > toJson () => _$SubscriptionToJson (this );
498
+
499
+ /// Returns a plain `ZulipStream` with same values as `this`
500
+ ///
501
+ /// This is helpful when unsubscribing from a stream.
502
+ ZulipStream toStream () => ZulipStream (
503
+ streamId: streamId,
504
+ name: name,
505
+ description: description,
506
+ renderedDescription: renderedDescription,
507
+ dateCreated: dateCreated,
508
+ firstMessageId: firstMessageId,
509
+ inviteOnly: inviteOnly,
510
+ isWebPublic: isWebPublic,
511
+ historyPublicToSubscribers: historyPublicToSubscribers,
512
+ messageRetentionDays: messageRetentionDays,
513
+ channelPostPolicy: channelPostPolicy,
514
+ canRemoveSubscribersGroup: canRemoveSubscribersGroup,
515
+ streamWeeklyTraffic: streamWeeklyTraffic);
498
516
}
499
517
500
518
@JsonEnum (fieldRename: FieldRename .snake, valueField: "apiValue" )
Original file line number Diff line number Diff line change @@ -310,6 +310,9 @@ class ChannelStoreImpl with ChannelStore {
310
310
}
311
311
assert (streamsByName[subscription.name] is Subscription );
312
312
assert (subscriptions.containsKey (streamId));
313
+ final unsubscribedStream = subscription.toStream ();
314
+ streams[streamId] = unsubscribedStream;
315
+ streamsByName[subscription.name] = unsubscribedStream;
313
316
subscriptions.remove (streamId);
314
317
}
315
318
Original file line number Diff line number Diff line change @@ -114,6 +114,17 @@ void main() {
114
114
value: false ));
115
115
check (store.subscriptions[stream.streamId]! .isMuted).isTrue ();
116
116
});
117
+
118
+ test ('SubscriptionRemoveEvent updates streams and streamsByName' , () async {
119
+ final store = eg.store (initialSnapshot: eg.initialSnapshot (
120
+ streams: [eg.subscription (stream)],
121
+ subscriptions: [eg.subscription (stream)],
122
+ ));
123
+
124
+ check (store.streams[stream.streamId] is Subscription ).isTrue ();
125
+ await store.handleEvent (SubscriptionRemoveEvent (id: 1 , streamIds: [stream.streamId]));
126
+ check (store.streams[stream.streamId] is Subscription ).isFalse ();
127
+ });
117
128
});
118
129
119
130
group ('topic visibility' , () {
You can’t perform that action at this time.
0 commit comments