Skip to content

Commit

Permalink
api: Change streamPostPolicy to JsonEnum
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpengi committed Nov 14, 2023
1 parent e7fe06c commit 7b6a7e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
25 changes: 23 additions & 2 deletions lib/api/model/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ class ZulipStream {
final bool historyPublicToSubscribers;
final int? messageRetentionDays;

final int streamPostPolicy; // TODO enum
// final bool isAnnouncementOnly; // deprecated; ignore
final StreamPostPolicy streamPostPolicy;
// final bool isAnnouncementOnly; // deprecated for `streamPostPolicy`; ignore

final int? canRemoveSubscribersGroupId; // TODO(server-6)

Expand All @@ -275,6 +275,27 @@ class ZulipStream {
Map<String, dynamic> toJson() => _$ZulipStreamToJson(this);
}

/// Policy for which users can post to the stream.
///
/// For docs, search for "stream_post_policy"
/// in <https://zulip.com/api/get-stream-by-id>
@JsonEnum(valueField: 'apiValue')
enum StreamPostPolicy{
any(apiValue: 1),
admin(apiValue: 2),
member(apiValue: 3),
moderator(apiValue: 4),
unknown(apiValue: null);

const StreamPostPolicy({
required this.apiValue,
});

final int? apiValue;

int? toJson() => apiValue;
}

/// As in `subscriptions` in the initial snapshot.
///
/// For docs, search for "subscriptions:"
Expand Down
11 changes: 10 additions & 1 deletion lib/api/model/model.g.dart

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

4 changes: 2 additions & 2 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ZulipStream stream({
bool? isWebPublic,
bool? historyPublicToSubscribers,
int? messageRetentionDays,
int? streamPostPolicy,
StreamPostPolicy? streamPostPolicy,
int? canRemoveSubscribersGroupId,
}) {
return ZulipStream(
Expand All @@ -117,7 +117,7 @@ ZulipStream stream({
isWebPublic: isWebPublic ?? false,
historyPublicToSubscribers: historyPublicToSubscribers ?? true,
messageRetentionDays: messageRetentionDays,
streamPostPolicy: streamPostPolicy ?? 1,
streamPostPolicy: streamPostPolicy ?? StreamPostPolicy.any,
canRemoveSubscribersGroupId: canRemoveSubscribersGroupId ?? 123,
);
}
Expand Down

0 comments on commit 7b6a7e8

Please sign in to comment.