Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/api/model/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,38 @@ class ChannelDeleteEvent extends ChannelEvent {
@JsonKey(includeToJson: true)
String get op => 'delete';

final List<ZulipStream> streams;
@JsonKey(readValue: _readChannelIds, includeToJson: false)
final List<int> channelIds;

// TODO(server-10) simplify away; rely on stream_ids
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

api: Update ChannelDeleteEvent to match new API changes

Let's link to #api design > stream deletion events @ 💬 in the commit message.

(Also a nit: the symptom is described in that discussion; it's noticeable but it's not as bad as crashing the app.)

static List<int> _readChannelIds(Map<dynamic, dynamic> json, String key) {
final channelIds = json['stream_ids'] as List<dynamic>?;
if (channelIds != null) channelIds.map((id) => id as int).toList();

final channels = json['streams'] as List<dynamic>;
return channels
.map((c) => (c as Map<String, dynamic>)['stream_id'] as int)
.toList();
}

ChannelDeleteEvent({required super.id, required this.streams});
ChannelDeleteEvent({
required super.id,
required this.channelIds,
});

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

@override
Map<String, dynamic> toJson() => _$ChannelDeleteEventToJson(this);
Map<String, dynamic> toJson() {
// TODO(server-10) simplify away; rely on stream_ids
final result = _$ChannelDeleteEventToJson(this);
result['stream_ids'] = channelIds;
result['streams'] = [
for (final id in channelIds) {'stream_id': id}
];
return result;
}
}

/// A [ChannelEvent] with op `update`: https://zulip.com/api/get-events#stream-update
Expand Down Expand Up @@ -683,6 +706,8 @@ class ChannelUpdateEvent extends ChannelEvent {
return value as int?;
case ChannelPropertyName.channelPostPolicy:
return ChannelPostPolicy.fromApiValue(value as int);
case ChannelPropertyName.isRecentlyActive:
return value as bool?;
Comment on lines +709 to +710
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: bump on #1902 (comment)

case ChannelPropertyName.folderId:
return value as int?;
case ChannelPropertyName.canAddSubscribersGroup:
Expand Down
10 changes: 6 additions & 4 deletions lib/api/model/events.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ class ZulipStream {
GroupSettingValue? canSendMessageGroup; // TODO(server-10)
GroupSettingValue? canSubscribeGroup; // TODO(server-10)

bool? isRecentlyActive; // TODO(server-10)
// TODO(server-8): added in FL 199, was previously only on [Subscription] objects
int? streamWeeklyTraffic;

Expand All @@ -681,6 +682,7 @@ class ZulipStream {
required this.canDeleteOwnMessageGroup,
required this.canSendMessageGroup,
required this.canSubscribeGroup,
required this.isRecentlyActive,
required this.streamWeeklyTraffic,
});

Expand All @@ -705,6 +707,7 @@ class ZulipStream {
canDeleteOwnMessageGroup: subscription.canDeleteOwnMessageGroup,
canSendMessageGroup: subscription.canSendMessageGroup,
canSubscribeGroup: subscription.canSubscribeGroup,
isRecentlyActive: subscription.isRecentlyActive,
streamWeeklyTraffic: subscription.streamWeeklyTraffic,
);
}
Expand Down Expand Up @@ -742,6 +745,7 @@ enum ChannelPropertyName {
canDeleteOwnMessageGroup,
canSendMessageGroup,
canSubscribeGroup,
isRecentlyActive,
streamWeeklyTraffic;

/// Get a [ChannelPropertyName] from a raw, snake-case string we recognize, else null.
Expand Down Expand Up @@ -827,6 +831,7 @@ class Subscription extends ZulipStream {
required super.canDeleteOwnMessageGroup,
required super.canSendMessageGroup,
required super.canSubscribeGroup,
required super.isRecentlyActive,
required super.streamWeeklyTraffic,
required this.desktopNotifications,
required this.emailNotifications,
Expand Down
5 changes: 5 additions & 0 deletions lib/api/model/model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading