Skip to content

Commit ff4ff57

Browse files
author
Fizz
committed
fix: classify forum thread agent avatars
Signed-off-by: Fizz <dae5f6af70b8695a8b83c8deae555f63be41630ec2b8cd493e41a439c9527dd8@buzz.block.builderlab.xyz>
1 parent 7827c15 commit ff4ff57

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

‎mobile/lib/features/forum/forum_thread_page.dart‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,11 @@ class _OriginalPost extends ConsumerWidget {
359359
GestureDetector(
360360
onTap: () => showUserProfileSheet(context, post.pubkey),
361361
child: _Avatar(
362+
key: ValueKey('forum-original-avatar-${post.eventId}'),
362363
profile: profile,
363364
pubkey: post.pubkey,
364365
radius: 16,
366+
isAgent: agentMentionPubkeys.contains(pk),
365367
),
366368
),
367369
const SizedBox(width: Grid.xxs),
@@ -462,9 +464,11 @@ class _ReplyRow extends ConsumerWidget {
462464
GestureDetector(
463465
onTap: () => showUserProfileSheet(context, reply.pubkey),
464466
child: _Avatar(
467+
key: ValueKey('forum-reply-avatar-${reply.eventId}'),
465468
profile: profile,
466469
pubkey: reply.pubkey,
467470
radius: 12,
471+
isAgent: agentMentionPubkeys.contains(pk),
468472
),
469473
),
470474
const SizedBox(width: Grid.xxs),
@@ -620,11 +624,14 @@ class _Avatar extends StatelessWidget {
620624
final UserProfile? profile;
621625
final String pubkey;
622626
final double radius;
627+
final bool isAgent;
623628

624629
const _Avatar({
630+
super.key,
625631
required this.profile,
626632
required this.pubkey,
627633
required this.radius,
634+
required this.isAgent,
628635
});
629636

630637
@override
@@ -645,7 +652,7 @@ class _Avatar extends StatelessWidget {
645652
color: context.colors.onPrimaryContainer,
646653
),
647654
),
648-
isAgent: profile?.ownerPubkey != null,
655+
isAgent: isAgent,
649656
);
650657
}
651658
}

‎mobile/test/features/forum/forum_widgets_test.dart‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@ Widget _buildThreadPage({
125125
bool isMember = true,
126126
bool isArchived = false,
127127
Map<String, UserProfile> users = const {},
128+
Set<String> knownAgentPubkeys = const {},
129+
Set<String> channelBotPubkeys = const {},
128130
TextScaler textScaler = TextScaler.noScaling,
129131
}) {
130132
return ProviderScope(
131133
overrides: [
132134
userCacheProvider.overrideWith(() => _FakeUserCacheNotifier(users)),
135+
knownAgentPubkeysProvider.overrideWithValue(knownAgentPubkeys),
136+
channelBotPubkeysProvider(
137+
_channelId,
138+
).overrideWith((ref) async => channelBotPubkeys),
133139
profileProvider.overrideWith(() => _FakeProfileNotifier()),
134140
forumThreadProvider((
135141
channelId: _channelId,
@@ -570,6 +576,81 @@ void main() {
570576
});
571577

572578
group('ForumThreadPage', () {
579+
AvatarImage avatarIn(WidgetTester tester, Key key) =>
580+
tester.widget<AvatarImage>(
581+
find.descendant(
582+
of: find.byKey(key),
583+
matching: find.byType(AvatarImage),
584+
),
585+
);
586+
587+
testWidgets(
588+
'uses directory classification for an uncached original author',
589+
(tester) async {
590+
await tester.pumpWidget(
591+
_buildThreadPage(
592+
threadResponse: ForumThreadResponse(
593+
post: _makePost(pubkey: 'directory-agent'),
594+
replies: const [],
595+
totalReplies: 0,
596+
),
597+
knownAgentPubkeys: const {'directory-agent'},
598+
),
599+
);
600+
await tester.pumpAndSettle();
601+
602+
expect(
603+
avatarIn(
604+
tester,
605+
const ValueKey('forum-original-avatar-post1'),
606+
).isAgent,
607+
isTrue,
608+
);
609+
},
610+
);
611+
612+
testWidgets('uses bot-role classification for an uncached reply author', (
613+
tester,
614+
) async {
615+
await tester.pumpWidget(
616+
_buildThreadPage(
617+
threadResponse: ForumThreadResponse(
618+
post: _makePost(),
619+
replies: const [
620+
ThreadReply(
621+
eventId: 'bot-reply',
622+
pubkey: 'channel-bot',
623+
content: 'Automated reply',
624+
kind: 45003,
625+
createdAt: 2000,
626+
channelId: _channelId,
627+
tags: [
628+
['h', _channelId],
629+
],
630+
depth: 1,
631+
),
632+
],
633+
totalReplies: 1,
634+
),
635+
users: const {'alice': _aliceProfile},
636+
channelBotPubkeys: const {'channel-bot'},
637+
),
638+
);
639+
await tester.pumpAndSettle();
640+
641+
expect(
642+
avatarIn(
643+
tester,
644+
const ValueKey('forum-reply-avatar-bot-reply'),
645+
).isAgent,
646+
isTrue,
647+
);
648+
expect(
649+
avatarIn(tester, const ValueKey('forum-original-avatar-post1')).isAgent,
650+
isFalse,
651+
);
652+
});
653+
573654
testWidgets('shows original post and replies header', (tester) async {
574655
await tester.pumpWidget(
575656
_buildThreadPage(

0 commit comments

Comments
 (0)