Skip to content

Commit bfeb0fe

Browse files
klopez4212Terp
andcommitted
Preserve hidden DM recovery and constrain landscape avatar flights
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <[email protected]>
1 parent 04789cf commit bfeb0fe

4 files changed

Lines changed: 163 additions & 103 deletions

File tree

‎mobile/lib/app.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'features/activity/activity_provider.dart';
12
import 'features/channels/default_agent_launcher.dart';
23
import 'features/agents/agents_page.dart';
34
import 'dart:async';
@@ -308,6 +309,8 @@ class App extends HookConsumerWidget {
308309
ref.listen(observerRelayProvider, (_, _) {});
309310
ref.watch(appLifecycleProvider);
310311
ref.listen(userStatusCacheProvider, (_, _) {});
312+
// Activity owns hidden-DM recovery even when Inbox is never opened.
313+
ref.listen(activityProvider, (_, _) {});
311314
// Preserve initial read seeding even while Solo is hidden.
312315
ref.listen(meUnreadChannelIdsProvider, (_, _) {});
313316
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class _CommunityFlyingAvatar extends StatelessWidget {
520520
final width = screen.width;
521521
final control = Offset(
522522
bend.dx.clamp(margin, max(margin, width - margin)),
523-
bend.dy,
523+
bend.dy.clamp(margin, max(margin, screen.height - margin)),
524524
);
525525
final t = departure;
526526
final position =

‎mobile/test/features/activity/activity_provider_test.dart‎

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import 'package:buzz/app.dart';
2+
import 'package:buzz/features/activity/activity_page.dart';
3+
import 'package:buzz/features/age_gate/age_signal_provider.dart';
4+
import 'package:buzz/shared/auth/auth.dart';
5+
import 'package:buzz/shared/theme/theme_provider.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:shared_preferences/shared_preferences.dart';
18
import 'dart:async';
29

310
import 'package:buzz/features/activity/activity_provider.dart';
@@ -391,9 +398,9 @@ void main() {
391398
},
392399
);
393400

394-
test(
395-
'live activity resurfaces a hidden DM through the existing open action',
396-
() async {
401+
testWidgets(
402+
'authenticated shell resurfaces hidden DMs without opening Inbox',
403+
(tester) async {
397404
const self =
398405
'1111111111111111111111111111111111111111111111111111111111111111';
399406
const alice =
@@ -402,8 +409,13 @@ void main() {
402409
'3333333333333333333333333333333333333333333333333333333333333333';
403410
final session = _RecordingSessionNotifier();
404411
final reopened = <List<String>>[];
412+
SharedPreferences.setMockInitialValues({});
413+
final prefs = await SharedPreferences.getInstance();
405414
final container = ProviderContainer(
406415
overrides: [
416+
savedPrefsProvider.overrideWithValue(prefs),
417+
authProvider.overrideWith(_ShellAuth.new),
418+
ageSignalProvider.overrideWith(_ShellAge.new),
407419
relayConfigProvider.overrideWith(_FixedRelayConfigNotifier.new),
408420
myPubkeyProvider.overrideWithValue(self),
409421
relaySessionProvider.overrideWith(() => session),
@@ -441,8 +453,16 @@ void main() {
441453
addTearDown(container.dispose);
442454

443455
await container.read(channelsProvider.future);
444-
await container.read(activityProvider.future);
445-
await Future<void>.delayed(const Duration(milliseconds: 10));
456+
await tester.pumpWidget(
457+
UncontrolledProviderScope(container: container, child: const App()),
458+
);
459+
for (var i = 0; i < 20; i++) {
460+
await tester.pump();
461+
}
462+
expect(find.byType(ActivityPage), findsNothing);
463+
expect(session.hiddenDmSubscriptionBatches, [
464+
['hidden-dm'],
465+
]);
446466

447467
session.emit(
448468
const NostrEvent(
@@ -459,10 +479,14 @@ void main() {
459479
),
460480
);
461481

462-
await _waitFor(() => reopened.isNotEmpty);
482+
for (var i = 0; i < 20 && reopened.isEmpty; i++) {
483+
await tester.pump();
484+
}
463485
expect(reopened, [
464486
[alice, bob],
465487
]);
488+
await tester.pumpWidget(const SizedBox.shrink());
489+
container.dispose();
466490
},
467491
);
468492

@@ -1201,3 +1225,16 @@ class _DeferredChannelsNotifier extends ChannelsNotifier {
12011225
_gate.complete(channels);
12021226
}
12031227
}
1228+
1229+
class _ShellAuth extends AuthNotifier {
1230+
@override
1231+
Future<AuthState> build() async =>
1232+
const AuthState(status: AuthStatus.authenticated);
1233+
}
1234+
1235+
class _ShellAge extends AgeSignalNotifier {
1236+
@override
1237+
AgeSignalState build() => AgeSignalState.allowed;
1238+
@override
1239+
Future<void> request() async {}
1240+
}

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

Lines changed: 116 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -8,105 +8,125 @@ void _homeCommunityFlightTests(
88
})
99
buildTestable,
1010
) {
11-
for (final reduced in [false, true]) {
12-
testWidgets(
13-
'Home community flight lands at the moved menu (reduced: $reduced)',
14-
(tester) async {
15-
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
16-
addTearDown(() => debugDefaultTargetPlatformOverride = null);
17-
tester.view.physicalSize = const Size(390, 844);
18-
tester.view.devicePixelRatio = 1;
19-
addTearDown(tester.view.resetPhysicalSize);
20-
addTearDown(tester.view.resetDevicePixelRatio);
21-
final communities = [
22-
for (final id in ['alpha', 'bravo'])
23-
Community(
24-
id: id,
25-
name: id,
26-
relayUrl: 'wss://$id.example.com',
27-
addedAt: DateTime(2025),
28-
),
29-
];
30-
final notifier = _FakeCommunityListNotifier(communities);
31-
final loaded = Completer<List<Channel>>();
32-
SharedPreferences.setMockInitialValues({});
33-
final prefs = await SharedPreferences.getInstance();
34-
await tester.pumpWidget(
35-
buildTestable(
36-
realHome: true,
37-
disableAnimations: reduced,
38-
overrides: [
39-
savedPrefsProvider.overrideWithValue(prefs),
40-
channelsProvider.overrideWith(
41-
() => _FakeNotifier(
42-
[],
43-
load: () => notifier.activeId == 'bravo'
44-
? loaded.future
45-
: Future.value([]),
46-
),
11+
for (final size in [const Size(390, 844), const Size(844, 390)]) {
12+
for (final reduced in [false, true]) {
13+
testWidgets(
14+
'Home community flight lands at the moved menu (size: $size, reduced: $reduced)',
15+
(tester) async {
16+
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
17+
addTearDown(() => debugDefaultTargetPlatformOverride = null);
18+
tester.view.physicalSize = size;
19+
final center = size.center(Offset.zero);
20+
tester.view.devicePixelRatio = 1;
21+
addTearDown(tester.view.resetPhysicalSize);
22+
addTearDown(tester.view.resetDevicePixelRatio);
23+
final communities = [
24+
for (final id in ['alpha', 'bravo'])
25+
Community(
26+
id: id,
27+
name: id,
28+
relayUrl: 'wss://$id.example.com',
29+
addedAt: DateTime(2025),
4730
),
48-
communityListProvider.overrideWith(() => notifier),
49-
activeCommunityProvider.overrideWith((ref) async {
50-
await ref.watch(communityListProvider.future);
51-
return communities.firstWhere((c) => c.id == notifier.activeId);
52-
}),
53-
],
54-
),
55-
);
56-
await tester.pumpAndSettle();
57-
final menu = find.byWidgetPredicate(
58-
(w) =>
59-
w is IosMessageCreateButton &&
60-
w.accessibilityLabel == 'Community menu',
61-
);
62-
final destination = tester.getCenter(menu);
63-
tester.widget<IosMessageCreateButton>(menu).actions.first.onPressed!();
64-
await tester.pumpAndSettle();
65-
await tester.tap(find.byKey(const Key('community-switcher-row-bravo')));
66-
await tester.pump();
67-
final avatar = find.byKey(const Key('community-flying-avatar'));
68-
final origin = tester.getCenter(avatar);
69-
await tester.pump(const Duration(milliseconds: 105));
70-
if (!reduced) {
71-
expect(tester.getCenter(avatar), isNot(origin));
72-
expect(tester.getCenter(avatar), isNot(const Offset(195, 422)));
73-
}
74-
await tester.pump(const Duration(milliseconds: 420));
75-
await tester.pump();
76-
expect(tester.getCenter(avatar), const Offset(195, 422));
77-
expect(
78-
find.byKey(const Key('community-switch-loading')),
79-
findsOneWidget,
80-
);
81-
loaded.complete([]);
82-
// Advance until readiness starts departure, without skipping the flight.
83-
for (var i = 0; i < 90; i++) {
84-
await tester.pump(const Duration(milliseconds: 16));
85-
if (find
86-
.byKey(const Key('community-switch-loading'))
87-
.evaluate()
88-
.isEmpty) {
89-
break;
31+
];
32+
final notifier = _FakeCommunityListNotifier(communities);
33+
final loaded = Completer<List<Channel>>();
34+
SharedPreferences.setMockInitialValues({});
35+
final prefs = await SharedPreferences.getInstance();
36+
await tester.pumpWidget(
37+
buildTestable(
38+
realHome: true,
39+
disableAnimations: reduced,
40+
overrides: [
41+
savedPrefsProvider.overrideWithValue(prefs),
42+
channelsProvider.overrideWith(
43+
() => _FakeNotifier(
44+
[],
45+
load: () => notifier.activeId == 'bravo'
46+
? loaded.future
47+
: Future.value([]),
48+
),
49+
),
50+
communityListProvider.overrideWith(() => notifier),
51+
activeCommunityProvider.overrideWith((ref) async {
52+
await ref.watch(communityListProvider.future);
53+
return communities.firstWhere(
54+
(c) => c.id == notifier.activeId,
55+
);
56+
}),
57+
],
58+
),
59+
);
60+
await tester.pumpAndSettle();
61+
final menu = find.byWidgetPredicate(
62+
(w) =>
63+
w is IosMessageCreateButton &&
64+
w.accessibilityLabel == 'Community menu',
65+
);
66+
final destination = tester.getCenter(menu);
67+
tester
68+
.widget<IosMessageCreateButton>(menu)
69+
.actions
70+
.first
71+
.onPressed!();
72+
await tester.pumpAndSettle();
73+
await tester.tap(
74+
find.byKey(const Key('community-switcher-row-bravo')),
75+
);
76+
await tester.pump();
77+
final avatar = find.byKey(const Key('community-flying-avatar'));
78+
final origin = tester.getCenter(avatar);
79+
await tester.pump(const Duration(milliseconds: 105));
80+
if (!reduced) {
81+
expect(tester.getCenter(avatar), isNot(origin));
82+
expect(tester.getCenter(avatar), isNot(center));
9083
}
91-
}
92-
if (!reduced) {
93-
await tester.pump(const Duration(milliseconds: 65));
94-
expect(tester.getCenter(avatar).dx, lessThan(195));
95-
await tester.pump(const Duration(milliseconds: 195));
96-
expect(tester.getCenter(avatar).dy, lessThan(422));
97-
expect(tester.getCenter(avatar).dy, greaterThan(destination.dy));
98-
await tester.pump(const Duration(milliseconds: 260));
84+
await tester.pump(const Duration(milliseconds: 420));
85+
await tester.pump();
86+
expect(tester.getCenter(avatar), center);
9987
expect(
100-
(tester.getCenter(avatar) - destination).distance,
101-
lessThan(1),
88+
find.byKey(const Key('community-switch-loading')),
89+
findsOneWidget,
10290
);
103-
}
104-
await tester.pumpAndSettle();
105-
expect(avatar, findsNothing);
106-
expect(notifier.switchedIds, ['bravo']);
107-
expect(tester.takeException(), isNull);
108-
debugDefaultTargetPlatformOverride = null;
109-
},
110-
);
91+
loaded.complete([]);
92+
// Advance until readiness starts departure, without skipping the flight.
93+
for (var i = 0; i < 90; i++) {
94+
await tester.pump(const Duration(milliseconds: 16));
95+
if (find
96+
.byKey(const Key('community-switch-loading'))
97+
.evaluate()
98+
.isEmpty) {
99+
break;
100+
}
101+
}
102+
if (!reduced) {
103+
await tester.pump(const Duration(milliseconds: 65));
104+
if (size.width < size.height) {
105+
expect(tester.getCenter(avatar).dx, lessThan(center.dx));
106+
}
107+
expect(tester.getCenter(avatar).dy, greaterThanOrEqualTo(0));
108+
for (var frame = 0; frame < 13; frame++) {
109+
await tester.pump(const Duration(milliseconds: 15));
110+
expect(
111+
tester.getCenter(avatar).dy,
112+
inInclusiveRange(0, size.height),
113+
);
114+
}
115+
expect(tester.getCenter(avatar).dy, lessThan(center.dy));
116+
expect(tester.getCenter(avatar).dy, greaterThan(destination.dy));
117+
await tester.pump(const Duration(milliseconds: 260));
118+
expect(
119+
(tester.getCenter(avatar) - destination).distance,
120+
lessThan(1),
121+
);
122+
}
123+
await tester.pumpAndSettle();
124+
expect(avatar, findsNothing);
125+
expect(notifier.switchedIds, ['bravo']);
126+
expect(tester.takeException(), isNull);
127+
debugDefaultTargetPlatformOverride = null;
128+
},
129+
);
130+
}
111131
}
112132
}

0 commit comments

Comments
 (0)