Skip to content

Commit 0aad8ee

Browse files
loganjLarry
andcommitted
fix(mobile): preserve authored label padding and self-DM avatar keying
PR-M1 review follow-up (#7493): exact-head re-review findings on 25a93bb. ## Summary - dm_channel_labels.dart: dmAvatarInitial's exhausted-participant fallback now splits the two cases — no participant pubkeys keeps the first-participant-label fallback, while all-self WITH keys (a self-DM) resets index 0 and reuses the shared name/key provenance rule below. A self-DM tile keyed to the current user's hex key now shows that key's initial (B) beside its compact-npub label, instead of the label's leading N. - user_profile.dart: label trims only to judge blankness and returns the authored displayName when nonblank, so authored padding survives (' Carol ' renders ' Carol ', not 'Carol'); initial is unchanged and still reads the trimmed padding. - user_profile_test.dart: the ' Carol ' case expects the padded label with initial C. - channels_page_test.dart: the named-second fixture is Dana on the b0b key and asserts D, proving the authored name — not the key — sources the initial; a new self-DM tile case keys the fake profile and participant pubkeys to b0b and asserts the compact-npub label plus the B avatar. The fake profile notifier gains a pubkey knob for that one case; no other fixture changes. Full suite: 2096 passing. flutter analyze clean, dart format clean. Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz> Signed-off-by: Logan Johnson <[email protected]>
1 parent 25a93bb commit 0aad8ee

4 files changed

Lines changed: 83 additions & 25 deletions

File tree

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ String resolveDmChannelDisplayLabel(Channel channel, {String? currentPubkey}) {
5757
/// Avatar initial for the DM's visible counterpart.
5858
///
5959
/// Mirrors [resolveDmChannelDisplayLabel]'s participant selection: the
60-
/// first participant that is not [currentPubkey] (falling back to the first
61-
/// participant when every participant is the current user), since member
62-
/// order does not guarantee the counterpart is listed first — otherwise the
63-
/// avatar could identify the current user while the label beside it
64-
/// identifies the counterpart.
60+
/// first participant that is not [currentPubkey], since member order does
61+
/// not guarantee the counterpart is listed first — otherwise the avatar
62+
/// could identify the current user while the label beside it identifies
63+
/// the counterpart. When every participant is the current user (a
64+
/// self-DM), the label names the current user too, so the avatar keys off
65+
/// that same first participant instead of its label's first character.
6566
///
6667
/// A resolved display name keeps its name-derived initial. A label that
6768
/// fell back to the compact npub form of the participant's key is keyed to
@@ -76,14 +77,21 @@ String dmAvatarInitial(Channel channel, {String? currentPubkey}) {
7677
index++;
7778
}
7879

79-
// No participant pubkeys (labels only) or every pubkey is the current
80-
// user: fall back to the first participant label, like the channel label
81-
// does when the non-self list is empty.
8280
if (index >= channel.participantPubkeys.length) {
83-
final label = channel.participants.isNotEmpty
84-
? channel.participants.first
85-
: '';
86-
return label.isNotEmpty ? label[0].toUpperCase() : '?';
81+
// No participant pubkeys (labels only): fall back to the first
82+
// participant label, like the channel label does when the non-self
83+
// list is empty.
84+
if (channel.participantPubkeys.isEmpty) {
85+
final label = channel.participants.isNotEmpty
86+
? channel.participants.first
87+
: '';
88+
return label.isNotEmpty ? label[0].toUpperCase() : '?';
89+
}
90+
// Keys exist but every participant is the current user (a self-DM):
91+
// the label names the current user, so key the avatar to that same
92+
// first participant with the shared provenance rule below — the hex
93+
// key for a compact npub label, the authored name otherwise.
94+
index = 0;
8795
}
8896

8997
final pubkey = channel.participantPubkeys[index];

‎mobile/lib/shared/profile/user_profile.dart‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ class UserProfile {
3737
///
3838
/// Blank display names (empty or whitespace-only) fall back to the compact
3939
/// npub too — relay profiles can carry them — so a valid identity never
40-
/// renders an empty label. Mirrors [initial], which already rejects blank
41-
/// names.
40+
/// renders an empty label, like [initial]. Nonblank names render as
41+
/// authored: trim only tests blankness, so authored padding survives
42+
/// (unlike [initial], which reads the trimmed padding).
4243
String get label {
43-
final name = displayName?.trim();
44-
return name != null && name.isNotEmpty ? name : shortPubkey(pubkey);
44+
final name = displayName;
45+
return name != null && name.trim().isNotEmpty ? name : shortPubkey(pubkey);
4546
}
4647

4748
/// First letter for fallback avatar.

‎mobile/test/features/channels/channels_page_test.dart‎

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ void main() {
4343
Gradient? topSectionGradient,
4444
ValueChanged<double>? onSettingsTransitionProgress,
4545
ValueListenable<int>? tabReselection,
46+
_FakeProfileNotifier? profile,
4647
}) {
4748
return ProviderScope(
4849
overrides: [
49-
// Provide a fake profile and presence so the avatar doesn't hit the network.
50-
profileProvider.overrideWith(() => _FakeProfileNotifier()),
50+
// Provide a fake profile and presence so the avatar doesn't hit the
51+
// network. [profile] swaps the current user for tests keyed to a
52+
// different identity (the page reads its pubkey from profileProvider).
53+
profileProvider.overrideWith(() => profile ?? _FakeProfileNotifier()),
5154
presenceProvider.overrideWith(() => _FakePresenceNotifier()),
5255
communityIconProvider.overrideWith((ref, relayUrl) async {
5356
onCommunityIconLoad?.call(relayUrl);
@@ -283,7 +286,7 @@ void main() {
283286
createdBy: 'aabb',
284287
createdAt: DateTime(2025),
285288
memberCount: 2,
286-
participants: const ['Test', 'Bob'],
289+
participants: const ['Test', 'Dana'],
287290
participantPubkeys: const ['aabb', b0b],
288291
isMember: true,
289292
);
@@ -303,8 +306,48 @@ void main() {
303306
// that same hex key — never the current user's `A`.
304307
expect(find.text(shortPubkey(b0b)), findsOneWidget);
305308
expect(_dmTileAvatarInitial(tester, shortPubkey(b0b)), 'B');
306-
// A named counterpart listed second keeps its authored initial too.
307-
expect(_dmTileAvatarInitial(tester, 'Bob'), 'B');
309+
// A named counterpart listed second keeps its authored initial too —
310+
// `D`, not its key's `B`, proves the name is the initial's source.
311+
expect(_dmTileAvatarInitial(tester, 'Dana'), 'D');
312+
});
313+
314+
testWidgets('keys the self-DM tile avatar to the current user key', (
315+
tester,
316+
) async {
317+
// A self-DM lists only the current user, so the tile label falls back
318+
// to the sole participant — the compact npub of the current user's
319+
// own key.
320+
const b0b =
321+
'b0b0000000000000000000000000000000000000000000000000000000000000';
322+
final selfDm = Channel(
323+
id: 'dm-self',
324+
name: 'DM',
325+
channelType: 'dm',
326+
visibility: 'open',
327+
description: 'Direct message',
328+
createdBy: b0b,
329+
createdAt: DateTime(2025),
330+
memberCount: 1,
331+
participants: [shortPubkey(b0b)],
332+
participantPubkeys: const [b0b],
333+
isMember: true,
334+
);
335+
await tester.pumpWidget(
336+
buildTestable(
337+
// The tile reads the current user's pubkey from profileProvider, so
338+
// the self-DM needs the fake profile keyed to the same participant.
339+
profile: _FakeProfileNotifier(pubkey: b0b),
340+
overrides: [
341+
channelsProvider.overrideWith(() => _FakeNotifier([selfDm])),
342+
],
343+
),
344+
);
345+
await tester.pumpAndSettle();
346+
347+
// The compact-npub label and its avatar identify the same key: the
348+
// hex-key initial `B`, never the `N` the npub label starts with.
349+
expect(find.text(shortPubkey(b0b)), findsOneWidget);
350+
expect(_dmTileAvatarInitial(tester, shortPubkey(b0b)), 'B');
308351
});
309352

310353
testWidgets('sizes the community header for accessible text', (tester) async {
@@ -2629,9 +2672,15 @@ class _ReconnectingRelaySession extends RelaySessionNotifier {
26292672
}
26302673

26312674
class _FakeProfileNotifier extends ProfileNotifier {
2675+
_FakeProfileNotifier({this.pubkey = 'aabb'});
2676+
2677+
/// Current-user pubkey; the default keeps the historical 'aabb' fake used
2678+
/// by the other tile tests. The display name stays 'Test'.
2679+
final String pubkey;
2680+
26322681
@override
26332682
Future<UserProfile?> build() async =>
2634-
const UserProfile(pubkey: 'aabb', displayName: 'Test');
2683+
UserProfile(pubkey: pubkey, displayName: 'Test');
26352684
}
26362685

26372686
class _FakePresenceNotifier extends PresenceNotifier {

‎mobile/test/shared/profile/user_profile_test.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ void main() {
1212
// Relay profiles can carry a blank `display_name` (empty or
1313
// whitespace-only) and reach the cache unchanged, so both accessors must
1414
// reject blank names and fall back to the key instead of rendering an
15-
// empty label. Resolved names keep their authored label and initial
16-
// (whitespace-only padding is trimmed, like `initial` already did).
15+
// empty label. Nonblank names render as authored: `label` only tests
16+
// blankness with trim, while `initial` reads the trimmed padding.
1717
final cases = <({String? displayName, String label, String initial})>[
1818
(displayName: null, label: shortPubkey(b0b), initial: 'B'),
1919
(displayName: '', label: shortPubkey(b0b), initial: 'B'),
2020
(displayName: ' ', label: shortPubkey(b0b), initial: 'B'),
2121
(displayName: 'Carol', label: 'Carol', initial: 'C'),
22-
(displayName: ' Carol ', label: 'Carol', initial: 'C'),
22+
(displayName: ' Carol ', label: ' Carol ', initial: 'C'),
2323
];
2424

2525
for (final testCase in cases) {

0 commit comments

Comments
 (0)