mirror of
https://github.com/block/buzz.git
synced 2026-10-27 20:41:57 +00:00
fix(mobile): reset community notification preferences (#8455)
Community notification choices now use `pushNotificationsEnabledV2`, defaulting ON when absent. This gives every installed community a fresh enabled preference, including communities previously disabled. Subsequent explicit OFF choices persist per community through reloads and reconnects. Previous values are deliberately discarded, not migrated or preserved. There is no migration or compatibility read. Enabled communities enter the existing APNs enrollment and active relay lease publication path when connected to a push-capable relay. iOS still controls notification display authorization. Notification eligibility and lease addressing are unchanged. Related work: [#8425](https://github.com/block/buzz/pull/8425). ### Validation - Extended the settings integration test to load a saved community with the previous preference OFF and no new preference and verify native enrollment plus decrypted active lease publication, then OFF across reconnect and ON again. - The focused model test proves both previous values are ignored and new-key OFF wins even when the previous key says ON. A temporary compatibility-fallback mutation failed this test as expected; the implementation was restored unchanged. - Added storage coverage for independent community choices across reloads; updated existing model round-trip coverage for the new key. - Mobile dependency setup, formatting, analysis, and the full mobile suite passed, including gateway-unconfigured coverage. - Agent review found no blockers. Enrollment coverage uses the real Flutter bootstrap, storage, signing, and lease construction with mocked native and relay boundaries; no physical-device or live APNs delivery test was run. The fresh enabled preference is an intentional product exception to the general zero-notification default in VISION.md. Subsequent user choices and existing eligibility filters remain authoritative. <!-- buzz-review-completed --> --------- Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -21,6 +21,8 @@ enum SensitiveActionPolicy { enabled, disabledByUser }
|
||||
class Community {
|
||||
static const _defaultPushNotificationsEnabled = true;
|
||||
|
||||
static const _pushNotificationsEnabledKey = 'pushNotificationsEnabledV2';
|
||||
|
||||
final String id;
|
||||
final String name;
|
||||
final String relayUrl;
|
||||
@@ -115,7 +117,7 @@ class Community {
|
||||
if (pubkey != null) 'pubkey': pubkey,
|
||||
if (nsec != null) 'nsec': nsec,
|
||||
'sensitiveActionPolicy': sensitiveActionPolicy.name,
|
||||
'pushNotificationsEnabled': pushNotificationsEnabled,
|
||||
_pushNotificationsEnabledKey: pushNotificationsEnabled,
|
||||
'pushSubscriptionState': pushSubscriptionState.toJson(),
|
||||
if (pushLeaseInstallationId != null)
|
||||
'pushLeaseInstallationId': pushLeaseInstallationId,
|
||||
@@ -132,7 +134,7 @@ class Community {
|
||||
);
|
||||
}
|
||||
final pushNotificationsEnabled =
|
||||
json['pushNotificationsEnabled'] as bool? ??
|
||||
json[_pushNotificationsEnabledKey] as bool? ??
|
||||
_defaultPushNotificationsEnabled;
|
||||
var pushSubscriptionState = json['pushSubscriptionState'] == null
|
||||
? const BuzzPushLeaseSubscriptionState.desired()
|
||||
|
||||
@@ -37,7 +37,13 @@ void main() {
|
||||
..addFont(rootBundle.load('assets/fonts/InterVariable.ttf'));
|
||||
await fonts.load();
|
||||
});
|
||||
for (final outcome in ['accepted', 'failed', 'pending', 'scaled']) {
|
||||
for (final outcome in [
|
||||
'accepted',
|
||||
'failed',
|
||||
'pending',
|
||||
'scaled',
|
||||
'unset preference',
|
||||
]) {
|
||||
testWidgets('off then on remains usable with $outcome cleanup', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -61,7 +67,8 @@ void main() {
|
||||
);
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final storage = CommunityStorage(secure: FakeSecureStorage());
|
||||
final secure = FakeSecureStorage();
|
||||
final storage = CommunityStorage(secure: secure);
|
||||
final subscriptions = [
|
||||
BuzzPushSubscription(
|
||||
filter: BuzzPushFilter(kinds: const [9], pTags: ['a' * 64]),
|
||||
@@ -110,7 +117,13 @@ void main() {
|
||||
desired: subscriptions,
|
||||
).withAccepted(subscriptions: subscriptions, generation: 7),
|
||||
);
|
||||
await storage.save(community);
|
||||
if (outcome == 'unset preference') {
|
||||
final saved = community.toJson()..remove('pushNotificationsEnabledV2');
|
||||
saved['pushNotificationsEnabled'] = false;
|
||||
secure['buzz_communities'] = jsonEncode([saved]);
|
||||
} else {
|
||||
await storage.save(community);
|
||||
}
|
||||
await storage.saveActiveId(community.id);
|
||||
|
||||
final cleanup = Completer<void>();
|
||||
@@ -236,6 +249,15 @@ void main() {
|
||||
reason: 'failed cleanup must not defeat the retry backoff',
|
||||
);
|
||||
expect(discoveries, 2);
|
||||
session.setStatus(SessionStatus.disconnected);
|
||||
await tester.pumpAndSettle();
|
||||
session.setStatus(SessionStatus.connected);
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
session.leases.where((lease) => lease['active'] == true),
|
||||
hasLength(1),
|
||||
);
|
||||
expect(discoveries, 3);
|
||||
expect(snapshots.last.single.pushNotificationsEnabled, isFalse);
|
||||
final offSwitch = tester.widget<Switch>(find.byType(Switch));
|
||||
expect(offSwitch.value, isFalse);
|
||||
@@ -273,7 +295,7 @@ void main() {
|
||||
isTrue,
|
||||
reason: 'a delayed old tombstone cannot supersede the new active lease',
|
||||
);
|
||||
expect(discoveries, 3);
|
||||
expect(discoveries, 4);
|
||||
// A real reconnect must still discover capability again.
|
||||
(container.read(relaySessionProvider.notifier) as _Connected).setStatus(
|
||||
SessionStatus.disconnected,
|
||||
@@ -284,7 +306,7 @@ void main() {
|
||||
SessionStatus.connected,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(discoveries, 4);
|
||||
expect(discoveries, 5);
|
||||
expect(tester.widget<Switch>(find.byType(Switch)).onChanged, isNotNull);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox.shrink());
|
||||
|
||||
@@ -127,6 +127,33 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
test('push choices persist independently across storage reloads', () async {
|
||||
final first = Community.create(
|
||||
name: 'First',
|
||||
relayUrl: 'https://first.example',
|
||||
pubkey: 'a' * 64,
|
||||
);
|
||||
final second = Community.create(
|
||||
name: 'Second',
|
||||
relayUrl: 'https://second.example',
|
||||
pubkey: 'b' * 64,
|
||||
);
|
||||
await storage.saveAll([first, second]);
|
||||
await storage.save(first.copyWith(pushNotificationsEnabled: false));
|
||||
|
||||
final reloaded = CommunityStorage(secure: fakeSecure);
|
||||
final communities = await reloaded.loadAll();
|
||||
expect(communities.map((c) => c.pushNotificationsEnabled), [false, true]);
|
||||
expect(communities.map((c) => c.pubkey), [first.pubkey, second.pubkey]);
|
||||
await reloaded.save(communities.last.copyWith(name: 'Renamed'));
|
||||
expect(
|
||||
(await CommunityStorage(
|
||||
secure: fakeSecure,
|
||||
).loadAll()).map((c) => c.pushNotificationsEnabled),
|
||||
[false, true],
|
||||
);
|
||||
});
|
||||
|
||||
test('round-trips desired push subscription state', () async {
|
||||
final pubkey = 'a' * 64;
|
||||
final subscriptions = buildDesiredBuzzPushSubscriptions(
|
||||
|
||||
@@ -59,7 +59,8 @@ void main() {
|
||||
'id': 'one',
|
||||
'name': 'Buzz',
|
||||
'relayUrl': 'https://relay.test',
|
||||
'pushNotificationsEnabled': enabled,
|
||||
'pushNotificationsEnabledV2': enabled,
|
||||
'pushNotificationsEnabled': !enabled,
|
||||
'addedAt': '2026-08-05T00:00:00.000Z',
|
||||
});
|
||||
expect(community.pushNotificationsEnabled, enabled);
|
||||
@@ -78,6 +79,19 @@ void main() {
|
||||
});
|
||||
}
|
||||
|
||||
test('previous preference values are intentionally not preserved', () {
|
||||
for (final previous in [false, true]) {
|
||||
final saved = Community.create(
|
||||
name: 'Team',
|
||||
relayUrl: 'https://relay.test',
|
||||
).toJson()..remove('pushNotificationsEnabledV2');
|
||||
saved['pushNotificationsEnabled'] = previous;
|
||||
final community = Community.fromJson(saved);
|
||||
expect(community.pushNotificationsEnabled, isTrue);
|
||||
expect(community.toJson(), isNot(contains('pushNotificationsEnabled')));
|
||||
}
|
||||
});
|
||||
|
||||
test('malformed stored push lease address id is rejected', () {
|
||||
expect(
|
||||
() => Community.fromJson({
|
||||
|
||||
Reference in New Issue
Block a user