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>
227 lines
7.2 KiB
Dart
227 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:buzz/shared/profile/user_cache_provider.dart';
|
|
import 'package:buzz/shared/profile/user_profile.dart';
|
|
import 'package:buzz/features/pulse/compose_note_page.dart';
|
|
import 'package:buzz/features/pulse/pulse_models.dart';
|
|
import 'package:buzz/shared/theme/theme.dart';
|
|
import 'package:buzz/shared/widgets/avatar_image.dart';
|
|
|
|
class _FakeUserCacheNotifier extends UserCacheNotifier {
|
|
final Map<String, UserProfile> _users;
|
|
_FakeUserCacheNotifier(this._users);
|
|
|
|
@override
|
|
Map<String, UserProfile> build() => _users;
|
|
|
|
@override
|
|
UserProfile? get(String pubkey) => _users[pubkey.toLowerCase()];
|
|
}
|
|
|
|
void main() {
|
|
final replyNote = UserNote(
|
|
id: 'note1',
|
|
pubkey: 'alice_pk',
|
|
createdAt: DateTime.now().millisecondsSinceEpoch ~/ 1000 - 120,
|
|
content: 'The original note being replied to',
|
|
tags: const [],
|
|
);
|
|
|
|
Widget buildTestable(
|
|
Widget home, {
|
|
TextScaler textScaler = TextScaler.noScaling,
|
|
String displayName = 'Alice',
|
|
Map<String, UserProfile>? users,
|
|
}) {
|
|
return ProviderScope(
|
|
overrides: [
|
|
userCacheProvider.overrideWith(
|
|
() => _FakeUserCacheNotifier(
|
|
users ??
|
|
{
|
|
'alice_pk': UserProfile(
|
|
pubkey: 'alice_pk',
|
|
displayName: displayName,
|
|
),
|
|
},
|
|
),
|
|
),
|
|
],
|
|
child: MaterialApp(
|
|
theme: AppTheme.light(),
|
|
home: Builder(
|
|
builder: (context) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(textScaler: textScaler),
|
|
child: home,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
testWidgets('reply mode shows a rich preview of the replied-to note', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(buildTestable(ComposeNotePage(replyTo: replyNote)));
|
|
await tester.pump();
|
|
|
|
expect(find.text('Replying to Alice'), findsOneWidget);
|
|
expect(find.text('Alice'), findsOneWidget); // author name in the row
|
|
expect(find.textContaining('original note being replied to'), findsWidgets);
|
|
expect(find.text('Reply'), findsOneWidget); // action button label
|
|
// Named parent: the preview avatar initial comes from the authored name.
|
|
expect(_replyPreviewAvatarInitial(tester, 'Replying to Alice'), 'A');
|
|
});
|
|
|
|
testWidgets('reply preview constrains its timestamp at large text sizes', (
|
|
tester,
|
|
) async {
|
|
final oldReplyNote = UserNote(
|
|
id: 'old-note',
|
|
pubkey: 'alice_pk',
|
|
createdAt: DateTime.utc(2025, 9, 30, 12).millisecondsSinceEpoch ~/ 1000,
|
|
content: 'An older note',
|
|
tags: const [],
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
buildTestable(
|
|
ComposeNotePage(replyTo: oldReplyNote),
|
|
textScaler: const TextScaler.linear(2),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
final timestamp = tester.widget<Text>(find.text('Sep 30'));
|
|
expect(timestamp.maxLines, 1);
|
|
expect(timestamp.overflow, TextOverflow.ellipsis);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('gives the reply author unused timestamp width', (tester) async {
|
|
tester.view.devicePixelRatio = 1;
|
|
tester.view.physicalSize = const Size(320, 600);
|
|
addTearDown(() {
|
|
tester.view.resetPhysicalSize();
|
|
tester.view.resetDevicePixelRatio();
|
|
});
|
|
const displayName = 'A moderately long Pulse reply author';
|
|
|
|
await tester.pumpWidget(
|
|
buildTestable(
|
|
ComposeNotePage(replyTo: replyNote),
|
|
displayName: displayName,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(tester.getSize(find.text(displayName)).width, greaterThan(150));
|
|
expect(find.text('2m'), findsOneWidget);
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
|
|
testWidgets('new-note mode shows no reply preview', (tester) async {
|
|
await tester.pumpWidget(buildTestable(const ComposeNotePage()));
|
|
await tester.pump();
|
|
|
|
expect(find.textContaining('Replying to'), findsNothing);
|
|
expect(find.text('Post'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('reply preview stays compact for a short note', (tester) async {
|
|
await tester.pumpWidget(buildTestable(ComposeNotePage(replyTo: replyNote)));
|
|
await tester.pump();
|
|
|
|
// The preview content sits just above the divider; for a one-line note
|
|
// the gap between the content text and the divider must be small (this
|
|
// guards the earlier "preview row way too tall" regression).
|
|
final contentBottom = tester
|
|
.getRect(find.text('The original note being replied to'))
|
|
.bottom;
|
|
final divider = find.byType(Divider);
|
|
expect(divider, findsOneWidget);
|
|
final dividerTop = tester.getRect(divider).top;
|
|
expect(
|
|
dividerTop - contentBottom,
|
|
lessThan(24),
|
|
reason: 'reply preview should hug its content, not reserve tall space',
|
|
);
|
|
});
|
|
|
|
testWidgets('reply preview with an image note clips to a bounded height', (
|
|
tester,
|
|
) async {
|
|
final imageNote = UserNote(
|
|
id: 'note2',
|
|
pubkey: 'alice_pk',
|
|
createdAt: DateTime.now().millisecondsSinceEpoch ~/ 1000 - 60,
|
|
content: '#buzz\n',
|
|
tags: const [
|
|
[
|
|
'imeta',
|
|
'url https://example.com/big.png',
|
|
'm image/png',
|
|
'dim 800x1600',
|
|
],
|
|
],
|
|
);
|
|
await tester.pumpWidget(buildTestable(ComposeNotePage(replyTo: imageNote)));
|
|
await tester.pump();
|
|
|
|
// Renders the rich content (not the raw "" markdown).
|
|
expect(find.textContaining('![image]'), findsNothing);
|
|
// The whole reply context stays bounded: divider sits within a screen of
|
|
// the "Replying to" label (guards a tall image blowing up the page).
|
|
final labelTop = tester.getRect(find.text('Replying to Alice')).top;
|
|
final dividerTop = tester.getRect(find.byType(Divider)).top;
|
|
expect(dividerTop - labelTop, lessThan(220));
|
|
});
|
|
|
|
testWidgets('reply preview keys unnamed parent authors to their hex key', (
|
|
tester,
|
|
) async {
|
|
const a11ce =
|
|
'a11ce00000000000000000000000000000000000000000000000000000000000';
|
|
|
|
final unnamedParentNote = UserNote(
|
|
id: 'note-unnamed-parent',
|
|
pubkey: a11ce,
|
|
createdAt: DateTime.now().millisecondsSinceEpoch ~/ 1000 - 120,
|
|
content: 'The original note being replied to',
|
|
tags: const [],
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
buildTestable(
|
|
ComposeNotePage(replyTo: unnamedParentNote),
|
|
users: const {},
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.text('Replying to npub15yw\u2026ccpw'), findsOneWidget);
|
|
expect(
|
|
_replyPreviewAvatarInitial(tester, 'Replying to npub15yw\u2026ccpw'),
|
|
'A',
|
|
);
|
|
});
|
|
}
|
|
|
|
/// Avatar fallback initial in the reply-context preview, located by the
|
|
/// `Replying to` label it renders beside — the parent author's avatar, not
|
|
/// the composer's.
|
|
String _replyPreviewAvatarInitial(WidgetTester tester, String replyingLabel) {
|
|
final preview = find
|
|
.ancestor(of: find.text(replyingLabel), matching: find.byType(Column))
|
|
.first;
|
|
final avatar = find.descendant(
|
|
of: preview,
|
|
matching: find.byType(AvatarImage),
|
|
);
|
|
final initial = tester.widget<Text>(
|
|
find.descendant(of: avatar, matching: find.byType(Text)),
|
|
);
|
|
return initial.data!;
|
|
}
|