-
Notifications
You must be signed in to change notification settings - Fork 471
[1/6] api: Audit enums to handle unknown values where appropriate #2339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
4983a7c
80bed4b
bb5b96a
f854928
9c56c05
1aa4aac
945522d
acf3ce5
be1721a
cce7d5b
e6bad69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1289,6 +1289,34 @@ sealed class Message<T extends Conversation> extends MessageBase<T> { | |||||
| Map<String, dynamic> toJson(); | ||||||
| } | ||||||
|
|
||||||
| /// As in [DeleteMessageEvent.messageType], | ||||||
| /// [UpdateMessageFlagsMessageDetail.type], | ||||||
| /// or [TypingEvent.messageType]. | ||||||
| @JsonEnum(alwaysCreate: true) | ||||||
| enum MessageType { | ||||||
| stream, | ||||||
| direct; | ||||||
|
|
||||||
| factory fromJson(String json) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Don't think we've used nameless constructors yet.
Suggested change
Also without the name, it's easy to confuse it as a method. |
||||||
| if (json == 'private') json = 'direct'; // TODO(server-future) | ||||||
| return $enumDecode(_$MessageTypeEnumMap, json); | ||||||
|
Comment on lines
+1301
to
1303
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Now that there are more than one cases, let's use |
||||||
| } | ||||||
| } | ||||||
|
|
||||||
| class MessageTypeConverter extends JsonConverter<MessageType, String> { | ||||||
| const MessageTypeConverter(); | ||||||
|
|
||||||
| @override | ||||||
| MessageType fromJson(String json) { | ||||||
| return MessageType.fromJson(json); | ||||||
| } | ||||||
|
|
||||||
| @override | ||||||
| String toJson(MessageType object) { | ||||||
| return _$MessageTypeEnumMap[object]!; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// https://zulip.com/api/update-message-flags#available-flags | ||||||
| @JsonEnum(fieldRename: FieldRename.snake, alwaysCreate: true) | ||||||
| enum MessageFlag { | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This too is technically out of scope for #1982, but it's fine to have.