Skip to content

Commit 966d716

Browse files
committed
api: Update ChannelDeleteEvent to match new API changes
There are new changes made to `stream op: delete` event in server-10: - The `streams` field used to be an array of just-deleted channel objects, but now it is an array of objects each containing only ID of the just-deleted channels (this would crash the app). - The `streams` field is also deprecated and will be removed in a future release. - As a replacement to `streams`, `stream_ids` is introduced which is an array of the just-deleted channel IDs.
1 parent 5778bea commit 966d716

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

lib/api/model/events.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,14 @@ class ChannelDeleteEvent extends ChannelEvent {
609609
@JsonKey(includeToJson: true)
610610
String get op => 'delete';
611611

612-
final List<ZulipStream> streams;
612+
final List<ZulipStreamId>? streams; // TODO(server-10): remove
613+
final List<int>? streamIds; // TODO(server-10): remove nullability
613614

614-
ChannelDeleteEvent({required super.id, required this.streams});
615+
ChannelDeleteEvent({
616+
required super.id,
617+
this.streams,
618+
required this.streamIds,
619+
}) : assert(streams != null || streamIds != null);
615620

616621
factory ChannelDeleteEvent.fromJson(Map<String, dynamic> json) =>
617622
_$ChannelDeleteEventFromJson(json);
@@ -620,6 +625,18 @@ class ChannelDeleteEvent extends ChannelEvent {
620625
Map<String, dynamic> toJson() => _$ChannelDeleteEventToJson(this);
621626
}
622627

628+
@JsonSerializable(fieldRename: FieldRename.snake)
629+
class ZulipStreamId {
630+
final int streamId;
631+
632+
ZulipStreamId({required this.streamId});
633+
634+
factory ZulipStreamId.fromJson(Map<String, dynamic> json) =>
635+
_$ZulipStreamIdFromJson(json);
636+
637+
Map<String, dynamic> toJson() => _$ZulipStreamIdToJson(this);
638+
}
639+
623640
/// A [ChannelEvent] with op `update`: https://zulip.com/api/get-events#stream-update
624641
@JsonSerializable(fieldRename: FieldRename.snake)
625642
class ChannelUpdateEvent extends ChannelEvent {

lib/api/model/events.g.dart

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/model/channel.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,16 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
370370
// details will come in a later `subscription` event.)
371371

372372
case ChannelDeleteEvent():
373-
for (final stream in event.streams) {
374-
assert(identical(streams[stream.streamId], streamsByName[stream.name]));
375-
assert(subscriptions[stream.streamId] == null
376-
|| identical(subscriptions[stream.streamId], streams[stream.streamId]));
377-
streams.remove(stream.streamId);
378-
streamsByName.remove(stream.name);
379-
subscriptions.remove(stream.streamId);
373+
final channelIds = event.streamIds ?? event.streams!.map((e) => e.streamId);
374+
for (final channelId in channelIds) {
375+
final channel = streams[channelId];
376+
if (channel == null) break;
377+
assert(identical(streams[channel.streamId], streamsByName[channel.name]));
378+
assert(subscriptions[channelId] == null
379+
|| identical(subscriptions[channelId], streams[channelId]));
380+
streams.remove(channel.streamId);
381+
streamsByName.remove(channel.name);
382+
subscriptions.remove(channel.streamId);
380383
}
381384

382385
case ChannelUpdateEvent():

test/model/store_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ void main() {
862862
// Then prepare an event on which handleEvent will throw
863863
// because it hits that broken invariant.
864864
connection.prepare(json: GetEventsResult(events: [
865-
ChannelDeleteEvent(id: 1, streams: [stream]),
865+
ChannelDeleteEvent(id: 1, streamIds: [stream.streamId]),
866866
], queueId: null).toJson());
867867
}
868868

0 commit comments

Comments
 (0)