Skip to content

Commit

Permalink
msglist: Distinguish isBot: true message senders with a bot marker
Browse files Browse the repository at this point in the history
Fixes: #156
  • Loading branch information
sm-sayedi committed Apr 8, 2024
1 parent 5c47233 commit 8c0f9ae
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
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
45 changes: 45 additions & 0 deletions test/widgets/message_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void main() {
int? messageCount,
List<Message>? messages,
List<ZulipStream>? streams,
List<User>? users,
List<Subscription>? subscriptions,
UnreadMessagesSnapshot? unreadMsgs,
}) async {
Expand All @@ -55,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 @@ -479,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(
of: nameFinder,
matching: find.ancestor(
of: botFinder,
matching: find.byType(Row),
));

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

prepareBoringImageHttpClient();

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

0 comments on commit 8c0f9ae

Please sign in to comment.