Skip to content

Commit 82656ff

Browse files
loganjLarry
andauthored
fix(mobile): standardize public-key identity display on npub (block#7493)
🤖 ## Summary In the mobile app, anyone who hasn't set a display name shows up as a raw 64-character hex key (e.g. `3a5d4f9c…`) — unreadable, and unrecognizable as the same identity across screens. Profile and Settings also let you copy that raw hex. Nostr public keys have a standard readable form — `npub1…`, the same encoding other Nostr apps and our desktop app already display. This PR makes every mobile identity surface render npub instead: - **Unnamed people everywhere** — message and thread authors, reactions, typing indicators, member lists, channel details, DM headers and tiles, inbox, search, forum cards, Pulse notes and reply context, mention suggestions, and invite rows — now show a compact npub label: first 8 + last 4 characters of the full npub joined by an ellipsis (`npub1abcd…wxyz`), the same truncation desktop uses. Previously these showed truncated raw hex. - **DM fallback avatars and blank names** — 1:1 DM tiles and headers key their fallback avatar to the same non-self counterpart the label names, including self-first participant order; a self-DM keeps its hex-key-derived initial. Blank or whitespace-only display names fall back to the compact npub instead of rendering empty, while nonblank authored names render verbatim (padding included). - **Profile sheet → "Copy public key"** now copies the full canonical npub — never raw hex. When the identity string isn't a valid public key, the copy tile is disabled, so a malformed key never reaches the clipboard. - **Settings → Identity (pubkey)** displays and copies the full npub; an invalid identity reads "Identity unavailable" with copy disabled. - **Invalid identities never leak truncated raw hex** into the UI anywhere — they render a neutral "Unknown identity" label. - **Unchanged on purpose:** display names and verified handles (NIP-05 — the `name@domain` badge) still render as before. Unnamed avatars keep distinct per-key initials, derived from the underlying hex key rather than the npub — otherwise every unnamed key would render the same "N" initial. Event IDs are not public keys, so they keep their hex truncation (in Pulse's "Replying to", the parent author shows npub while an event-id fallback still shows hex). The nevent share link, private keys, and internal hex storage are untouched. Inputs that accept a key (invite/member entry) accept both hex and npub and keep working in hex internally. ### Related issue N/A. Searched open issues/PRs for npub identity display on mobile — closest related: none found. Desktop's parallel npub standardization lives in the stacked desktop PRs (block#7488 foundation, block#7489 controls, block#7495 display surfaces); this is the independent mobile slice (based directly on `main`, not on those branches). ### Testing At exact head `5a620e420a1fd57d9d8011ac26434eed32fcf765` (base: `main` `44316ff72`; 40 files, +1,345/−154): - Full mobile suite: 2,098 tests passing (`cd mobile && flutter test`); `flutter analyze` clean; `dart format --set-exit-if-changed .` clean — the same checks CI runs. - Widget/unit coverage at production seams: compact labels and hex-keyed avatar initials for DM headers/tiles, member rows, mention suggestions, and Pulse reply context; DM fallback avatars keyed to the labeled counterpart (self-first order and self-DMs); blank/whitespace display-name npub fallback with nonblank authored labels verbatim, including the Activity inbox sender and profile-sheet heading (each with its own empty/whitespace production-seam regression); full-npub copy and disabled-copy semantics in profile and settings; invalid-key suppression; and hex↔npub input round-trips. Verified via unit and widget tests — no device/simulator validation is claimed. ### Task provenance Buzz channel: `1f0e4a3d-7e01-4efe-bb16-843b357f85c9` Task: buzz://message?channel=1f0e4a3d-7e01-4efe-bb16-843b357f85c9&id=86b34eb4bd84a1472419e9af22636c011c0fe273e3c196f967d7a36996e149b6 --------- Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 2226b6f commit 82656ff

40 files changed

Lines changed: 1345 additions & 154 deletions

‎mobile/lib/features/activity/activity_page/inbox_row.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class _InboxRow extends HookConsumerWidget {
8080
pubkey: ref.watch(userCacheProvider.select((cache) => cache[pubkey])),
8181
};
8282
final profile = profiles[senderPubkey];
83-
final senderLabel = profile?.displayName ?? shortPubkey(item.item.pubkey);
83+
// The shared label contract: blank cached names (empty or whitespace-only
84+
// are relay-valid) fall back to the compact npub, never a blank sender.
85+
final senderLabel = profile?.label ?? shortPubkey(item.item.pubkey);
8486
final profileMentionNames = {
8587
for (final pubkey in mentionPubkeys)
8688
if (profiles[pubkey]?.displayName?.trim().isNotEmpty == true)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,14 @@ class _DmAppBarTitle extends ConsumerWidget {
238238
.contains(otherPubkey)) ||
239239
profile?.ownerPubkey != null;
240240
final animatedAvatar = parseAnimatedAvatarUrl(avatarUrl);
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. Selection skips
244+
// the current user like the header label does, so the initial always
245+
// identifies the same counterpart the label names.
241246
final initial =
242247
profile?.initial ??
243-
(channel.participants.isNotEmpty
244-
? channel.participants.first[0].toUpperCase()
245-
: '?');
248+
dmAvatarInitial(channel, currentPubkey: currentPubkey);
246249
final presenceLabel = switch (presence) {
247250
'online' => 'Online',
248251
'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/channel_management_provider.dart‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../../shared/custom_emoji/custom_emoji_provider.dart';
1010
import '../../shared/crypto/nip_oa.dart';
1111
import '../../shared/mentions/agent_identity_provider.dart';
1212
import '../../shared/relay/relay.dart';
13+
import '../../shared/utils/string_utils.dart';
1314
import '../profile/profile_provider.dart';
1415
import 'channel.dart';
1516
import 'channel_metadata_updates.dart';
@@ -35,10 +36,7 @@ class AddMembersException implements Exception {
3536
const AddMembersException(this.failures);
3637

3738
String get message => failures.entries
38-
.map(
39-
(entry) =>
40-
'${entry.key.length > 8 ? '${entry.key.substring(0, 8)}…' : entry.key}: ${entry.value}',
41-
)
39+
.map((entry) => '${shortPubkey(entry.key)}: ${entry.value}')
4240
.join('; ');
4341

4442
@override
@@ -71,7 +69,7 @@ class ChannelMember {
7169
if (displayName case final name? when name.trim().isNotEmpty) {
7270
return name.trim();
7371
}
74-
return pubkey.length > 8 ? '${pubkey.substring(0, 8)}…' : pubkey;
72+
return shortPubkey(pubkey);
7573
}
7674
}
7775

@@ -175,19 +173,30 @@ class DirectoryUser {
175173
if (nip05 != null && nip05.isNotEmpty) {
176174
return nip05;
177175
}
178-
return pubkey.length > 8 ? '${pubkey.substring(0, 8)}…' : pubkey;
176+
return shortPubkey(pubkey);
179177
}
180178

181179
String get secondaryLabel {
182180
final nip05 = nip05Handle?.trim();
183181
if (nip05 != null && nip05.isNotEmpty && nip05 != label) {
184182
return nip05;
185183
}
186-
return pubkey.length > 16 ? '${pubkey.substring(0, 16)}…' : pubkey;
184+
// The primary label is already the compact key when no name or NIP-05
185+
// exists; a second key-shaped line would only duplicate it.
186+
final display = displayName?.trim();
187+
return display != null && display.isNotEmpty ? shortPubkey(pubkey) : '';
187188
}
188189

189-
/// First visible character used when no avatar image is available.
190-
String get initial => label.isNotEmpty ? label[0].toUpperCase() : '?';
190+
/// Avatar initial — name-derived when available, otherwise keyed to the
191+
/// hex public key so unnamed identities keep distinct initials (a compact
192+
/// npub would render `N` for everyone).
193+
String get initial {
194+
final display = displayName?.trim();
195+
if (display != null && display.isNotEmpty) return display[0].toUpperCase();
196+
final nip05 = nip05Handle?.trim();
197+
if (nip05 != null && nip05.isNotEmpty) return nip05[0].toUpperCase();
198+
return pubkey.isNotEmpty ? pubkey[0].toUpperCase() : '?';
199+
}
191200
}
192201

193202
/// Whether the mobile DM directory should show local preview identities.

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

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

193193
final avatarUrl = profile?.avatarUrl;
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. Selection skips
197+
// the current user like the row label does, so the initial always
198+
// identifies the same counterpart the label names.
194199
final initial =
195200
profile?.initial ??
196-
(channel.participants.isNotEmpty
197-
? channel.participants.first[0].toUpperCase()
198-
: '?');
201+
dmAvatarInitial(channel, currentPubkey: currentPubkey);
199202
return SizedBox(
200203
width: _kDmAvatarSize,
201204
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,56 @@ String resolveDmChannelDisplayLabel(Channel channel, {String? currentPubkey}) {
5454
: channel.name;
5555
}
5656

57+
/// Avatar initial for the DM's visible counterpart.
58+
///
59+
/// Mirrors [resolveDmChannelDisplayLabel]'s participant selection: the
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.
66+
///
67+
/// A resolved display name keeps its name-derived initial. A label that
68+
/// fell back to the compact npub form of the participant's key is keyed to
69+
/// the hex public key instead — the npub form starts with `npub1`, so every
70+
/// unnamed participant would otherwise render `N`.
71+
String dmAvatarInitial(Channel channel, {String? currentPubkey}) {
72+
final normalizedCurrent = currentPubkey?.toLowerCase();
73+
var index = 0;
74+
while (normalizedCurrent != null &&
75+
index < channel.participantPubkeys.length &&
76+
channel.participantPubkeys[index].toLowerCase() == normalizedCurrent) {
77+
index++;
78+
}
79+
80+
if (index >= channel.participantPubkeys.length) {
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;
95+
}
96+
97+
final pubkey = channel.participantPubkeys[index];
98+
final label = index < channel.participants.length
99+
? channel.participants[index]
100+
: shortPubkey(pubkey);
101+
if (pubkey.isNotEmpty && label == shortPubkey(pubkey)) {
102+
return pubkey[0].toUpperCase();
103+
}
104+
return label.isNotEmpty ? label[0].toUpperCase() : '?';
105+
}
106+
57107
List<Channel> sortDmChannelsByDisplayLabel(
58108
Iterable<Channel> channels, {
59109
String? currentPubkey,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ class _MemberTile extends ConsumerWidget {
221221
: (profile?.displayName?.trim().isNotEmpty == true
222222
? profile!.displayName!.trim()
223223
: member.labelFor(currentPubkey));
224-
final initial = label.substring(0, 1).toUpperCase();
224+
// Named members initial from their name; unnamed ones stay keyed to the
225+
// hex public key so the compact-npub label doesn't render `N` for all.
226+
final hasName = profile?.displayName?.trim().isNotEmpty == true;
227+
final initial = isSelf || hasName
228+
? label[0].toUpperCase()
229+
: (member.pubkey.isNotEmpty ? member.pubkey[0].toUpperCase() : '?');
225230
final showManagementActions = canManage && !isSelf && !member.isOwner;
226231
final showMenu = showManagementActions || onViewActivity != null;
227232

‎mobile/lib/features/channels/mentions/mention_candidates.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import '../../../shared/mentions/agent_identity_provider.dart';
22
import '../../../shared/profile/user_profile.dart';
3+
import '../../../shared/utils/string_utils.dart';
34
import '../channel_management_provider.dart';
45
import 'mention_ranking.dart';
56

@@ -35,7 +36,7 @@ String? formatOwnerLabel(
3536
if (name != null && name.isNotEmpty) return name;
3637
final handle = profile?.nip05Handle?.trim();
3738
if (handle != null && handle.isNotEmpty) return handle;
38-
return '${ownerPubkey.substring(0, 8)}…';
39+
return shortPubkey(ownerPubkey);
3940
}
4041

4142
/// Assemble the full mention candidate list: channel members first-class,

‎mobile/lib/features/channels/mentions/mention_ranking.dart‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:flutter/foundation.dart';
22

3+
import '../../../shared/utils/string_utils.dart';
4+
35
/// A mention autocomplete candidate. Mirrors the desktop's
46
/// `MentionCandidateForRanking` (desktop/src/features/messages/lib/mentionRanking.ts).
57
@immutable
@@ -27,7 +29,16 @@ class MentionCandidate {
2729
String get label {
2830
final name = displayName?.trim();
2931
if (name != null && name.isNotEmpty) return name;
30-
return pubkey.length >= 8 ? pubkey.substring(0, 8) : pubkey;
32+
return shortPubkey(pubkey);
33+
}
34+
35+
/// Avatar initial: display-name-derived, or keyed to the hex public key
36+
/// so unnamed identities keep distinct initials (a compact npub would
37+
/// render `N` for everyone).
38+
String get initial {
39+
final name = displayName?.trim();
40+
if (name != null && name.isNotEmpty) return name[0].toUpperCase();
41+
return pubkey.isNotEmpty ? pubkey[0].toUpperCase() : '?';
3142
}
3243
}
3344

0 commit comments

Comments
 (0)