Skip to content
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

autocomplete: Add user avatars to user-mention autocompletes #590

Merged

Conversation

sm-sayedi
Copy link
Collaborator

When mentioning users, their avatars are shown beside their names in the autocomplete popup.

Fixes: #227

@sm-sayedi sm-sayedi force-pushed the issue-227-avatars-in-user-mention-autocompletes branch 2 times, most recently from a78d4e0 to 0cf6caf Compare March 25, 2024 18:30
@sm-sayedi sm-sayedi marked this pull request as ready for review March 25, 2024 18:32
@sm-sayedi
Copy link
Collaborator Author

Thanks for the review. Revision pushed with tests included.

@sm-sayedi sm-sayedi force-pushed the issue-227-avatars-in-user-mention-autocompletes branch from 0cf6caf to 5633215 Compare March 26, 2024 08:24
Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sm-sayedi! Generally this looks good. Various comments below, all fairly small.

lib/model/autocomplete.dart Outdated Show resolved Hide resolved
lib/model/autocomplete.dart Outdated Show resolved Hide resolved
lib/model/autocomplete.dart Show resolved Hide resolved
lib/widgets/autocomplete.dart Outdated Show resolved Hide resolved
lib/widgets/autocomplete.dart Show resolved Hide resolved
test/widgets/autocomplete_test.dart Outdated Show resolved Hide resolved
test/widgets/autocomplete_test.dart Outdated Show resolved Hide resolved
test/widgets/autocomplete_test.dart Outdated Show resolved Hide resolved
@@ -39,6 +41,8 @@ Future<Finder> setupToComposeInput(WidgetTester tester, {
messages: [message],
).toJson());

prepareBoringImageHttpClient();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this call, it becomes part of the interface of this setupToComposeInput function that its caller needs to set debugNetworkImageHttpClientProvider back to null before the end of the test. So this function should gain a note to that effect in its dartdoc, just like prepareBoringImageHttpClient has.

(It's regrettable that that reset can't be done using addTearDown, so that callers and callers' callers wouldn't have to care like this. There's an open issue upstream about that, relating to debugNetworkImageHttpClientProvider and a bunch of other Flutter test knobs of a similar flavor. I don't have the link offhand, but it'd be good to track it down again and then put a comment on prepareBoringImageHttpClient pointing to that.)

Copy link
Collaborator Author

@sm-sayedi sm-sayedi Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found a closed issue upstream. This one also seemed closer to this, but wasn't sure to add it to the prepareBoringImageHttpClient comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking! Found the one I was thinking of (which it turns out is one I filed 🙂), and added a comment: 68116a2

Looks like there was a backlink to it in the second issue you found:
image
as that issue is basically a different specific case of the issue I had in mind.

test/widgets/content_test.dart Show resolved Hide resolved
The WildcardMentionAutocompleteResult and
UserGroupMentionAutocompleteResult classes are not
used, so better to remove them for now.
@sm-sayedi sm-sayedi force-pushed the issue-227-avatars-in-user-mention-autocompletes branch from 5633215 to 957338d Compare March 26, 2024 20:55
@sm-sayedi
Copy link
Collaborator Author

Thanks for the review. Revision pushed.

Also requested to work on issue 100 simultaneously!

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks great — just two nits below.

I'll fix those up and merge.

Comment on lines 80 to 82
Image(image: NetworkImage(url: var imageUrl)) when imageUrl == url => true,
_ => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: because the first pattern is so long, the result "true" gets a bit hard to spot when it's off at the end of that line. So:

Suggested change
Image(image: NetworkImage(url: var imageUrl)) when imageUrl == url => true,
_ => false,
Image(image: NetworkImage(url: var imageUrl)) when imageUrl == url
=> true,
_ => false,

check(tester.widgetList(find.text('User One'))).isEmpty();
tester.widget(find.text('User Two'));
tester.widget(find.text('User Three'));
checkUserShown(user1, store, expected: false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version is fine. But for other situations where the shared context is more verbose than just store, and so it's more of a pain to have to pass it each time, there are two solutions we often use:

  • The helper function can be local within the test function, so that it sees the same store as a local.
  • The context like store can be a late variable that's declared up at the top of a test group, or of the whole test main, and that gets initialized afresh by a helper function that each test case calls. Those helpers are often named prepare or of the form prepareFoo.

///
/// The caller must set [debugNetworkImageHttpClientProvider] back to null
/// before the end of the test.
FakeImageHttpClient prepareBoringImageHttpClient() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefix for this commit:

f3aebc9 autocomplete [nfc]: Pull prepareBoringImageHttpClient out to toplevel

should be autocomplete test [nfc]:, to indicate that it's only touching the test code

(And then the "nfc" part means that on top of that, it has only an NFC effect on even the test code.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh and looking again, it's not really about the autocomplete tests in particular, so autocomplete isn't quite right.

I'll make it content test [nfc], since it is in that file. Could also have made it just test [nfc], since the point is it's now exporting this for other tests.

Moving `prepareBoringImageHttpClient` method to
the toplevel of the file will make it reusable in
other files.
@gnprice gnprice force-pushed the issue-227-avatars-in-user-mention-autocompletes branch from 957338d to 919cf12 Compare March 27, 2024 02:39
@gnprice gnprice merged commit 919cf12 into zulip:main Mar 27, 2024
1 check passed
gnprice added a commit that referenced this pull request Mar 27, 2024
@sm-sayedi
Copy link
Collaborator Author

Thanks @gnprice for all this and for the instructive comments!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autocomplete: Add user avatars to user-mention autocompletes
2 participants