Skip to content

Commit 0917da3

Browse files
klopez4212Terp
andcommitted
Preserve Add recovery intent and clarify community choices
Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Signed-off-by: kenny lopez <[email protected]>
1 parent a3b0fd8 commit 0917da3

6 files changed

Lines changed: 123 additions & 81 deletions

File tree

‎mobile/lib/features/onboarding/hosted_join_policy_view.dart‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class HostedJoinPolicyView extends HookWidget {
2121
@override
2222
Widget build(BuildContext context) {
2323
final ageConfirmed = useState(false);
24+
final documents = [
25+
if (policy.terms != null) 'terms',
26+
if (policy.privacy != null) 'privacy policy',
27+
];
2428
final children = <Widget>[
2529
if (policy.terms != null)
2630
ExpansionTile(
@@ -70,8 +74,9 @@ class HostedJoinPolicyView extends HookWidget {
7074
if (fullScreen) {
7175
return OnboardingStepPage(
7276
title: 'Join your community',
73-
subtitle:
74-
'Review this community’s terms and privacy policy before joining.',
77+
subtitle: documents.isEmpty
78+
? null
79+
: 'Review this community’s ${documents.join(' and ')} before joining.',
7580
onBack: onBack ?? () {},
7681
content: Column(
7782
crossAxisAlignment: CrossAxisAlignment.stretch,

‎mobile/lib/shared/hosted/hosted_flow.dart‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class HostedFlow extends ChangeNotifier {
108108
String? landingRelay;
109109
final Set<String> _addedRelays = {};
110110
bool _addingCommunities = false;
111-
bool _preparingAdd = false;
111+
Completer<bool>? _pendingAdd;
112112
String? _batchSubject;
113113
String? _conflictingRelay;
114114
String? _failedRelay;
@@ -649,26 +649,26 @@ class HostedFlow extends ChangeNotifier {
649649
!communities.any((item) => item.relayUrl == relay)) {
650650
return;
651651
}
652+
selectedRelays = Set.unmodifiable({...selectedRelays, relay});
652653
landingRelay = relay;
653654
notifyListeners();
654655
}
655656

656657
/// Restore existing memberships before presenting a separate Add route.
657-
Future<bool> prepareToAddCommunity() async {
658-
if (_preparingAdd || stage != HostedFlowStage.chooseCommunities) {
659-
return false;
660-
}
661-
_preparingAdd = true;
662-
try {
663-
final restoring = addSelectedCommunities();
664-
final generation = _generation;
665-
await restoring;
666-
return !_disposed &&
667-
generation == _generation &&
668-
stage == HostedFlowStage.chooseCommunities;
669-
} finally {
670-
_preparingAdd = false;
658+
Future<bool> prepareToAddCommunity() {
659+
if (_pendingAdd != null || stage != HostedFlowStage.chooseCommunities) {
660+
return Future.value(false);
671661
}
662+
if (selectedRelays.isEmpty) return Future.value(true);
663+
final pending = _pendingAdd = Completer<bool>();
664+
unawaited(addSelectedCommunities());
665+
return pending.future;
666+
}
667+
668+
void _finishPreparingAdd(bool ready) {
669+
final pending = _pendingAdd;
670+
_pendingAdd = null;
671+
pending?.complete(ready);
672672
}
673673

674674
Future<void> addSelectedCommunities() {
@@ -686,6 +686,7 @@ class HostedFlow extends ChangeNotifier {
686686
/// Keep completed additions while allowing a different landing choice.
687687
void backToCommunityChoices() {
688688
if (!canChangeCommunities) return;
689+
_finishPreparingAdd(false);
689690
_nextGeneration();
690691
_conflictingRelay = null;
691692
addingCommunityName = null;
@@ -771,17 +772,18 @@ class HostedFlow extends ChangeNotifier {
771772
}
772773
if (!current()) return;
773774
addingCommunityName = null;
775+
if (_pendingAdd != null) {
776+
_set(HostedFlowStage.chooseCommunities);
777+
_finishPreparingAdd(true);
778+
return;
779+
}
774780
if (_addedRelays.isEmpty) {
775781
communities = List.unmodifiable(
776782
communities.where((item) => selectedRelays.contains(item.relayUrl)),
777783
);
778784
await leave(noCommunities: true);
779785
return;
780786
}
781-
if (_preparingAdd) {
782-
_set(HostedFlowStage.chooseCommunities);
783-
return;
784-
}
785787
final destination = _addedRelays.contains(landingRelay)
786788
? landingRelay!
787789
: _addedRelays.first;
@@ -896,6 +898,7 @@ class HostedFlow extends ChangeNotifier {
896898
bool noCommunitiesToAdd = false;
897899

898900
void _clearCommunityBatch() {
901+
_finishPreparingAdd(false);
899902
noCommunitiesToAdd = false;
900903
communities = const [];
901904
selectedRelays = const {};
@@ -972,6 +975,7 @@ class HostedFlow extends ChangeNotifier {
972975
@override
973976
void dispose() {
974977
_disposed = true;
978+
_finishPreparingAdd(false);
975979
_cancelPolicy();
976980
_cancelProfile();
977981
_nextGeneration();

‎mobile/test/features/onboarding/fullscreen_onboarding_test.dart‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import '../../helpers/two_finger_double_tap.dart';
2+
import 'package:buzz/shared/hosted/builderlab_account.dart';
3+
import 'package:buzz/shared/hosted/hosted_community_connection.dart';
24
import 'package:hooks_riverpod/hooks_riverpod.dart';
35
import 'package:buzz/shared/theme/theme.dart';
46
import 'package:buzz/features/pairing/add_community_page.dart';
@@ -172,6 +174,29 @@ void main() {
172174
await tester.pumpAndSettle();
173175
expect(find.byType(OnboardingAppEntry), findsNothing);
174176
expect(find.text('Select a community'), findsOneWidget);
177+
for (final conflict in [false, true]) {
178+
fixture.beforeAdmission = (name) async {
179+
if (name == 'two.communities.buzz.xyz') {
180+
if (conflict) throw const SavedCommunityIdentityConflict();
181+
throw AccountFailure.unavailable;
182+
}
183+
};
184+
await tester.tap(find.byKey(const Key('community-switcher-add')));
185+
await tester.pumpAndSettle();
186+
expect(find.byType(OnboardingAppEntry), findsNothing);
187+
await tester.tap(
188+
find.text(
189+
conflict ? 'Keep saved identity and skip' : 'Skip this community',
190+
),
191+
);
192+
await tester.pumpAndSettle();
193+
expect(find.byType(OnboardingAppEntry), findsOneWidget);
194+
expect(fixture.openedCommunity, isNull);
195+
await tester.pageBack();
196+
await tester.pumpAndSettle();
197+
expect(find.text('Select a community'), findsOneWidget);
198+
fixture.admitted.clear();
199+
}
175200
fixture.beforeAdmission = null;
176201
// Add restores existing memberships, stays opaque, and returns to the
177202
// picker on Back without the disposed Add route cancelling discovery.

‎mobile/test/features/onboarding/hosted_communities_test.dart‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,10 @@ void main() {
269269
expect(find.byType(HostedConnectPage), findsNothing);
270270
await tester.tap(find.text('Continue with Builderlab'));
271271
await tester.pumpAndSettle();
272-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
273-
expect(find.byType(CommunityGridOption), findsWidgets);
274-
await tester.tap(find.byType(CommunityGridOption).first);
275-
await tester.pumpAndSettle();
276-
}
272+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
273+
expect(find.byType(CommunityGridOption), findsWidgets);
274+
await tester.tap(find.byType(CommunityGridOption).first);
275+
await tester.pumpAndSettle();
277276
expect(find.byType(CommunityGridOption), findsNothing);
278277
expect(f.admitted, [
279278
'one.communities.buzz.xyz',
@@ -288,11 +287,10 @@ void main() {
288287
};
289288
await tester.tap(find.text('Continue with Builderlab'));
290289
await tester.pumpAndSettle();
291-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
292-
expect(find.byType(CommunityGridOption), findsWidgets);
293-
await tester.tap(find.byType(CommunityGridOption).first);
294-
await tester.pumpAndSettle();
295-
}
290+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
291+
expect(find.byType(CommunityGridOption), findsWidgets);
292+
await tester.tap(find.byType(CommunityGridOption).first);
293+
await tester.pumpAndSettle();
296294
expect(find.text('Keep saved identity and skip'), findsOneWidget);
297295
expect(find.text('1 community added and kept.'), findsOneWidget);
298296
await tester.tap(find.text('Keep saved identity and skip'));
@@ -305,11 +303,10 @@ void main() {
305303
};
306304
await tester.tap(find.text('Continue with Builderlab'));
307305
await tester.pumpAndSettle();
308-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
309-
expect(find.byType(CommunityGridOption), findsWidgets);
310-
await tester.tap(find.byType(CommunityGridOption).first);
311-
await tester.pumpAndSettle();
312-
}
306+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
307+
expect(find.byType(CommunityGridOption), findsWidgets);
308+
await tester.tap(find.byType(CommunityGridOption).first);
309+
await tester.pumpAndSettle();
313310
expect(find.text('1 community added and kept.'), findsOneWidget);
314311
expect(find.text('Try again').hitTestable(), findsNothing);
315312
expect(find.text('Skip this community').hitTestable(), findsOneWidget);

‎mobile/test/features/onboarding/hosted_journeys_test.dart‎

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,8 @@ void main() {
7171
// Account restoration may resume independently of the Add choices.
7272
await f.flow.signInAccount();
7373
await f.settle(tester);
74-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
75-
expect(f.probes, isEmpty);
76-
await tester.tap(find.byType(CommunityGridOption).first);
77-
await f.settle(tester);
78-
}
74+
expect(f.flow.stage, HostedFlowStage.setupIdentity);
75+
expect(f.probes, isEmpty);
7976
expect(find.text('Create my Buzz identity'), findsOneWidget);
8077
expect(find.text('Import existing identity'), findsOneWidget);
8178
expect(await f.store.read(), isNull);
@@ -127,11 +124,8 @@ void main() {
127124
// Account restoration may resume independently of the Add choices.
128125
await f.flow.signInAccount();
129126
await f.settle(tester);
130-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
131-
expect(f.probes, isEmpty);
132-
await tester.tap(find.byType(CommunityGridOption).first);
133-
await f.settle(tester);
134-
}
127+
expect(f.flow.stage, HostedFlowStage.setupIdentity);
128+
expect(f.probes, isEmpty);
135129
expect(find.text('Create my Buzz identity'), findsNothing);
136130
expect(find.text('Import existing identity'), findsOneWidget);
137131
await f.tap(tester, 'Import existing identity');
@@ -188,11 +182,10 @@ void main() {
188182
// Account restoration may resume independently of the Add choices.
189183
await f.flow.signInAccount();
190184
await f.settle(tester);
191-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
192-
expect(f.probes, isEmpty);
193-
await tester.tap(find.byType(CommunityGridOption).first);
194-
await f.settle(tester);
195-
}
185+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
186+
expect(f.probes, isEmpty);
187+
await tester.tap(find.byType(CommunityGridOption).first);
188+
await f.settle(tester);
196189
await tester.tap(find.byTooltip('Add profile photo'));
197190
await f.settle(tester);
198191
expect(find.byType(ProfileSetupAvatarEditor), findsOneWidget);
@@ -215,11 +208,10 @@ void main() {
215208
// Account restoration may resume independently of the Add choices.
216209
await f.flow.signInAccount();
217210
await f.settle(tester);
218-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
219-
expect(f.probes, isEmpty);
220-
await tester.tap(find.byType(CommunityGridOption).first);
221-
await f.settle(tester);
222-
}
211+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
212+
expect(f.probes, isEmpty);
213+
await tester.tap(find.byType(CommunityGridOption).first);
214+
await f.settle(tester);
223215
await tester.tap(find.byTooltip('Add profile photo'));
224216
await f.settle(tester);
225217
final url = emojiAvatarDataUrl('🐝', 0xFFFFE75C);
@@ -631,11 +623,11 @@ void main() {
631623
// Account restoration may resume independently of the Add choices.
632624
await f.flow.signInAccount();
633625
await f.settle(tester);
634-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
635-
expect(f.probes, isEmpty);
636-
await tester.tap(find.byType(CommunityGridOption).first);
637-
await f.settle(tester);
638-
}
626+
expect(
627+
f.flow.stage,
628+
boundAccount ? HostedFlowStage.idle : HostedFlowStage.chooseIdentity,
629+
);
630+
expect(f.probes, isEmpty);
639631
if (!boundAccount) {
640632
expect(find.text('Saved identity'), findsOneWidget);
641633
expect(f.sent('/verify'), isEmpty);
@@ -674,11 +666,8 @@ void main() {
674666
// Account restoration may resume independently of the Add choices.
675667
await f.flow.signInAccount();
676668
await f.settle(tester);
677-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
678-
expect(f.probes, isEmpty);
679-
await tester.tap(find.byType(CommunityGridOption).first);
680-
await f.settle(tester);
681-
}
669+
expect(f.flow.stage, HostedFlowStage.chooseIdentity);
670+
expect(f.probes, isEmpty);
682671
expect(find.text('Use Builderlab identity'), findsNWidgets(2));
683672
await f.tap(tester, fullNpub(f.secondKeys.public)!);
684673
expect((await f.store.read())!.pubkey, f.secondKeys.public);
@@ -694,11 +683,8 @@ void main() {
694683
);
695684
f.rejectList = false;
696685
await f.tap(tester, 'Try again');
697-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
698-
expect(f.probes, isEmpty);
699-
await tester.tap(find.byType(CommunityGridOption).first);
700-
await f.settle(tester);
701-
}
686+
expect(f.flow.stage, HostedFlowStage.idle);
687+
expect(f.probes, isEmpty);
702688
expect(
703689
find.text(
704690
'No communities available to add. Scan a QR code or use an invite link.',
@@ -711,11 +697,10 @@ void main() {
711697
// Account restoration may resume independently of the Add choices.
712698
await f.flow.signInAccount();
713699
await f.settle(tester);
714-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
715-
expect(f.probes, isEmpty);
716-
await tester.tap(find.byType(CommunityGridOption).first);
717-
await f.settle(tester);
718-
}
700+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
701+
expect(f.probes, isEmpty);
702+
await tester.tap(find.byType(CommunityGridOption).first);
703+
await f.settle(tester);
719704
// Continue explicitly admits the selected communities.
720705
expect(find.byType(CheckboxListTile).hitTestable(), findsNothing);
721706
expect(
@@ -776,11 +761,10 @@ void main() {
776761
// Account restoration may resume independently of the Add choices.
777762
await f.flow.signInAccount();
778763
await f.settle(tester);
779-
if (f.flow.stage == HostedFlowStage.chooseCommunities) {
780-
expect(f.probes, isEmpty);
781-
await tester.tap(find.byType(CommunityGridOption).last);
782-
await f.settle(tester);
783-
}
764+
expect(f.flow.stage, HostedFlowStage.chooseCommunities);
765+
expect(f.probes, isEmpty);
766+
await tester.tap(find.byType(CommunityGridOption).last);
767+
await f.settle(tester);
784768
// All memberships are restored; the second is the chosen destination.
785769
expect(f.profileWrites, isEmpty);
786770
expect(

‎mobile/test/shared/hosted/hosted_communities_flow_test.dart‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ void main() {
4242
);
4343
}
4444

45+
test(
46+
'selecting a skipped relay retries it as the landing community',
47+
() async {
48+
final f = await fixture();
49+
f.rows = [f.row('one'), f.row('two'), f.row('three')];
50+
f.beforeAdmission = (name) async {
51+
if (name != 'one.communities.buzz.xyz') {
52+
throw AccountFailure.unavailable;
53+
}
54+
};
55+
await f.flow.signInAccount();
56+
await f.flow.addSelectedCommunities();
57+
await f.flow.skipFailedCommunity();
58+
expect(f.flow.stage, HostedFlowStage.blocked);
59+
f.flow.backToCommunityChoices();
60+
f.flow.chooseLandingCommunity('wss://two.communities.buzz.xyz');
61+
f.beforeAdmission = null;
62+
await f.flow.addSelectedCommunities();
63+
expect(f.admitted, [
64+
'one.communities.buzz.xyz',
65+
'two.communities.buzz.xyz',
66+
'three.communities.buzz.xyz',
67+
]);
68+
expect(f.openedCommunity, 'wss://two.communities.buzz.xyz');
69+
},
70+
);
71+
4572
test('malformed list targets cannot authorize admission', () async {
4673
final f = await fixture();
4774
f.rows = [

0 commit comments

Comments
 (0)