Skip to content

Commit 8f2c771

Browse files
authored
fix(mobile): default community push notifications to on (#8425)
New mobile communities currently require a manual Settings opt-in before push can start. Default that local preference to on for new communities and stored records without a preference. Preserve every saved `true` or `false`, including values written by older clients. Older default-off values are indistinguishable from explicit opt-outs, so this does not migrate them to on. Push still requires a configured gateway, authenticated connectivity, and a valid relay capability. iOS continues to control display authorization through its existing permission prompt. Notification eligibility and subscriptions are unchanged. Settings retains its existing opt-out control for enabled communities even when capability is unavailable. Drafted from the 0.24 baseline; release-branch inclusion is a separate decision. ### Related issue Closest related issue: #3238 (synced defaults). This change is limited to the mobile device-local community preference; no duplicate found. ### Validation - Added or updated coverage for new and missing preferences, saved true/false persistence, opt-out after restart, capability-gated registration, and Settings without a configured gateway. - Full configured mobile suite: 3,499 passed, 4 skipped. Separate no-gateway suite: 4 passed. Flutter analysis passed. - Existing permission-denied and unsupported-relay tests passed as part of the mobile suite. No physical-device or end-to-end APNs validation performed. - Full local repository gate passed (formatting, lint, unit tests, desktop/web builds, Tauri checks/tests, and mobile tests). - Follow-up review edits: restored the original VISION.md wording and shared the default in one private Community constant. All 43 focused community/bootstrap tests passed. <!-- buzz-review-completed --> --------- Signed-off-by: Tom Brow <[email protected]>
1 parent 305fb7b commit 8f2c771

5 files changed

Lines changed: 116 additions & 44 deletions

File tree

‎mobile/lib/shared/community/community.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ String _newPushLeaseInstallationId() {
1919
enum SensitiveActionPolicy { enabled, disabledByUser }
2020

2121
class Community {
22+
static const _defaultPushNotificationsEnabled = true;
23+
2224
final String id;
2325
final String name;
2426
final String relayUrl;
@@ -45,7 +47,7 @@ class Community {
4547
this.pubkey,
4648
this.nsec,
4749
this.sensitiveActionPolicy = SensitiveActionPolicy.disabledByUser,
48-
this.pushNotificationsEnabled = false,
50+
this.pushNotificationsEnabled = _defaultPushNotificationsEnabled,
4951
this.pushSubscriptionState = const BuzzPushLeaseSubscriptionState.desired(),
5052
this.pushLeaseInstallationId,
5153
this.starterSetupIncomplete = false,
@@ -130,7 +132,8 @@ class Community {
130132
);
131133
}
132134
final pushNotificationsEnabled =
133-
json['pushNotificationsEnabled'] as bool? ?? false;
135+
json['pushNotificationsEnabled'] as bool? ??
136+
_defaultPushNotificationsEnabled;
134137
var pushSubscriptionState = json['pushSubscriptionState'] == null
135138
? const BuzzPushLeaseSubscriptionState.desired()
136139
: BuzzPushLeaseSubscriptionState.fromJson(

‎mobile/test/shared/community/community_provider_test.dart‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ void main() {
122122
});
123123

124124
test(
125-
'push notifications default off and opt-in survives restart',
125+
'push notifications default on and opt-out survives restart',
126126
() async {
127127
container = createContainer();
128128
await container.read(communityListProvider.future);
@@ -137,20 +137,20 @@ void main() {
137137
(await container.read(
138138
communityListProvider.future,
139139
)).single.pushNotificationsEnabled,
140-
isFalse,
140+
isTrue,
141141
);
142142

143143
await container
144144
.read(communityListProvider.notifier)
145-
.setPushNotificationsEnabled(community.id, true);
145+
.setPushNotificationsEnabled(community.id, false);
146146
container.dispose();
147147
container = createContainer();
148148

149149
expect(
150150
(await container.read(
151151
communityListProvider.future,
152152
)).single.pushNotificationsEnabled,
153-
isTrue,
153+
isFalse,
154154
);
155155
},
156156
);

‎mobile/test/shared/community/community_test.dart‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ void main() {
1616
);
1717
expect(community.starterSetupIncomplete, isFalse);
1818
expect(community.pushLeaseInstallationId, isNull);
19+
expect(community.pushNotificationsEnabled, isTrue);
20+
expect(community.pushSubscriptionState.pendingTombstoneGeneration, isNull);
1921
});
2022

2123
test('new community gets a unique canonical push lease address id', () {
@@ -25,6 +27,8 @@ void main() {
2527
relayUrl: 'https://relay.test',
2628
);
2729

30+
expect(first.pushNotificationsEnabled, isTrue);
31+
expect(Community.fromJson(first.toJson()).pushNotificationsEnabled, isTrue);
2832
expect(first.pushLeaseInstallationId, matches(RegExp(r'^[0-9a-f]{32}$')));
2933
expect(
3034
second.pushLeaseInstallationId,
@@ -49,6 +53,31 @@ void main() {
4953
expect(roundTrip.pushLeaseInstallationId, 'a' * 32);
5054
});
5155

56+
for (final enabled in [true, false]) {
57+
test('saved push preference $enabled survives loading and copying', () {
58+
final community = Community.fromJson({
59+
'id': 'one',
60+
'name': 'Buzz',
61+
'relayUrl': 'https://relay.test',
62+
'pushNotificationsEnabled': enabled,
63+
'addedAt': '2026-08-05T00:00:00.000Z',
64+
});
65+
expect(community.pushNotificationsEnabled, enabled);
66+
expect(
67+
community.copyWith(name: 'Renamed').pushNotificationsEnabled,
68+
enabled,
69+
);
70+
expect(
71+
Community.fromJson(community.toJson()).pushNotificationsEnabled,
72+
enabled,
73+
);
74+
expect(
75+
community.pushSubscriptionState.pendingTombstoneGeneration,
76+
isNull,
77+
);
78+
});
79+
}
80+
5281
test('malformed stored push lease address id is rejected', () {
5382
expect(
5483
() => Community.fromJson({

‎mobile/test/shared/push/push_bootstrap_test.dart‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@ void main() {
2626
expect(registrations, 1);
2727
});
2828

29+
testWidgets('new community starts registration once capability arrives', (
30+
tester,
31+
) async {
32+
final community = Community.create(
33+
name: 'Team',
34+
relayUrl: 'wss://relay.example',
35+
);
36+
var registrations = 0;
37+
Widget bootstrap(BuzzPushLeaseDescriptor? descriptor) =>
38+
BuzzPushRegistrationBootstrap(
39+
shouldRegister: buzzPushLifecycleEnabled(
40+
community: community,
41+
descriptor: descriptor,
42+
),
43+
attemptKey: '${community.id}|${community.relayUrl}',
44+
startRegistration: () async => registrations += 1,
45+
child: const SizedBox(),
46+
);
47+
await tester.pumpWidget(bootstrap(null));
48+
expect(registrations, 0);
49+
final descriptor = _descriptor(keyId: 'relay-v1', pubkey: _hex('b'));
50+
await tester.pumpWidget(bootstrap(descriptor));
51+
expect(registrations, 1);
52+
await tester.pumpWidget(bootstrap(descriptor));
53+
expect(registrations, 1);
54+
});
55+
2956
test(
3057
'superseded lease acceptance is a retryable publication failure',
3158
() async {
@@ -141,12 +168,12 @@ void main() {
141168
);
142169
});
143170

144-
test('relay capability alone does not activate push without opt-in', () {
145-
final disabled = Community.create(
171+
test('default push requires relay capability and respects opt-out', () {
172+
final enabled = Community.create(
146173
name: 'Team',
147174
relayUrl: 'wss://relay.example',
148175
);
149-
final enabled = disabled.copyWith(pushNotificationsEnabled: true);
176+
final disabled = enabled.copyWith(pushNotificationsEnabled: false);
150177

151178
expect(
152179
buzzPushLifecycleEnabled(

‎mobile/test/shared/push/push_unconfigured_build_test.dart‎

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,43 +73,56 @@ void main() {
7373
expect(calls, isEmpty);
7474
});
7575

76-
testWidgets('Settings hides notifications without push capability', (
77-
tester,
78-
) async {
79-
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
80-
addTearDown(() => debugDefaultTargetPlatformOverride = null);
81-
SharedPreferences.setMockInitialValues({});
82-
final prefs = await SharedPreferences.getInstance();
83-
await tester.pumpWidget(
84-
ProviderScope(
85-
overrides: [
86-
savedPrefsProvider.overrideWithValue(prefs),
87-
activeCommunityProvider.overrideWith(
88-
(ref) async => Community.create(
89-
name: 'Team',
90-
relayUrl: 'wss://relay.example',
76+
for (final enabled in [true, false]) {
77+
testWidgets(
78+
'Settings preserves preference $enabled without push capability',
79+
(tester) async {
80+
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
81+
addTearDown(() => debugDefaultTargetPlatformOverride = null);
82+
SharedPreferences.setMockInitialValues({});
83+
final prefs = await SharedPreferences.getInstance();
84+
await tester.pumpWidget(
85+
ProviderScope(
86+
overrides: [
87+
savedPrefsProvider.overrideWithValue(prefs),
88+
activeCommunityProvider.overrideWith(
89+
(ref) async => Community.create(
90+
name: 'Team',
91+
relayUrl: 'wss://relay.example',
92+
).copyWith(pushNotificationsEnabled: enabled),
93+
),
94+
buzzPushAuthorizationStatusReaderProvider.overrideWithValue(
95+
() async => throw StateError(
96+
'must not query notification permission',
97+
),
98+
),
99+
],
100+
child: MaterialApp(
101+
theme: AppTheme.light(),
102+
home: SettingsPage(
103+
profileHeader: const SizedBox.shrink(),
104+
identityRecoveryPageBuilder: (_) => const SizedBox.shrink(),
105+
),
91106
),
92107
),
93-
buzzPushAuthorizationStatusReaderProvider.overrideWithValue(
94-
() async =>
95-
throw StateError('must not query notification permission'),
96-
),
97-
],
98-
child: MaterialApp(
99-
theme: AppTheme.light(),
100-
home: SettingsPage(
101-
profileHeader: const SizedBox.shrink(),
102-
identityRecoveryPageBuilder: (_) => const SizedBox.shrink(),
103-
),
104-
),
105-
),
108+
);
109+
await tester.pumpAndSettle();
110+
expect(
111+
find.text('Notifications'),
112+
enabled ? findsOneWidget : findsNothing,
113+
);
114+
expect(find.text('Push notifications'), findsNothing);
115+
if (enabled) {
116+
final toggle = tester.widget<Switch>(find.byType(Switch));
117+
expect(toggle.value, isTrue);
118+
expect(toggle.onChanged, isNotNull);
119+
} else {
120+
expect(find.byType(Switch), findsNothing);
121+
}
122+
expect(tester.takeException(), isNull);
123+
debugDefaultTargetPlatformOverride = null;
124+
},
106125
);
107-
await tester.pumpAndSettle();
108-
expect(find.text('Notifications'), findsNothing);
109-
expect(find.text('Push notifications'), findsNothing);
110-
expect(find.byType(Switch), findsNothing);
111-
expect(tester.takeException(), isNull);
112-
debugDefaultTargetPlatformOverride = null;
113-
});
126+
}
114127
}, skip: Env.pushGatewayConfigured);
115128
}

0 commit comments

Comments
 (0)