Skip to content

Commit ed503d3

Browse files
loganjLarry
andcommitted
test(mobile): slim npub-identity tests, key avatars to hex pubkey
PR-M1 follow-up: consolidate the npub identity test surface into fewer table-driven cases while keeping every behavior assertion, and land the hex-keyed avatar-initial repair verified end to end. ## Summary - compose_note_page_test: replace the mid-edit 3-remount reply-preview test (it referenced the deleted _NoSelfProfileNotifier) with one unnamed-parent scenario through buildTestable(users:) — asserts the compact npub label and the hex-keyed preview avatar initial; the named parent control stays in the existing rich-preview test. - note_card_test: fold the reply-target and avatar cases into one table test — p-tag parent (compact npub, npub count 2, initial B), e-only parent (hex event id, npub count 1), cached author (authored label + name initial C); KeyedSubtree remounts keep each scenario's user cache isolated and the avatar finder is scoped to the single card. - channel_management_provider_test: combine the member-label and directory-label pairs (assertions unchanged); keep the AddMembersException compact-npub case. - string_utils_test: table-combine the fullNpub wrapper cases (hex/uppercase/padded/npub converge on the canonical npub); keep the shared canonical vector, invalid no-leak matrix, idempotence, and invite round-trip. - profile_provider_test: drop the redundant npub shape regex now that the exact compact label is pinned. - channel_detail/channels_page/compose_bar: folded scenarios verified — DM-header unnamed avatar, membership-sheet invalid-copy keyed remount, seven-fixture member preview (self/a11ce/cached Carol/3 members/agent asserting A/C/Y), DM tile labels and avatars, and mention-suggestion initials all assert at the production seams. - Delete the untracked 188-line channel_details_page driver: its member-row identity coverage is carried by the preview test at the same channel-details-member-* row seam. - Production avatar repairs ride along unchanged: hex-keyed initials for DM headers/tiles, suggestions, and member rows, and compact npub labels for unnamed DM counterparts. Full suite: 2088 passing. flutter analyze clean. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent d325e4c commit ed503d3

15 files changed

Lines changed: 546 additions & 204 deletions

