Skip to content

Commit 1193a12

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 which used to be an array of the just-deleted channel objects is now an array of objects which only contains IDs of the just-deleted channels (the app throws away its event queue and reregisters before this commit). - The same `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 channels IDs. Related CZO discussion: https://chat.zulip.org/#narrow/channel/378-api-design/topic/stream.20deletion.20events/near/2284969
1 parent 1b968fc commit 1193a12

File tree

7 files changed

+37
-18
lines changed

7 files changed

+37
-18
lines changed

lib/api/model/events.dart

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,24 @@ class ChannelDeleteEvent extends ChannelEvent {
616616
@JsonKey(includeToJson: true)
617617
String get op => 'delete';
618618

619-
final List<ZulipStream> streams;
619+
@JsonKey(name: 'stream_ids', readValue: _readChannelIds)
620+
final List<int> channelIds;
621+
622+
// TODO(server-10) simplify away; rely on stream_ids
623+
static List<int> _readChannelIds(Map<dynamic, dynamic> json, String key) {
624+
final channelIds = json['stream_ids'] as List<dynamic>?;
625+
if (channelIds != null) return channelIds.map((id) => id as int).toList();
620626

621-
ChannelDeleteEvent({required super.id, required this.streams});
627+
final channels = json['streams'] as List<dynamic>;
628+
return channels
629+
.map((c) => (c as Map<String, dynamic>)['stream_id'] as int)
630+
.toList();
631+
}
632+
633+
ChannelDeleteEvent({
634+
required super.id,
635+
required this.channelIds,
636+
});
622637

623638
factory ChannelDeleteEvent.fromJson(Map<String, dynamic> json) =>
624639
_$ChannelDeleteEventFromJson(json);

lib/api/model/events.g.dart

Lines changed: 6 additions & 4 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: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,15 @@ class ChannelStoreImpl extends HasUserStore with ChannelStore {
398398
// details will come in a later `subscription` event.)
399399

400400
case ChannelDeleteEvent():
401-
for (final stream in event.streams) {
402-
assert(identical(streams[stream.streamId], streamsByName[stream.name]));
403-
assert(subscriptions[stream.streamId] == null
404-
|| identical(subscriptions[stream.streamId], streams[stream.streamId]));
405-
streams.remove(stream.streamId);
406-
streamsByName.remove(stream.name);
407-
subscriptions.remove(stream.streamId);
401+
for (final channelId in event.channelIds) {
402+
final channel = streams[channelId];
403+
if (channel == null) break;
404+
assert(identical(streams[channel.streamId], streamsByName[channel.name]));
405+
assert(subscriptions[channelId] == null
406+
|| identical(subscriptions[channelId], streams[channelId]));
407+
streams.remove(channel.streamId);
408+
streamsByName.remove(channel.name);
409+
subscriptions.remove(channel.streamId);
408410
}
409411

410412
case ChannelUpdateEvent():

lib/model/message.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ class MessageStoreImpl extends HasChannelStore with MessageStore, _OutboxMessage
556556
}
557557

558558
void handleChannelDeleteEvent(ChannelDeleteEvent event) {
559-
final channelIds = event.streams.map((channel) => channel.streamId);
560-
_handleSubscriptionsRemoved(channelIds);
559+
_handleSubscriptionsRemoved(event.channelIds);
561560
}
562561

563562
void handleSubscriptionRemoveEvent(SubscriptionRemoveEvent event) {

test/model/message_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ void main() {
634634
// Subscribe, to mark message as not-stale, setting up another check…
635635
await store.addSubscription(eg.subscription(otherChannel));
636636

637-
await store.handleEvent(ChannelDeleteEvent(id: 1, streams: [otherChannel]));
637+
await store.handleEvent(ChannelDeleteEvent(id: 1, channelIds: [otherChannel.streamId]));
638638
// Message was in a channel that became unknown, so clobber.
639639
checkClobber();
640640
});

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, channelIds: [stream.streamId]),
866866
], queueId: null).toJson());
867867
}
868868

test/widgets/action_sheet_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,8 @@ void main() {
340340

341341
testWidgets('unknown channel', (tester) async {
342342
await prepare();
343-
await store.handleEvent(ChannelDeleteEvent(id: 1, streams: [someChannel]));
343+
await store.handleEvent(ChannelDeleteEvent(id: 1,
344+
channelIds: [someChannel.streamId]));
344345
check(store.streams[someChannel.streamId]).isNull();
345346
await showFromTopicListAppBar(tester);
346347
check(findInHeader(find.byType(Icon))).findsNothing();

0 commit comments

Comments
 (0)