File tree 3 files changed +31
-0
lines changed
3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -437,6 +437,24 @@ class Subscription extends ZulipStream {
437
437
438
438
@override
439
439
Map <String , dynamic > toJson () => _$SubscriptionToJson (this );
440
+
441
+ /// Returns a plain `ZulipStream` with same values as `this`
442
+ ///
443
+ /// This is helpful when unsubscribing from a stream.
444
+ ZulipStream toStream () => ZulipStream (
445
+ streamId: streamId,
446
+ name: name,
447
+ description: description,
448
+ renderedDescription: renderedDescription,
449
+ dateCreated: dateCreated,
450
+ firstMessageId: firstMessageId,
451
+ inviteOnly: inviteOnly,
452
+ isWebPublic: isWebPublic,
453
+ historyPublicToSubscribers: historyPublicToSubscribers,
454
+ messageRetentionDays: messageRetentionDays,
455
+ channelPostPolicy: channelPostPolicy,
456
+ canRemoveSubscribersGroup: canRemoveSubscribersGroup,
457
+ streamWeeklyTraffic: streamWeeklyTraffic);
440
458
}
441
459
442
460
@JsonEnum (fieldRename: FieldRename .snake, valueField: "apiValue" )
Original file line number Diff line number Diff line change @@ -173,6 +173,8 @@ class ChannelStoreImpl with ChannelStore {
173
173
assert (streamsByName.containsKey (streams[streamId]! .name)
174
174
&& streamsByName[streams[streamId]! .name] is Subscription );
175
175
assert (subscriptions.containsKey (streamId));
176
+ streams[streamId] = subscriptions[streamId]! .toStream ();
177
+ streamsByName[streams[streamId]! .name] = subscriptions[streamId]! .toStream ();
176
178
subscriptions.remove (streamId);
177
179
}
178
180
Original file line number Diff line number Diff line change @@ -103,6 +103,17 @@ void main() {
103
103
value: false ));
104
104
check (store.subscriptions[stream.streamId]! .isMuted).isTrue ();
105
105
});
106
+
107
+ test ('SubscriptionRemoveEvent updates streams and streamsByName' , () async {
108
+ final store = eg.store (initialSnapshot: eg.initialSnapshot (
109
+ streams: [eg.subscription (stream)],
110
+ subscriptions: [eg.subscription (stream)],
111
+ ));
112
+
113
+ await store.handleEvent (SubscriptionRemoveEvent (id: 1 , streamIds: [stream.streamId]));
114
+ check (store.streams[stream.streamId] is Subscription ).isFalse ();
115
+ check (store.streams[stream.streamId] is ZulipStream ).isTrue ();
116
+ });
106
117
});
107
118
108
119
group ('topic visibility' , () {
You can’t perform that action at this time.
0 commit comments