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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/widgets/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,10 @@ class MessageWithPossibleSender extends StatelessWidget {

@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);

final message = item.message;
final sender = store.users[message.senderId];

Widget? senderRow;
if (item.showSender) {
Expand Down Expand Up @@ -926,6 +929,14 @@ class MessageWithPossibleSender extends StatelessWidget {
).merge(weightVariableTextStyle(context, wght: 600,
wghtIfPlatformRequestsBold: 900)),
overflow: TextOverflow.ellipsis)),
if (sender?.isBot ?? false) ...[
const SizedBox(width: 5),
const Icon(
ZulipIcons.bot,
size: 15,
color: Color.fromARGB(255, 159, 173, 173),
),
],
]))),
const SizedBox(width: 4),
Text(time,
Expand Down
3 changes: 2 additions & 1 deletion test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ User user({
String? email,
String? fullName,
bool? isActive,
bool? isBot,
String? avatarUrl,
Map<int, ProfileFieldUserData>? profileData,
}) {
Expand All @@ -89,7 +90,7 @@ User user({
isAdmin: false,
isGuest: false,
isBillingAdmin: false,
isBot: false,
isBot: isBot ?? false,
botType: null,
botOwnerId: null,
role: UserRole.member,
Expand Down
52 changes: 46 additions & 6 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';

import 'package:checks/checks.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -44,6 +43,7 @@ void main() {
int? messageCount,
List<Message>? messages,
List<ZulipStream>? streams,
List<User>? users,
List<Subscription>? subscriptions,
UnreadMessagesSnapshot? unreadMsgs,
}) async {
Expand All @@ -56,6 +56,7 @@ void main() {

// prepare message list data
store.addUser(eg.selfUser);
store.addUsers(users ?? []);
assert((messageCount == null) != (messages == null));
messages ??= List.generate(messageCount!, (index) {
return eg.streamMessage(sender: eg.selfUser);
Expand Down Expand Up @@ -467,11 +468,7 @@ void main() {
await tester.pump();
}

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

await setupMessageListPage(tester, messageCount: 10);
checkResultForSender(eg.selfUser.avatarUrl);
Expand All @@ -484,6 +481,49 @@ void main() {

debugNetworkImageHttpClientProvider = null;
});

testWidgets('Bot user is distinguished by showing an icon', (tester) async {
// When using this function, provide only one bot user
// to [PerAccountStore] through [setupMessageListPage] function.
void checkUser(User user, {required bool isBot}) {
final nameFinder = find.text(user.fullName);
final botFinder = find.byIcon(ZulipIcons.bot);

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.

of: nameFinder,
matching: find.ancestor(
of: botFinder,
matching: find.byType(Row),
));

isBot
? check(userFinder.evaluate()).isNotEmpty()
: check(userFinder.evaluate()).isEmpty();
}

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! 🙂


final users = [
eg.user(fullName: 'User 1', isBot: true),
eg.user(fullName: 'User 2', isBot: false),
eg.user(fullName: 'User 3', isBot: false),
];

await setupMessageListPage(
tester,
messages: users.map((user) => eg.streamMessage(sender: user)).toList(),
users: users,
);

checkUser(users[0], isBot: true);
checkUser(users[1], isBot: false);
checkUser(users[2], isBot: false);

debugNetworkImageHttpClientProvider = null;
});
});

group('Starred messages', () {
Expand Down