-
Notifications
You must be signed in to change notification settings - Fork 383
api: Add update_message_flags events #299
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
Changes from all commits
5d2e6fd
fbe72e8
4568db8
68fe7ba
8da16f1
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 |
|---|---|---|
|
|
@@ -10,19 +10,6 @@ import 'events_checks.dart'; | |
| import 'model_checks.dart'; | ||
|
|
||
| void main() { | ||
| test('message: move flags into message object', () { | ||
| final message = eg.streamMessage(); | ||
| MessageEvent mkEvent(List<MessageFlag> flags) => Event.fromJson({ | ||
| 'type': 'message', | ||
| 'id': 1, | ||
| 'message': (deepToJson(message) as Map<String, dynamic>)..remove('flags'), | ||
| 'flags': flags.map((f) => f.toJson()).toList(), | ||
| }) as MessageEvent; | ||
| check(mkEvent(message.flags)).message.jsonEquals(message); | ||
| check(mkEvent([])).message.flags.deepEquals([]); | ||
| check(mkEvent([MessageFlag.read])).message.flags.deepEquals([MessageFlag.read]); | ||
| }); | ||
|
|
||
| test('user_settings: all known settings have event handling', () { | ||
| final dataClassFieldNames = UserSettings.debugKnownNames; | ||
| final enumNames = UserSettingName.values.map((n) => n.name); | ||
|
|
@@ -42,4 +29,35 @@ void main() { | |
| ' on the pattern of the existing cases.' | ||
| ).isEmpty(); | ||
| }); | ||
|
|
||
| test('message: move flags into message object', () { | ||
| final message = eg.streamMessage(); | ||
| MessageEvent mkEvent(List<MessageFlag> flags) => Event.fromJson({ | ||
| 'type': 'message', | ||
| 'id': 1, | ||
| 'message': (deepToJson(message) as Map<String, dynamic>)..remove('flags'), | ||
| 'flags': flags.map((f) => f.toJson()).toList(), | ||
| }) as MessageEvent; | ||
| check(mkEvent(message.flags)).message.jsonEquals(message); | ||
| check(mkEvent([])).message.flags.deepEquals([]); | ||
| check(mkEvent([MessageFlag.read])).message.flags.deepEquals([MessageFlag.read]); | ||
| }); | ||
|
|
||
| test('update_message_flags/remove: require messageDetails in mark-as-unread', () { | ||
|
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: put the tests in the same order as the code they test |
||
| final baseJson = { | ||
| 'id': 1, | ||
| 'type': 'update_message_flags', | ||
| 'op': 'remove', | ||
| 'flag': 'starred', | ||
| 'messages': [123], | ||
| 'all': false, | ||
| }; | ||
| check(() => UpdateMessageFlagsRemoveEvent.fromJson(baseJson)).returnsNormally(); | ||
| check(() => UpdateMessageFlagsRemoveEvent.fromJson({ | ||
| ...baseJson, 'flag': 'read', | ||
| })).throws(); | ||
| check(() => UpdateMessageFlagsRemoveEvent.fromJson({ | ||
| ...baseJson, 'message_details': {'123': {'type': 'private', 'mentioned': false, 'user_ids': [2]}}, | ||
| })).returnsNormally(); | ||
|
Comment on lines
+59
to
+61
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. This test should set
Collaborator
Author
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. Eep, thanks! 89fd1f7 |
||
| }); | ||
| } | ||
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.
I think we'll probably want a crunchy shell on ensuring that when
typeisprivatewe always haveuserIds, and when it'sstreamwe always havestreamIdandtopic.That is, in zulip-flutter I think we've been pretty successful in making it so that malformed server data can't make us outright crash or misbehave, and instead just interrupts talking to the server (thanks mostly to the autogenerated
fromJsonimplementations), so I'd like to try to hold the line on that as an invariant. And I suspect that doing so in the code that consumes this data, if it's just three independent nullables like this, will be annoying and make that code hard to read.One way to get the crunchy shell would be to have a base class and two subclasses, akin to
Messageitself. But another solution might be more expedient and would also suffice: just have ourfromJsoncheck those conditions, and throw if they're not met, in much the same way as the autogenerated code does when an expected field is missing. For example ourfromJsoncan take a few lines to do that on theMap, before then calling the autogenerated implementation as usual.The downside of that approach is that the consuming code is slightly uglier, with
!operators scattered around, than it would be with subclasses. But I think that's a good trade because there's not that much consuming code for this type, and the subclasses mean significantly more code here at the definitions. (ForMessagethe tradeoff goes heavily the other way, because that's such a fundamental type and so much of our code consumes it.)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.
How about calling the autogenerated implementation first? Then we can do an exhaustive switch on
type, which will be aMessageTypeenum value.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.
Sure.