Skip to content

Commit a12b0ee

Browse files
committed
api: Change streamPostPolicy to JsonEnum
1 parent af94f47 commit a12b0ee

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed

lib/api/model/model.dart

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ class ZulipStream {
249249
final bool historyPublicToSubscribers;
250250
final int? messageRetentionDays;
251251

252-
final int streamPostPolicy; // TODO enum
253-
// final bool isAnnouncementOnly; // deprecated; ignore
252+
final StreamPostPolicy streamPostPolicy;
253+
// final bool isAnnouncementOnly; // deprecated for `streamPostPolicy`; ignore
254254

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

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

278+
/// Policy for which users can post to the stream.
279+
///
280+
/// For docs, search for "stream_post_policy"
281+
/// in <https://zulip.com/api/get-stream-by-id>
282+
@JsonEnum(valueField: 'apiValue')
283+
enum StreamPostPolicy{
284+
any(apiValue: 1),
285+
admin(apiValue: 2),
286+
member(apiValue: 3),
287+
moderator(apiValue: 4),
288+
unknown(apiValue: null);
289+
290+
const StreamPostPolicy({
291+
required this.apiValue,
292+
});
293+
294+
final int? apiValue;
295+
296+
int? toJson() => apiValue;
297+
}
298+
278299
/// As in `subscriptions` in the initial snapshot.
279300
///
280301
/// For docs, search for "subscriptions:"

lib/api/model/model.g.dart

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/example_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ZulipStream stream({
103103
bool? isWebPublic,
104104
bool? historyPublicToSubscribers,
105105
int? messageRetentionDays,
106-
int? streamPostPolicy,
106+
StreamPostPolicy? streamPostPolicy,
107107
int? canRemoveSubscribersGroupId,
108108
}) {
109109
return ZulipStream(
@@ -117,7 +117,7 @@ ZulipStream stream({
117117
isWebPublic: isWebPublic ?? false,
118118
historyPublicToSubscribers: historyPublicToSubscribers ?? true,
119119
messageRetentionDays: messageRetentionDays,
120-
streamPostPolicy: streamPostPolicy ?? 1,
120+
streamPostPolicy: streamPostPolicy ?? StreamPostPolicy.any,
121121
canRemoveSubscribersGroupId: canRemoveSubscribersGroupId ?? 123,
122122
);
123123
}

0 commit comments

Comments
 (0)