mirror of
https://github.com/block/buzz.git
synced 2026-10-27 04:30:52 +00:00
🤖 ## 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 (#7488 foundation, #7489 controls, #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 <loganj@squareup.com> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
251 lines
7.9 KiB
Dart
251 lines
7.9 KiB
Dart
part of '../channels_page.dart';
|
|
|
|
class _ChannelTile extends ConsumerWidget {
|
|
final Channel channel;
|
|
final bool isUnread;
|
|
final bool isMuted;
|
|
final String? currentPubkey;
|
|
final VoidCallback onTap;
|
|
|
|
/// Called when the user requests to mark this channel read (from long-press
|
|
/// actions menu). Null for channels in built-in sections.
|
|
final VoidCallback? onMarkRead;
|
|
|
|
/// The user-defined section this channel currently belongs to, or null.
|
|
final String? sectionId;
|
|
|
|
const _ChannelTile({
|
|
required this.channel,
|
|
required this.isUnread,
|
|
required this.currentPubkey,
|
|
required this.onTap,
|
|
this.isMuted = false,
|
|
this.onMarkRead,
|
|
this.sectionId,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final contentColor = isMuted
|
|
? navigationSecondaryForeground(context)
|
|
: navigationPrimaryForeground(
|
|
context,
|
|
).withValues(alpha: isUnread ? 1 : 0.8);
|
|
|
|
return InkWell(
|
|
borderRadius: BorderRadius.circular(Radii.md),
|
|
onTap: onTap,
|
|
onLongPress: () => _showChannelActions(context, ref),
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(
|
|
left: _kChannelSectionInset,
|
|
right: _kChannelSectionInset,
|
|
top: _kChannelRowVerticalPadding,
|
|
bottom: _kChannelRowVerticalPadding,
|
|
),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(
|
|
width: _kChannelLeadingWidth,
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: channel.isDm
|
|
? _DmAvatar(channel: channel, currentPubkey: currentPubkey)
|
|
: Icon(
|
|
channelIcon(channel),
|
|
key: ValueKey('channel-icon-${channel.id}'),
|
|
size: _kChannelIconSize,
|
|
color: contentColor,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: _kChannelLabelGap),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
resolveDmChannelDisplayLabel(
|
|
channel,
|
|
currentPubkey: currentPubkey,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: contentListTitleTextStyle.copyWith(
|
|
color: contentColor,
|
|
fontWeight: isUnread ? FontWeight.w700 : FontWeight.w400,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (channel.isEphemeral) ...[
|
|
const SizedBox(width: Grid.xxs),
|
|
_EphemeralBadge(channel: channel),
|
|
],
|
|
if (isMuted) ...[
|
|
const SizedBox(width: Grid.xxs),
|
|
Icon(
|
|
LucideIcons.bellOff,
|
|
size: 12,
|
|
color: context.colors.onSurface.withValues(alpha: 0.4),
|
|
),
|
|
],
|
|
if (!channel.isMember && !channel.isDm)
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: Grid.xxs),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: Grid.half + 2,
|
|
vertical: 3,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: context.colors.primary.withValues(alpha: 0.1),
|
|
borderRadius: BorderRadius.circular(Radii.sm),
|
|
),
|
|
child: Text(
|
|
'Open',
|
|
style: context.textTheme.labelSmall?.copyWith(
|
|
color: context.colors.primary,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showChannelActions(BuildContext context, WidgetRef ref) {
|
|
showChannelActionsSheet(
|
|
context: context,
|
|
channel: channel,
|
|
isUnread: isUnread,
|
|
onMarkRead: onMarkRead,
|
|
sectionId: sectionId,
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DmAvatar extends ConsumerWidget {
|
|
final Channel channel;
|
|
final String? currentPubkey;
|
|
|
|
const _DmAvatar({required this.channel, required this.currentPubkey});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final normalizedCurrent = currentPubkey?.toLowerCase();
|
|
final otherPubkeys = [
|
|
for (final pk in channel.participantPubkeys)
|
|
if (pk.toLowerCase() != normalizedCurrent) pk.toLowerCase(),
|
|
];
|
|
final visiblePubkeys = otherPubkeys.isNotEmpty
|
|
? otherPubkeys
|
|
: channel.participantPubkeys.map((pk) => pk.toLowerCase()).toList();
|
|
|
|
if (visiblePubkeys.length > 1) {
|
|
return Container(
|
|
width: _kDmAvatarSize,
|
|
height: _kDmAvatarSize,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: context.colors.surfaceContainerHighest,
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: context.colors.outlineVariant),
|
|
),
|
|
child: Text(
|
|
'${visiblePubkeys.length}',
|
|
style: context.textTheme.labelSmall?.copyWith(
|
|
fontSize: 9,
|
|
color: context.colors.onSurface,
|
|
fontWeight: FontWeight.w600,
|
|
height: 1,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
final otherPubkey = visiblePubkeys.isNotEmpty ? visiblePubkeys.first : null;
|
|
final profile = ref.watch(
|
|
userCacheProvider.select(
|
|
(profiles) => otherPubkey == null ? null : profiles[otherPubkey],
|
|
),
|
|
);
|
|
final presence = ref.watch(
|
|
presenceCacheProvider.select(
|
|
(presenceMap) => otherPubkey == null
|
|
? 'offline'
|
|
: (presenceMap[otherPubkey] ?? 'offline'),
|
|
),
|
|
);
|
|
|
|
// Trigger fetches if not cached yet.
|
|
if (otherPubkey != null) {
|
|
if (profile == null) {
|
|
ref.read(userCacheProvider.notifier).preload([otherPubkey]);
|
|
}
|
|
ref.read(presenceCacheProvider.notifier).track([otherPubkey]);
|
|
}
|
|
|
|
final avatarUrl = profile?.avatarUrl;
|
|
// Keyed to the hex public key when the counterpart is unnamed and the
|
|
// profile isn't cached — the compact-npub participant label would
|
|
// otherwise render `N` for every unnamed DM counterpart. Selection skips
|
|
// the current user like the row label does, so the initial always
|
|
// identifies the same counterpart the label names.
|
|
final initial =
|
|
profile?.initial ??
|
|
dmAvatarInitial(channel, currentPubkey: currentPubkey);
|
|
return SizedBox(
|
|
width: _kDmAvatarSize,
|
|
height: _kDmAvatarSize,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
AvatarImage(
|
|
imageUrl: avatarUrl,
|
|
radius: _kDmAvatarSize / 2,
|
|
backgroundColor: context.colors.primaryContainer,
|
|
fallback: Text(
|
|
initial,
|
|
style: context.textTheme.labelSmall?.copyWith(
|
|
fontSize: 9,
|
|
color: context.colors.onPrimaryContainer,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
isAgent: profile?.isAgent == true,
|
|
),
|
|
Positioned(
|
|
right: -1,
|
|
bottom: -1,
|
|
child: Container(
|
|
width: 8,
|
|
height: 8,
|
|
decoration: BoxDecoration(
|
|
color: _presenceColor(context, presence),
|
|
shape: BoxShape.circle,
|
|
border: Border.all(
|
|
color: context.theme.scaffoldBackgroundColor,
|
|
width: 1.5,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Color _presenceColor(BuildContext context, String presence) {
|
|
return switch (presence) {
|
|
'online' => context.appColors.success,
|
|
'away' => context.appColors.warning,
|
|
_ => context.colors.outline,
|
|
};
|
|
}
|
|
}
|