diff --git a/lib/api/model/model.dart b/lib/api/model/model.dart index 4c1e78a4e1..182daad19f 100644 --- a/lib/api/model/model.dart +++ b/lib/api/model/model.dart @@ -312,36 +312,9 @@ enum StreamPostPolicy { /// For docs, search for "subscriptions:" /// in . @JsonSerializable(fieldRename: FieldRename.snake) -class Subscription { - // First, fields that are about the stream and not the user's relation to it. - // These are largely the same as in [ZulipStream]. - - final int streamId; - final String name; - final String description; - final String renderedDescription; - - final int dateCreated; - final int? firstMessageId; - final int? streamWeeklyTraffic; - - final bool inviteOnly; - final bool isWebPublic; - final bool historyPublicToSubscribers; - final int? messageRetentionDays; +class Subscription extends ZulipStream { // final List subscribers; // we register with includeSubscribers false - final StreamPostPolicy streamPostPolicy; - // final bool? isAnnouncementOnly; // deprecated for `streamPostPolicy`; ignore - - // TODO(server-6): `canRemoveSubscribersGroupId` added in FL 142 - // TODO(server-8): in FL 197 renamed to `canRemoveSubscribersGroup` - @JsonKey(readValue: _readCanRemoveSubscribersGroup) - final int? canRemoveSubscribersGroup; - - // Then, fields that are specific to the subscription, - // i.e. the user's relationship to the stream. - final bool? desktopNotifications; final bool? emailNotifications; final bool? wildcardMentionsNotify; @@ -349,23 +322,25 @@ class Subscription { final bool? audibleNotifications; final bool pinToTop; - final bool isMuted; // final bool? inHomeView; // deprecated; ignore final String color; - static int? _readCanRemoveSubscribersGroup(Map json, String key) { - return json[key] ?? json['can_remove_subscribers_group_id']; - } - Subscription({ - required this.streamId, - required this.name, - required this.description, - required this.renderedDescription, - required this.dateCreated, - required this.inviteOnly, + required super.streamId, + required super.name, + required super.description, + required super.renderedDescription, + required super.dateCreated, + required super.firstMessageId, + required super.inviteOnly, + required super.isWebPublic, + required super.historyPublicToSubscribers, + required super.messageRetentionDays, + required super.streamPostPolicy, + required super.canRemoveSubscribersGroup, + required super.streamWeeklyTraffic, required this.desktopNotifications, required this.emailNotifications, required this.wildcardMentionsNotify, @@ -373,19 +348,13 @@ class Subscription { required this.audibleNotifications, required this.pinToTop, required this.isMuted, - required this.isWebPublic, required this.color, - required this.streamPostPolicy, - required this.messageRetentionDays, - required this.historyPublicToSubscribers, - required this.firstMessageId, - required this.streamWeeklyTraffic, - required this.canRemoveSubscribersGroup, }); factory Subscription.fromJson(Map json) => _$SubscriptionFromJson(json); + @override Map toJson() => _$SubscriptionToJson(this); } diff --git a/lib/api/model/model.g.dart b/lib/api/model/model.g.dart index 1cd0b0e5be..ecc8b11d48 100644 --- a/lib/api/model/model.g.dart +++ b/lib/api/model/model.g.dart @@ -193,7 +193,16 @@ Subscription _$SubscriptionFromJson(Map json) => Subscription( description: json['description'] as String, renderedDescription: json['rendered_description'] as String, dateCreated: json['date_created'] as int, + firstMessageId: json['first_message_id'] as int?, inviteOnly: json['invite_only'] as bool, + isWebPublic: json['is_web_public'] as bool, + historyPublicToSubscribers: json['history_public_to_subscribers'] as bool, + messageRetentionDays: json['message_retention_days'] as int?, + streamPostPolicy: + $enumDecode(_$StreamPostPolicyEnumMap, json['stream_post_policy']), + canRemoveSubscribersGroup: ZulipStream._readCanRemoveSubscribersGroup( + json, 'can_remove_subscribers_group') as int?, + streamWeeklyTraffic: json['stream_weekly_traffic'] as int?, desktopNotifications: json['desktop_notifications'] as bool?, emailNotifications: json['email_notifications'] as bool?, wildcardMentionsNotify: json['wildcard_mentions_notify'] as bool?, @@ -201,16 +210,7 @@ Subscription _$SubscriptionFromJson(Map json) => Subscription( audibleNotifications: json['audible_notifications'] as bool?, pinToTop: json['pin_to_top'] as bool, isMuted: json['is_muted'] as bool, - isWebPublic: json['is_web_public'] as bool, color: json['color'] as String, - streamPostPolicy: - $enumDecode(_$StreamPostPolicyEnumMap, json['stream_post_policy']), - messageRetentionDays: json['message_retention_days'] as int?, - historyPublicToSubscribers: json['history_public_to_subscribers'] as bool, - firstMessageId: json['first_message_id'] as int?, - streamWeeklyTraffic: json['stream_weekly_traffic'] as int?, - canRemoveSubscribersGroup: Subscription._readCanRemoveSubscribersGroup( - json, 'can_remove_subscribers_group') as int?, ); Map _$SubscriptionToJson(Subscription instance) => @@ -221,13 +221,13 @@ Map _$SubscriptionToJson(Subscription instance) => 'rendered_description': instance.renderedDescription, 'date_created': instance.dateCreated, 'first_message_id': instance.firstMessageId, - 'stream_weekly_traffic': instance.streamWeeklyTraffic, 'invite_only': instance.inviteOnly, 'is_web_public': instance.isWebPublic, 'history_public_to_subscribers': instance.historyPublicToSubscribers, 'message_retention_days': instance.messageRetentionDays, 'stream_post_policy': instance.streamPostPolicy, 'can_remove_subscribers_group': instance.canRemoveSubscribersGroup, + 'stream_weekly_traffic': instance.streamWeeklyTraffic, 'desktop_notifications': instance.desktopNotifications, 'email_notifications': instance.emailNotifications, 'wildcard_mentions_notify': instance.wildcardMentionsNotify,