‎mobile/lib/features/channels/channel_detail_page/app_bar.dart‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,10 @@ class _DmAppBarTitle extends ConsumerWidget {
238238
.contains(otherPubkey)) ||
239239
profile?.ownerPubkey != null;
240240
final animatedAvatar = parseAnimatedAvatarUrl(avatarUrl);
241-
final initial =
242-
profile?.initial ??
243-
(channel.participants.isNotEmpty
244-
? channel.participants.first[0].toUpperCase()
245-
: '?');
241+
// Keyed to the hex public key when the participant is unnamed and the
242+
// profile isn't cached — the compact-npub participant label would
243+
// otherwise render `N` for every unnamed DM counterpart.
244+
final initial = profile?.initial ?? dmAvatarInitial(channel);
246245
final presenceLabel = switch (presence) {
247246
'online' => 'Online',
248247
'away' => 'Away',

‎mobile/lib/features/channels/channel_details_page.dart‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,18 @@ class _ChannelMemberPreviewRow extends StatelessWidget {
655655
@override
656656
Widget build(BuildContext context) {
657657
final isSelf = member.pubkey.toLowerCase() == currentPubkey?.toLowerCase();
658+
final hasName = displayName?.trim().isNotEmpty == true;
658659
final label = isSelf
659660
? 'You'
660-
: displayName?.trim().isNotEmpty == true
661+
: hasName
661662
? displayName!.trim()
662663
: member.labelFor(currentPubkey);
664+
// Self/named initials come from the visible label; unnamed members stay
665+
// keyed to the hex public key so the compact-npub label doesn't render
666+
// `N` for everyone.
667+
final initial = isSelf || hasName
668+
? label[0].toUpperCase()
669+
: (member.pubkey.isNotEmpty ? member.pubkey[0].toUpperCase() : '?');
663670
final roleLabel = _channelMemberRoleLabel(member.role);
664671
final titleStyle = context.textTheme.bodyLarge;
665672
final roleStyle = context.textTheme.bodySmall?.copyWith(
@@ -671,7 +678,7 @@ class _ChannelMemberPreviewRow extends StatelessWidget {
671678
imageUrl: avatarUrl,
672679
radius: 20,
673680
backgroundColor: context.colors.primaryContainer,
674-
fallback: Text(label.isEmpty ? '?' : label[0].toUpperCase()),
681+
fallback: Text(initial),
675682
isAgent: member.isBot,
676683
),
677684
title: Text.rich(

‎mobile/lib/features/channels/channels_page/channel_tile.dart‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,10 @@ class _DmAvatar extends ConsumerWidget {
191191
}
192192

193193
final avatarUrl = profile?.avatarUrl;
194-
final initial =
195-
profile?.initial ??
196-
(channel.participants.isNotEmpty
197-
? channel.participants.first[0].toUpperCase()
198-
: '?');
194+
// Keyed to the hex public key when the counterpart is unnamed and the
195+
// profile isn't cached — the compact-npub participant label would
196+
// otherwise render `N` for every unnamed DM counterpart.
197+
final initial = profile?.initial ?? dmAvatarInitial(channel);
199198
return SizedBox(
200199
width: _kDmAvatarSize,
201200
height: _kDmAvatarSize,

‎mobile/lib/features/channels/compose_bar/suggestions.dart‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ class _MentionSuggestions extends StatelessWidget {
4747
radius: 18,
4848
backgroundColor: context.colors.primaryContainer,
4949
fallback: Text(
50-
name[0].toUpperCase(),
50+
// Name-derived for named candidates; keyed to the hex
51+
// public key for unnamed ones so the compact-npub label
52+
// doesn't render `N` for everyone.
53+
candidate.initial,
5154
style: context.textTheme.labelMedium?.copyWith(
5255
color: context.colors.onPrimaryContainer,
5356
fontWeight: FontWeight.w600,

‎mobile/lib/features/channels/dm_channel_labels.dart‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ String resolveDmChannelDisplayLabel(Channel channel, {String? currentPubkey}) {
5454
: channel.name;
5555
}
5656

57+
/// Avatar initial for the channel's first DM participant label.
58+
///
59+
/// A resolved display name keeps its name-derived initial. A label that
60+
/// fell back to the compact npub form of the participant's key is keyed to
61+
/// the hex public key instead — the npub form starts with `npub1`, so every
62+
/// unnamed participant would otherwise render `N`.
63+
String dmAvatarInitial(Channel channel) {
64+
if (channel.participants.isEmpty) return '?';
65+
final label = channel.participants.first;
66+
final pubkey = channel.participantPubkeys.isNotEmpty
67+
? channel.participantPubkeys.first
68+
: '';
69+
if (pubkey.isNotEmpty && label == shortPubkey(pubkey)) {
70+
return pubkey[0].toUpperCase();
71+
}
72+
return label.isNotEmpty ? label[0].toUpperCase() : '?';
73+
}
74+
5775
List<Channel> sortDmChannelsByDisplayLabel(
5876
Iterable<Channel> channels, {
5977
String? currentPubkey,

‎mobile/lib/features/pulse/compose_note_page.dart‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ class _ReplyContext extends ConsumerWidget {
192192
radius: 18,
193193
backgroundColor: context.colors.primaryContainer,
194194
fallback: Text(
195-
(profile?.initial ?? displayName[0]).toUpperCase(),
195+
// Name-derived when the profile is cached; keyed to the
196+
// hex public key when it isn't, so the compact-npub
197+
// fallback label doesn't render `N` for every unnamed
198+
// author.
199+
profile?.initial ??
200+
(pubkey.isNotEmpty ? pubkey[0].toUpperCase() : '?'),
196201
style: context.textTheme.labelMedium?.copyWith(
197202
color: context.colors.onPrimaryContainer,
198203
),

‎mobile/lib/features/pulse/note_card.dart‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ class NoteCard extends HookConsumerWidget {
7171
radius: 18,
7272
backgroundColor: context.colors.primaryContainer,
7373
fallback: Text(
74-
(profile?.initial ?? displayName[0]).toUpperCase(),
74+
// Name-derived when the profile is cached; keyed to the hex
75+
// public key when it isn't, so the compact-npub fallback
76+
// label doesn't render `N` for every unnamed author.
77+
profile?.initial ??
78+
(pubkey.isNotEmpty ? pubkey[0].toUpperCase() : '?'),
7579
style: context.textTheme.labelMedium?.copyWith(
7680
color: context.colors.onPrimaryContainer,
7781
),

0 commit comments

Comments
 (0)