Skip to content

Commit 5f5b95b

Browse files
Code Reviewerklopez4212
andcommitted
fix(mobile): preserve text-only profile statuses
Co-authored-by: Kenny Lopez <[email protected]> Signed-off-by: Kenny Lopez <[email protected]>
1 parent d526213 commit 5f5b95b

2 files changed

Lines changed: 115 additions & 80 deletions

File tree

‎mobile/lib/features/profile/settings_profile_header.dart‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class SettingsProfileHeader extends ConsumerWidget {
2828
Widget build(BuildContext context, WidgetRef ref) {
2929
final profile = ref.watch(profileProvider).asData?.value;
3030
final status = ref.watch(userStatusProvider).asData?.value;
31+
final hasStatus = status != null && !status.isEmpty;
3132
final presence = ref.watch(presenceProvider).value ?? 'offline';
3233

3334
void openStatusSheet() =>
@@ -62,6 +63,29 @@ class SettingsProfileHeader extends ConsumerWidget {
6263
style: context.textTheme.titleMedium,
6364
textAlign: TextAlign.center,
6465
),
66+
// Keep the status text visible even when no emoji is set. NIP-38
67+
// permits text-only statuses, which the avatar badge cannot represent.
68+
if (hasStatus)
69+
GestureDetector(
70+
onTap: openStatusSheet,
71+
child: Padding(
72+
padding: const EdgeInsets.only(
73+
top: Grid.quarter,
74+
left: Grid.gutter,
75+
right: Grid.gutter,
76+
bottom: Grid.half,
77+
),
78+
child: Text(
79+
status.text.isNotEmpty ? status.text : status.emoji,
80+
style: context.textTheme.bodySmall?.copyWith(
81+
color: context.colors.onSurfaceVariant,
82+
),
83+
textAlign: TextAlign.center,
84+
maxLines: 2,
85+
overflow: TextOverflow.ellipsis,
86+
),
87+
),
88+
),
6589
_PresencePill(
6690
presence: presence,
6791
onSelected: (nextPresence) => unawaited(

‎mobile/test/features/profile/settings_profile_header_test.dart‎

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -50,87 +50,98 @@ void main() {
5050
);
5151
});
5252

53-
testWidgets('replaces the status line with a changeable presence pill', (
54-
tester,
55-
) async {
56-
final presenceNotifier = _FakePresenceNotifier('away');
57-
await tester.pumpWidget(
58-
WidgetHelpers.testable(
59-
overrides: [
60-
profileProvider.overrideWith(_FakeProfileNotifier.new),
61-
presenceProvider.overrideWith(() => presenceNotifier),
62-
userStatusProvider.overrideWith(
63-
() => _FakeUserStatusNotifier(
64-
const UserStatus(text: 'Focusing', emoji: '🎯', updatedAt: 1),
53+
testWidgets(
54+
'keeps text-only status visible beside a changeable presence pill',
55+
(tester) async {
56+
final presenceNotifier = _FakePresenceNotifier('away');
57+
await tester.pumpWidget(
58+
WidgetHelpers.testable(
59+
overrides: [
60+
profileProvider.overrideWith(_FakeProfileNotifier.new),
61+
presenceProvider.overrideWith(() => presenceNotifier),
62+
userStatusProvider.overrideWith(
63+
() => _FakeUserStatusNotifier(
64+
const UserStatus(text: 'Focusing', emoji: '', updatedAt: 1),
65+
),
6566
),
66-
),
67-
customEmojiListProvider.overrideWithValue(const []),
68-
],
69-
child: const SettingsProfileHeader(),
70-
),
71-
);
72-
await tester.pumpAndSettle();
73-
74-
expect(find.text('Focusing'), findsNothing);
75-
expect(
76-
find.byKey(const ValueKey('settings-presence-label')),
77-
findsOneWidget,
78-
);
79-
expect(find.text('Away'), findsOneWidget);
80-
expect(
81-
tester
82-
.widget<Text>(find.byKey(const ValueKey('settings-presence-label')))
83-
.style
84-
?.fontSize,
85-
filterChipTextStyle.fontSize,
86-
);
87-
expect(
88-
tester
89-
.getSize(find.byKey(const ValueKey('settings-presence-target')))
90-
.height,
91-
48,
92-
);
93-
expect(
94-
tester
95-
.getSize(find.byKey(const ValueKey('settings-presence-pill')))
96-
.height,
97-
greaterThanOrEqualTo(31),
98-
);
99-
100-
final presenceTarget = find.byKey(
101-
const ValueKey('settings-presence-target'),
102-
);
103-
final targetRect = tester.getRect(presenceTarget);
104-
await tester.tapAt(Offset(targetRect.center.dx, targetRect.bottom - 1));
105-
await tester.pump();
106-
107-
final scale = tester.widget<ScaleTransition>(
108-
find.byKey(const ValueKey('activity-popover-scale')),
109-
);
110-
expect(scale.alignment, Alignment.topCenter);
111-
expect(
112-
find.byKey(const ValueKey('settings-presence-popover')),
113-
findsOneWidget,
114-
);
115-
await tester.pumpAndSettle();
116-
117-
expect(
118-
find.byKey(const ValueKey('settings-presence-online')),
119-
findsOneWidget,
120-
);
121-
expect(
122-
find.byKey(const ValueKey('settings-presence-away')),
123-
findsOneWidget,
124-
);
125-
expect(
126-
find.byKey(const ValueKey('settings-presence-offline')),
127-
findsOneWidget,
128-
);
129-
130-
await tester.tap(find.byKey(const ValueKey('settings-presence-offline')));
131-
await tester.pumpAndSettle();
132-
expect(presenceNotifier.selected, ['offline']);
133-
});
67+
customEmojiListProvider.overrideWithValue(const []),
68+
],
69+
child: const SettingsProfileHeader(),
70+
),
71+
);
72+
await tester.pumpAndSettle();
73+
74+
expect(find.text('Focusing'), findsOneWidget);
75+
await tester.tap(find.text('Focusing'));
76+
await tester.pumpAndSettle();
77+
expect(find.text('Set a status'), findsOneWidget);
78+
expect(
79+
tester.widget<TextField>(find.byType(TextField)).controller?.text,
80+
'Focusing',
81+
);
82+
await tester.binding.handlePopRoute();
83+
await tester.pumpAndSettle();
84+
85+
expect(
86+
find.byKey(const ValueKey('settings-presence-label')),
87+
findsOneWidget,
88+
);
89+
expect(find.text('Away'), findsOneWidget);
90+
expect(
91+
tester
92+
.widget<Text>(find.byKey(const ValueKey('settings-presence-label')))
93+
.style
94+
?.fontSize,
95+
filterChipTextStyle.fontSize,
96+
);
97+
expect(
98+
tester
99+
.getSize(find.byKey(const ValueKey('settings-presence-target')))
100+
.height,
101+
48,
102+
);
103+
expect(
104+
tester
105+
.getSize(find.byKey(const ValueKey('settings-presence-pill')))
106+
.height,
107+
greaterThanOrEqualTo(31),
108+
);
109+
110+
final presenceTarget = find.byKey(
111+
const ValueKey('settings-presence-target'),
112+
);
113+
final targetRect = tester.getRect(presenceTarget);
114+
await tester.tapAt(Offset(targetRect.center.dx, targetRect.bottom - 1));
115+
await tester.pump();
116+
117+
final scale = tester.widget<ScaleTransition>(
118+
find.byKey(const ValueKey('activity-popover-scale')),
119+
);
120+
expect(scale.alignment, Alignment.topCenter);
121+
expect(
122+
find.byKey(const ValueKey('settings-presence-popover')),
123+
findsOneWidget,
124+
);
125+
await tester.pumpAndSettle();
126+
127+
expect(
128+
find.byKey(const ValueKey('settings-presence-online')),
129+
findsOneWidget,
130+
);
131+
expect(
132+
find.byKey(const ValueKey('settings-presence-away')),
133+
findsOneWidget,
134+
);
135+
expect(
136+
find.byKey(const ValueKey('settings-presence-offline')),
137+
findsOneWidget,
138+
);
139+
140+
await tester.tap(find.byKey(const ValueKey('settings-presence-offline')));
141+
await tester.pumpAndSettle();
142+
expect(presenceNotifier.selected, ['offline']);
143+
},
144+
);
134145
}
135146

136147
class _FakeProfileNotifier extends ProfileNotifier {

0 commit comments

Comments
 (0)