-
Notifications
You must be signed in to change notification settings - Fork 310
Edit-message (5/n): Fix bug where compose progress can be lost on new event queue #1482
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
Conversation
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! The fix looks good to me with manual testing. Left some comments.
test/widgets/compose_box_test.dart
Outdated
await tester.pump(); | ||
|
||
// new store replaces the old one | ||
final newStore = testBinding.globalStore.perAccountSync(eg.selfAccount.id)!; |
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 this?
final newStore = testBinding.globalStore.perAccountSync(eg.selfAccount.id)!; | |
final newStore = testBinding.globalStore.perAccountSync(store.accountId)!; |
This way we don't rely on prepareComposeBox
using a specific value for self-account ID.
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.
Ooh, thanks for thinking of this.
test/widgets/compose_box_test.dart
Outdated
// new store has the same basic boring data so the compose box | ||
// has its content input instead of no-posting-permission error banner | ||
// TODO instead, add data by preparing new store's initial snapshot | ||
await newStore.addStream(channel); | ||
await newStore.addUser(eg.selfUser); |
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.
Maybe the TODO just calls for moving setup code into the initial snapshot in prepareComposeBox
?
await testBinding.globalStore.add(selfAccount, eg.initialSnapshot(
+ realmUsers: [selfUser, ...otherUsers],
+ streams: streams,
zulipFeatureLevel: zulipFeatureLevel,
realmMandatoryTopics: mandatoryTopics,
));
store = await testBinding.globalStore.perAccount(selfAccount.id);
-
- await store.addUsers([selfUser, ...otherUsers]);
- await store.addStreams(streams);
The initial call to testBinding.globalStore.add
sets the initial snapshot that will also be used when reloading the store.
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.
The initial call to
testBinding.globalStore.add
sets the initial snapshot that will also be used when reloading the store.
Ohh, I didn't realize; thanks for pointing this out.
lib/widgets/compose_box.dart
Outdated
if (_controller == null) { | ||
_setNewControllerForNarrow(newStore); | ||
} else { |
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: perhaps we can return early here and de-indent the else-block
8524b1e
to
6bc9bb7
Compare
Thanks for the review! Revision pushed. |
Thanks! Marking for Greg's review. |
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 both! Looks good; small comments.
lib/widgets/compose_box.dart
Outdated
switch (_controller) { | ||
case StreamComposeBoxController(): | ||
(_controller as StreamComposeBoxController).topic.store = newStore; |
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 can be simplified by extracting a local variable as a copy of the field, so that type promotion works:
switch (_controller) { | |
case StreamComposeBoxController(): | |
(_controller as StreamComposeBoxController).topic.store = newStore; | |
final controller = _controller; | |
switch (controller) { | |
case StreamComposeBoxController(): | |
controller.topic.store = newStore; |
lib/widgets/compose_box.dart
Outdated
case null: | ||
assert(false); | ||
} |
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: Similarly if the local is used for the initial null check, then the analyzer sees this case is impossible.
lib/widgets/compose_box.dart
Outdated
} | ||
} | ||
|
||
void _setNewControllerForNarrow(PerAccountStore store) { |
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: drop "for narrow"? Seems like it's just the new controller that's appropriate for this compose box.
And factor out a helper for the part that reads `widget.narrow` and sets a new controller accordingly; we'll use this helper for the edit-message UI, to reset the compose box at the end of an edit-message session. Fixes: zulip#1470
6bc9bb7
to
2683df0
Compare
Thanks! Revision pushed. |
Thanks! Looks good; merging. |
And factor out a helper for the part that reads
widget.narrow
and sets a new controller accordingly; we'll use this helper for the edit-message UI, to reset the compose box at the end of an edit-message session.Fixes: #1470