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 @@ -489,6 +489,24 @@ class Subscription extends ZulipStream {
489
489
490
490
@override
491
491
Map <String , dynamic > toJson () => _$SubscriptionToJson (this );
492
+
493
+ /// Returns a plain `ZulipStream` with same values as `this`
494
+ ///
495
+ /// This is helpful when unsubscribing from a stream.
496
+ ZulipStream toStream () => ZulipStream (
497
+ streamId: streamId,
498
+ name: name,
499
+ description: description,
500
+ renderedDescription: renderedDescription,
501
+ dateCreated: dateCreated,
502
+ firstMessageId: firstMessageId,
503
+ inviteOnly: inviteOnly,
504
+ isWebPublic: isWebPublic,
505
+ historyPublicToSubscribers: historyPublicToSubscribers,
506
+ messageRetentionDays: messageRetentionDays,
507
+ channelPostPolicy: channelPostPolicy,
508
+ canRemoveSubscribersGroup: canRemoveSubscribersGroup,
509
+ streamWeeklyTraffic: streamWeeklyTraffic);
492
510
}
493
511
494
512
@JsonEnum (fieldRename: FieldRename .snake, valueField: "apiValue" )
Original file line number Diff line number Diff line change @@ -268,6 +268,9 @@ class ChannelStoreImpl with ChannelStore {
268
268
}
269
269
assert (streamsByName[subscription.name] is Subscription );
270
270
assert (subscriptions.containsKey (streamId));
271
+ final unsubscribedStream = subscription.toStream ();
272
+ streams[streamId] = unsubscribedStream;
273
+ streamsByName[subscription.name] = unsubscribedStream;
271
274
subscriptions.remove (streamId);
272
275
}
273
276
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