-
Notifications
You must be signed in to change notification settings - Fork 373
model: Prevent duplicate flags when processing update_message_flags. #2033
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?
model: Prevent duplicate flags when processing update_message_flags. #2033
Conversation
6570cf0 to
2197c45
Compare
chrisbobbe
left a comment
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.
Thanks! Small comments below.
Also some commit-message nits:
Please keep the body of your commit message word-wrapped to 68 columns.
In this case the Fixes line suffices to explain the change, so you don't need the two paragraphs above that.
Also the Fixes line should read Fixes #1986. (note the period).
test/model/message_test.dart
Outdated
| // Should verify no notifications since no actual change happened | ||
| // But current implementation might notify anyway if it doesn't check for change | ||
| // optimization. The main point is flags list shouldn't have duplicates. | ||
| // Let's check the flags first. |
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 appreciate wanting to explain this 🙂 but I think we can cut this comment; the test is about an edge case that should be rare (in the fetch-event race) and an extra notifyListeners isn't a significant concern here.
2197c45 to
9329d2f
Compare
|
Thanks! I've removed the test comments and updated the commit message formatting |
chrisbobbe
left a comment
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.
Thanks! Small comments below, otherwise LGTM.
| if (isAdd && (event as UpdateMessageFlagsAddEvent).all) { | ||
| for (final message in messages.values) { | ||
| message.flags.add(event.flag); | ||
| if (!message.flags.contains(event.flag)) { | ||
| message.flags.add(event.flag); | ||
| } |
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.
Please also write a test exercising this case.
| test('avoid duplicate flags', () async { | ||
| await prepare(); |
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.
| test('avoid duplicate flags', () async { | |
| await prepare(); | |
| test('avoid duplicate flags', () async { | |
| // Regression test for https://github.com/zulip/zulip-flutter/issues/1986 | |
| await prepare(); |
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.
should I add this same comment in new test also?
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.
Yes, I think so; it's applies equally there.
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.
done @chrisbobbe
9329d2f to
9e5f2e9
Compare
|
Done! I have added the new test and your suggested comment. |
9e5f2e9 to
138cd43
Compare
chrisbobbe
left a comment
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.
Thanks! One small comment below, and I'll also mark this for Greg's review.
| check(store).messages.values.single.flags.deepEquals([MessageFlag.read]); | ||
| }); | ||
|
|
||
| test('handle update_message_flags: add flag "all" is idempotent', () async { |
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'd like to give the two new tests more similar descriptions, so it's more obvious that they're testing very similar logic. How about:
- 'prevent duplicate flags, when all: false'
- 'prevent duplicate flags, when all: true'
or similar.
gnprice
left a comment
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.
Thanks @sarafarajnasardi for taking care of this, and thanks @chrisbobbe for the previous reviews!
Generally this looks good. Some small comments, in addition to the one Chris makes above.
| final m1 = eg.streamMessage(flags: [MessageFlag.read]); | ||
| final m2 = eg.streamMessage(flags: []); |
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.
nit:
| final m1 = eg.streamMessage(flags: [MessageFlag.read]); | |
| final m2 = eg.streamMessage(flags: []); | |
| final message1 = eg.streamMessage(flags: [MessageFlag.read]); | |
| final message2 = eg.streamMessage(flags: []); |
This point about avoiding abbreviations, in the Flutter upstream style guide, applies equally in Zulip:
https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#avoid-abbreviations
(And not only in the mobile repo — in fact I think Tim applies it more strongly than I do, and we've been doing so since long before we used Flutter.)
| check(store.messages[m1.id]!.flags).deepEquals([MessageFlag.read]); | ||
| check(store.messages[m2.id]!.flags).deepEquals([MessageFlag.read]); |
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.
nit: Conversely, for making this a bit more compact again, see the test cases with "message1" and "message2" earlier in this group. Those give examples of how the package:checks API enables some handy shorthands.
| await store.handleEvent(UpdateMessageFlagsAddEvent( | ||
| id: 1, |
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.
nit: like the other cases in this group, use mkAddEvent for brevity and clarity
|
Oh and a commit-message nit: This should have a more specific prefix (vs "model:" which is quite general). To see examples, try Plus one very small nit: in this repo we don't use a period at the end of the summary line. |
Previously, the event handler would unconditionally add flags to the message's flag list. If a flag (like 'read') was already present, this created duplicates, which broke subsequent removal operations.
This commit adds a check to ensure the flag is not already present before adding it, making the operation idempotent.
Fixes #1986