Skip to content

msglist: Distinguish isBot: true message senders with a bot marker #605

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

Merged
merged 2 commits into from
Apr 9, 2024

Conversation

sm-sayedi
Copy link
Collaborator

@sm-sayedi sm-sayedi commented Mar 29, 2024

A bot icon is shown with the name of the bot users.

Before After

Fixes: #156

@sm-sayedi sm-sayedi marked this pull request as ready for review March 29, 2024 21:02
@@ -484,6 +487,22 @@ void main() {

debugNetworkImageHttpClientProvider = null;
});

testWidgets('Bot user is distinguished by showing an icon', (tester) async {
prepareBoringImageHttpClient();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In the test before this test, I noticed that there was a fake HttpClient set, that could be replaced by calling this method that was factored out in #590.

testWidgets('Updates avatar on RealmUserUpdateEvent', (tester) async {

-  final httpClient = FakeImageHttpClient();
-    debugNetworkImageHttpClientProvider = () => httpClient;
-    httpClient.request.response
-      ..statusCode = HttpStatus.ok
-      ..content = kSolidBlueAvatar;

+  prepareBoringImageHttpClient();
  
}

Is it ok if I add an additional [NFC] commit to this PR with the requested change, or should we just ignore it for now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable to me! 🙂

Copy link
Collaborator

@chrisbobbe chrisbobbe 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 mostly good! Small comments below.

@@ -926,6 +928,10 @@ class MessageWithPossibleSender extends StatelessWidget {
).merge(weightVariableTextStyle(context, wght: 600,
wghtIfPlatformRequestsBold: 900)),
overflow: TextOverflow.ellipsis)),
if (messageSender?.isBot ?? false) ...[
const SizedBox(width: 8),
const Icon(ZulipIcons.bot, size: 18, color: Colors.grey),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's match the color to what the web app uses.

I'm also curious how the 18px size is chosen, and the 8px distance from the user's name. To my eye I think those values might both want to be a bit smaller. What does the web app do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should be fixed. Even on the webapp the bot icon isn't super prominent, and I have no idea why it's blurred.

I saw this comment on CZO, so I decided to go with a more prominent icon. Any recommendations from your side are most welcome!

Copy link
Collaborator Author

@sm-sayedi sm-sayedi Mar 30, 2024

Choose a reason for hiding this comment

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

On the web, the icon size is 12px, the color is rgb(159, 173, 173), and the distance to the user's name is 5px.
With the same properties applied, it looks like this:

Should I go with this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm. To me, that all looks good except the size; I think it looks too small now. The font size in the web app is smaller than in the mobile app, so maybe this icon should be scaled up according to that. Maybe try 15px?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Applied the changes. Updated the description for the new images. Please have a look!

@@ -484,6 +487,22 @@ void main() {

debugNetworkImageHttpClientProvider = null;
});

testWidgets('Bot user is distinguished by showing an icon', (tester) async {
prepareBoringImageHttpClient();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems reasonable to me! 🙂

users: users,
);

tester.widget(find.byIcon(ZulipIcons.bot));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you check specifically that the icon appears next to the sender that is a bot, and also that an icon doesn't appear on the senders that are not bots?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure thing!

@sm-sayedi
Copy link
Collaborator Author

sm-sayedi commented Mar 30, 2024

Thanks for the review! A few comments above.

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 for handling this, and @chrisbobbe for the review!

Other than the things Chris remarked on above, this all looks good to me, except a few nits below.

testWidgets('Bot user is distinguished by showing an icon', (tester) async {
prepareBoringImageHttpClient();

final users = List.generate(3, (index) => eg.user(isBot: index == 0));
Copy link
Member

Choose a reason for hiding this comment

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

This is probably clearer as a list literal with three explicit eg.user calls: [eg.user(isBot: true), eg.user(isBot: false), etc. Not much longer that way, and less logic for the reader to unpack.

Comment on lines 899 to 901
final message = item.message;
final messageSender =
PerAccountStoreWidget.of(context).users[message.senderId];
Copy link
Member

Choose a reason for hiding this comment

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

nit: (two nits)

Suggested change
final message = item.message;
final messageSender =
PerAccountStoreWidget.of(context).users[message.senderId];
final store = PerAccountStoreWidget.of(context);
final message = item.message;
final sender = store.users[message.senderId];

That way the result of PerAccountStoreWidget.of goes into a store local, like in most of our other build methods where it appears. The uniformity is mildly helpful; and this way also makes it maximally easy to add another bit of logic using the store later, without either duplicating the lookup or rewriting these lines.

Separately, most everything within this method is about the particular message message, so a name "sender" communicates basically the same meaning as "message sender". Similarly the existing other locals include senderRow and time, without the added qualifier "message".

@gnprice
Copy link
Member

gnprice commented Apr 1, 2024

Oh and one other nit, in the commit message:

ui: Distinguish `isBot: true` users with a bot marker

Fixes: #156

Let's make the prefix msglist: — that's more specific than "ui", and lets the reader know this is about how we show users in specifically the message list.

Similarly, s/users/message senders/ would further help pin down where in the UI we're talking about (and the resulting summary line is 68 columns, so there's room; summary lines can go a bit over 70).

@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch 4 times, most recently from 14697c4 to 2570ae4 Compare April 1, 2024 08:46
@sm-sayedi
Copy link
Collaborator Author

Thanks for the review! Pushed the latest revision. PTAL!

@sm-sayedi
Copy link
Collaborator Author

sm-sayedi commented Apr 1, 2024

Similarly, s/users/message senders/ would further help pin down where in the UI we're talking about (and the resulting summary line is 68 columns, so there's room; summary lines can go a bit over 70).

Sorry, I am not sure where to add this in the commit message!

@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch from 2570ae4 to e0db6c1 Compare April 1, 2024 09:42
check(nameFinder.evaluate().singleOrNull).isNotNull();
check(botFinder.evaluate().singleOrNull).isNotNull();

final userFinder = find.ancestor(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For a bot user, this evaluates to two results, and that's because there are two Rows that satisfy this finder; one direct parent Row and another, the parent of this parent Row, both are for the same user. To make sure they're for the same user, the following two lines are added just before the finder:

check(nameFinder.evaluate().singleOrNull).isNotNull();
check(botFinder.evaluate().singleOrNull).isNotNull();

This makes sure the fullName text for a user is only shown once on the screen. The bot icon is also checked for being shown just once, but that does not guarantee it belongs to the current user. That check is done by check(userFinder.evaluate()).isNotEmpty().

I hope this test is fine for checking if a bot icon is shown next to a user name.

@sm-sayedi sm-sayedi changed the title ui: Distinguish isBot: true users with a bot marker msglist: Distinguish isBot: true users with a bot marker Apr 1, 2024
@gnprice
Copy link
Member

gnprice commented Apr 1, 2024

Similarly, s/users/message senders/ would further help pin down where in the UI we're talking about (and the resulting summary line is 68 columns, so there's room; summary lines can go a bit over 70).

Sorry, I am not sure where to add this in the commit message!

Ah, that was perhaps a bit cryptic of a way to put it. What I meant by "s/users/message senders/" was "replace 'users' with 'message senders'".

(The s/// syntax is found in various venerable tools from the Unix world. Here's Perl's documentation for it.)

@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch from e0db6c1 to 85051a3 Compare April 1, 2024 18:12
@sm-sayedi sm-sayedi changed the title msglist: Distinguish isBot: true users with a bot marker msglist: Distinguish isBot: true message senders with a bot marker Apr 1, 2024
@sm-sayedi
Copy link
Collaborator Author

Ah, that was perhaps a bit cryptic of a way to put it. What I meant by "s/users/message senders/" was "replace 'users' with 'message senders'".

(The s/// syntax is found in various venerable tools from the Unix world. Here's Perl's documentation for it.)

Thanks, just learned something new! Revision pushed!

@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch 2 times, most recently from 8038a39 to f2cf926 Compare April 3, 2024 01:32
@sm-sayedi sm-sayedi requested a review from gnprice April 3, 2024 01:38
@gnprice
Copy link
Member

gnprice commented Apr 3, 2024

Thanks for the revision!

This all looks good to me except one more commit-message nit:
23b1fe1 msglist-test [nfc]: Refactor some code to use prepareBoringImageHttpClient
f2cf926 msglist: Distinguish isBot: true message senders with a bot marker

For that first commit, the prefix should be msglist test [nfc]:, with a space, rather than msglist-test [nfc]:. In general if you look at git log --oneline, you'll see that the "test" modifier is always separated by a space.

Other than that I'll leave this for @chrisbobbe to re-review for the icon size and placement, and anything else he notices, and then merge.

@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch from f2cf926 to 50d079c Compare April 3, 2024 23:58
@sm-sayedi sm-sayedi requested a review from chrisbobbe April 4, 2024 00:03
@sm-sayedi
Copy link
Collaborator Author

Thanks for the review! Revision pushed.

Now waiting for a review from your side @chrisbobbe!

…Client`

In the test ('Updates avatar on RealmUserUpdateEvent'),
the code for setting a `FakeImageHttpClient` is
replaced by the `prepareBoringImageHttpClient` function.
@sm-sayedi sm-sayedi force-pushed the issue-156-distinguish-bot-users branch from 50d079c to 8c0f9ae Compare April 8, 2024 02:05
@chrisbobbe
Copy link
Collaborator

Thanks, looks good to me! Merging.

After this, there are still some places in the UI where we show the name of a bot user without making it clear it's a bot. For example, it would probably be helpful to show the bot icon next to a bot user's name on the profile page (ProfilePage). I'm not sure if we need to show the icon in all the places where names appear, though. Would you be willing to file a new issue with a checklist of all the places where bots' names might be displayed in the app, indicating which ones should start marking bots with the bot icon, which ones don't need to do that, and which ones you're not sure about?

@chrisbobbe chrisbobbe merged commit 8c0f9ae into zulip:main Apr 9, 2024
@sm-sayedi
Copy link
Collaborator Author

Would you be willing to file a new issue with a checklist of all the places where...

Sure, will do so.

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.

ui: Distinguish isBot: true users with a bot marker
3 participants