Skip to content

Commit f7fdd47

Browse files
committed
Revert "fix(mobile): push every message in your own Solo chats (#8615)"
This reverts commit bad9d26.
1 parent 770ab7f commit f7fdd47

10 files changed

Lines changed: 49 additions & 604 deletions

File tree

‎mobile/lib/features/settings/settings_page.dart‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import '../../shared/clipboard_utils.dart';
1515
import '../../shared/success_haptic.dart';
1616
import '../../shared/push/push_relay_capability_provider.dart';
1717
import '../../shared/push/push_bootstrap.dart';
18-
import '../../shared/push/push_subscription_provider.dart';
1918
import '../../shared/relay/relay.dart';
2019
import '../../shared/utils/string_utils.dart';
2120
import '../pairing/pairing_provider.dart';

‎mobile/lib/features/settings/settings_page/notifications_section.dart‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ class _NotificationsSection extends ConsumerWidget {
2525
return const SizedBox.shrink();
2626
}
2727
final canToggle = hasCapability || community.pushNotificationsEnabled;
28-
final omittedSoloChats = community.pushNotificationsEnabled
29-
? ref.watch(pushSubscriptionSyncProvider).value ?? 0
30-
: 0;
3128

3229
void setEnabled(bool enabled) {
3330
unawaited(
@@ -75,14 +72,6 @@ class _NotificationsSection extends ConsumerWidget {
7572
],
7673
),
7774
),
78-
if (omittedSoloChats > 0)
79-
AppListRow(
80-
key: const ValueKey('push-solo-coverage'),
81-
title: 'Older Solo chats notify only on mention',
82-
subtitle: omittedSoloChats == 1
83-
? '1 chat is past this relay’s notification limit.'
84-
: '$omittedSoloChats chats are past this relay’s notification limit.',
85-
),
8675
],
8776
);
8877
}

‎mobile/lib/shared/crypto/nip44.dart‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,6 @@ String nip44Decrypt(Uint8List conversationKey, String payloadBase64) {
8888
return _unpad(padded);
8989
}
9090

91-
/// Length of the base64 payload [nip44Encrypt] returns for a plaintext of
92-
/// [plaintextBytes] UTF-8 bytes, or null when NIP-44 cannot encrypt it.
93-
int? nip44PayloadLength(int plaintextBytes) {
94-
if (plaintextBytes < 1 || plaintextBytes > 65535) return null;
95-
// version(1) || nonce(32) || length(2) || padded || mac(32)
96-
final payload = 1 + 32 + 2 + _calcPaddedLen(plaintextBytes) + 32;
97-
return 4 * ((payload + 2) ~/ 3);
98-
}
99-
10091
// ── Padding ─────────────────────────────────────────────────────────────────
10192

10293
int _calcPaddedLen(int unpaddedLen) {

‎mobile/lib/shared/push/dev_push_lease.dart‎

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,6 @@ const _maxSafeJsonInteger = 9007199254740991;
1616
const _maxLeaseLifetimeSeconds = 2592000;
1717
const _lowercaseHex64Pattern = r'^[0-9a-f]{64}$';
1818
const _installationIdPattern = r'^[0-9a-f]{32}$';
19-
// The gateway's `<key id>.<base64url>` grant grammar, which JSON never escapes.
20-
const _endpointGrantPattern = r'^[A-Za-z0-9_.-]+$';
21-
22-
/// Whether an active lease carrying [subscriptions] fits [descriptor]'s
23-
/// plaintext and content limits with any endpoint grant and generation it
24-
/// accepts. Sizes are computed, not built, since the limits come from the relay.
25-
bool buzzPushSubscriptionsFitLease(
26-
BuzzPushLeaseDescriptor descriptor,
27-
List<BuzzPushSubscription> subscriptions,
28-
) {
29-
final withoutEndpoint = utf8
30-
.encode(
31-
_activeLeasePlaintext(
32-
descriptor: descriptor,
33-
endpoint: '',
34-
generation: _maxSafeJsonInteger,
35-
subscriptions: subscriptions,
36-
),
37-
)
38-
.length;
39-
// Publication accepts only grants JSON never escapes, so one at the endpoint
40-
// limit adds exactly it.
41-
final plaintext = withoutEndpoint + descriptor.maxEndpointLength;
42-
final content = nip44PayloadLength(plaintext);
43-
return plaintext <= descriptor.maxPlaintextLength &&
44-
content != null &&
45-
content <= descriptor.maxContentLength;
46-
}
47-
48-
String _activeLeasePlaintext({
49-
required BuzzPushLeaseDescriptor descriptor,
50-
required String endpoint,
51-
required int generation,
52-
required List<BuzzPushSubscription> subscriptions,
53-
}) => jsonEncode(<String, dynamic>{
54-
'v': 1,
55-
'origin': descriptor.origin,
56-
'transport': descriptor.transport,
57-
'endpoint': endpoint,
58-
'generation': generation,
59-
'active': true,
60-
'subscriptions': [
61-
for (final subscription in subscriptions) subscription.toJson(),
62-
],
63-
});
6419

6520
class BuzzPushLeaseDescriptor {
6621
final String origin;
@@ -376,12 +331,18 @@ Future<BuzzPushLeasePublication> publishBuzzDevPushLease({
376331
throw const FormatException('Endpoint grant is already expired');
377332
}
378333

379-
final plaintext = _activeLeasePlaintext(
380-
descriptor: descriptor,
381-
endpoint: grant.endpointGrant,
382-
generation: effectiveLeaseGeneration,
383-
subscriptions: subscriptions,
384-
);
334+
final plaintextMap = <String, dynamic>{
335+
'v': 1,
336+
'origin': descriptor.origin,
337+
'transport': descriptor.transport,
338+
'endpoint': grant.endpointGrant,
339+
'generation': effectiveLeaseGeneration,
340+
'active': true,
341+
'subscriptions': [
342+
for (final subscription in subscriptions) subscription.toJson(),
343+
],
344+
};
345+
final plaintext = jsonEncode(plaintextMap);
385346
if (utf8.encode(plaintext).length > descriptor.maxPlaintextLength) {
386347
throw const FormatException('lease plaintext exceeds the advertised limit');
387348
}
@@ -552,9 +513,6 @@ void _validateGrant(
552513
'Endpoint grant violates the advertised endpoint limit',
553514
);
554515
}
555-
if (!RegExp(_endpointGrantPattern).hasMatch(grant.endpointGrant)) {
556-
throw const FormatException('Endpoint grant is not a gateway grant');
557-
}
558516
if (grant.endpointEpoch <= 0) {
559517
throw const FormatException('Endpoint grant epoch is invalid');
560518
}

‎mobile/lib/shared/push/push_subscription.dart‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ const buzzPushMaxSubscriptions = 16;
1212
const buzzPushMaxIgnoreFilters = 8;
1313
const buzzPushHellthreadParticipantLimit = 20;
1414

15-
/// Channels one lease can follow channel-wide after its self-directed
16-
/// subscription, and muted channels its ignores can cover after the
17-
/// self-authored ignore.
18-
const buzzPushMaxChannelWideChannels =
19-
(buzzPushMaxSubscriptions - 1) * buzzPushChannelChunkSize;
20-
const buzzPushMaxMutedChannels =
21-
(buzzPushMaxIgnoreFilters - 1) * buzzPushChannelChunkSize;
22-
2315
const _supportedNotificationClasses = {'default'};
2416
const _filterKeys = {'kinds', 'authors', '#p', '#h', '#e'};
2517
final _exactHexPattern = RegExp(r'^[0-9a-f]{64}$');

‎mobile/lib/shared/push/push_subscription_provider.dart‎

Lines changed: 20 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -4,159 +4,68 @@ import '../../features/channels/channel.dart';
44
import '../../features/channels/channel_mutes/channel_mutes_provider.dart';
55
import '../../features/channels/channels_provider.dart';
66
import '../auth/auth.dart';
7-
import '../me/me_sync.dart';
87
import '../relay/relay_provider.dart';
9-
import 'dev_push_lease.dart';
108
import 'push_subscription.dart';
119
import 'push_relay_capability_provider.dart';
1210
import 'push_setup_recovery.dart';
1311

1412
/// Keeps the persisted desired lease and the App Group snapshot aligned with
1513
/// the active identity, joined channels, and mute state. This is desired client
1614
/// policy only. Relay-accepted authority is introduced by lease publication.
17-
///
18-
/// Yields how many Solo chats the lease had no room for.
19-
final pushSubscriptionSyncProvider = FutureProvider.autoDispose<int>((
15+
final pushSubscriptionSyncProvider = FutureProvider.autoDispose<void>((
2016
ref,
2117
) async {
2218
try {
2319
if (ref.watch(authProvider).value?.status != AuthStatus.authenticated) {
24-
return 0;
20+
return;
2521
}
2622
final active = ref.watch(activeCommunityProvider).value;
27-
final descriptor = ref.watch(currentRelayPushDescriptorProvider).value;
2823
if (active == null ||
2924
!active.pushNotificationsEnabled ||
30-
descriptor == null) {
31-
return 0;
25+
ref.watch(currentRelayPushDescriptorProvider).value == null) {
26+
return;
3227
}
3328
final channels = ref.watch(channelsProvider).value;
3429
final mutes = ref.watch(channelMutesProvider);
3530
if (channels == null || !mutes.isReady) {
36-
return 0;
31+
return;
3732
}
3833

39-
// Legacy Solo chats are listed only in the Solo record. Wait while it
40-
// loads so an unresolved record never drops them. If it fails without a
41-
// cached copy, keep DMs and mentions current; the Solo tab cannot list
42-
// those chats either, and recovery republishes them.
43-
final soloRecord = ref.watch(meGroupsProvider);
44-
if (soloRecord.isLoading && !soloRecord.hasValue) return 0;
45-
46-
final desired = desiredBuzzPushSubscriptions(
34+
final subscriptions = desiredBuzzPushSubscriptions(
4735
community: active,
48-
descriptor: descriptor,
4936
channels: channels,
50-
legacySoloChannelIds: soloRecord.value?.channels ?? const [],
5137
mutedChannelIds: [
5238
for (final entry in mutes.store.channels.entries)
5339
if (entry.value.muted) entry.key,
5440
],
5541
);
56-
if (desired == null) return 0;
42+
if (subscriptions == null) return;
5743
await ref
5844
.read(communityListProvider.notifier)
59-
.updateDesiredPushSubscriptions(active.id, desired.subscriptions);
60-
return desired.omittedSoloChats;
45+
.updateDesiredPushSubscriptions(active.id, subscriptions);
6146
} catch (error, stack) {
6247
reportPushSetupError('subscription synchronization', error, stack);
6348
rethrow;
6449
}
6550
}, retry: pushSetupRetry);
6651

67-
/// The desired lease, and how many Solo chats it had no room for.
68-
({List<BuzzPushSubscription> subscriptions, int omittedSoloChats})?
69-
desiredBuzzPushSubscriptions({
52+
List<BuzzPushSubscription>? desiredBuzzPushSubscriptions({
7053
required Community community,
71-
required BuzzPushLeaseDescriptor descriptor,
7254
required Iterable<Channel> channels,
7355
required Iterable<String> mutedChannelIds,
74-
Iterable<String> legacySoloChannelIds = const [],
7556
}) {
7657
final pubkey = community.pubkey ?? pubkeyFromNsec(community.nsec);
7758
if (pubkey == null || pubkey.isEmpty) return null;
78-
final muted = {for (final id in mutedChannelIds) id.toLowerCase()};
79-
final candidates = _channelWideCandidates(
80-
pubkey: pubkey,
81-
channels: channels,
82-
muted: muted,
83-
legacySoloChannelIds: legacySoloChannelIds,
84-
);
85-
List<BuzzPushSubscription> lease(int soloCount) =>
86-
buildDesiredBuzzPushSubscriptions(
87-
myPubkey: pubkey,
88-
channelIds: [...candidates.dms, ...candidates.solos.take(soloCount)],
89-
mutedChannelIds: mutedChannelIds,
90-
);
91-
92-
// Each Solo chat only adds bytes, so keep the most recent ones that fit.
93-
var fitting = candidates.solos.length;
94-
if (!buzzPushSubscriptionsFitLease(descriptor, lease(fitting))) {
95-
// Without Solo chats only DMs and mentions remain. A relay too small for
96-
// those cannot carry push, so fail setup rather than save a lease that
97-
// publication would reject.
98-
if (!buzzPushSubscriptionsFitLease(descriptor, lease(0))) {
99-
throw const FormatException(
100-
'The relay push limits are too small for a lease.',
101-
);
102-
}
103-
var low = 0;
104-
var high = fitting - 1;
105-
while (low < high) {
106-
final mid = (low + high + 1) ~/ 2;
107-
if (buzzPushSubscriptionsFitLease(descriptor, lease(mid))) {
108-
low = mid;
109-
} else {
110-
high = mid - 1;
111-
}
112-
}
113-
fitting = low;
114-
}
115-
return (
116-
subscriptions: lease(fitting),
117-
omittedSoloChats: candidates.omitted + candidates.solos.length - fitting,
118-
);
119-
}
120-
121-
/// Channel-wide traffic pushes only for joined DMs and the viewer's own Solo
122-
/// chats, which are conversations with them. Other channels push through an
123-
/// exact #p mention, so subscribing to every joined channel would over-notify.
124-
///
125-
/// DMs always stay, as before. Solo chats follow most recent first, within the
126-
/// lease's channel counts; the rest push only on mention.
127-
({List<String> dms, List<String> solos, int omitted}) _channelWideCandidates({
128-
required String pubkey,
129-
required Iterable<Channel> channels,
130-
required Set<String> muted,
131-
required Iterable<String> legacySoloChannelIds,
132-
}) {
133-
bool isMuted(String id) => muted.contains(id.toLowerCase());
134-
final joined = [
135-
for (final channel in channels)
136-
if (channel.isMember && !channel.isArchived) channel,
137-
];
138-
final dms = [
139-
for (final channel in joined)
140-
if (channel.isDm) channel.id,
141-
];
142-
// Muted Solo chats stay out, like muted channels, so they push only on
143-
// mention.
144-
final ordered = [
145-
for (final channel in joined)
146-
if (!channel.isDm &&
147-
!isMuted(channel.id) &&
148-
channel.isPersonalChat(pubkey, legacySoloChannelIds))
149-
channel,
150-
]..sort(_mostRecentFirst);
151-
final room =
152-
buzzPushMaxChannelWideChannels - dms.where((id) => !isMuted(id)).length;
153-
final solos = [for (final solo in ordered.take(room < 0 ? 0 : room)) solo.id];
154-
return (dms: dms, solos: solos, omitted: ordered.length - solos.length);
155-
}
156-
157-
int _mostRecentFirst(Channel a, Channel b) {
158-
final byRecency = (b.lastMessageAt ?? b.createdAt).compareTo(
159-
a.lastMessageAt ?? a.createdAt,
59+
return buildDesiredBuzzPushSubscriptions(
60+
myPubkey: pubkey,
61+
channelIds: [
62+
// Activity surfaces channel-wide traffic only for joined DM channels.
63+
// Other message kinds enter the inbox through an exact #p mention or
64+
// participant-thread tag, so subscribing to every joined channel would
65+
// over-notify compared with the product predicate.
66+
for (final channel in channels)
67+
if (channel.isDm && channel.isMember && !channel.isArchived) channel.id,
68+
],
69+
mutedChannelIds: mutedChannelIds,
16070
);
161-
return byRecency != 0 ? byRecency : a.id.compareTo(b.id);
16271
}

‎mobile/test/features/settings/settings_page_test.dart‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:buzz/shared/theme/theme.dart';
1212
import 'package:buzz/shared/push/push_bridge.dart';
1313
import 'package:buzz/shared/push/dev_push_lease.dart';
1414
import 'package:buzz/shared/push/push_relay_capability_provider.dart';
15-
import 'package:buzz/shared/push/push_subscription_provider.dart';
1615
import 'package:buzz/shared/relay/app_lifecycle_provider.dart';
1716
import 'package:buzz/shared/widgets/app_list.dart';
1817
import 'package:buzz/shared/widgets/app_list_card.dart';
@@ -171,8 +170,6 @@ void main() {
171170
savedPrefsProvider.overrideWithValue(prefs),
172171
activeCommunityProvider.overrideWith((ref) async => community),
173172
currentRelayPushDescriptorProvider.overrideWith((ref) => capability),
174-
// The lease had no room for 12 older Solo chats.
175-
pushSubscriptionSyncProvider.overrideWith((ref) async => 12),
176173
appLifecycleProvider.overrideWith(_SettingsLifecycleNotifier.new),
177174
buzzPushAuthorizationStatusReaderProvider.overrideWithValue(
178175
() async => BuzzPushAuthorizationStatus.authorized,
@@ -194,14 +191,6 @@ void main() {
194191
findsOneWidget,
195192
);
196193
expect(tester.widget<Switch>(find.byType(Switch)).value, isTrue);
197-
expect(
198-
find.text('Older Solo chats notify only on mention'),
199-
findsOneWidget,
200-
);
201-
expect(
202-
find.text('12 chats are past this relay’s notification limit.'),
203-
findsOneWidget,
204-
);
205194
debugDefaultTargetPlatformOverride = null;
206195
});
207196

‎mobile/test/shared/crypto/nip44_interop_test.dart‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,4 @@ void main() {
1818
'{"version":1,"theme":"catppuccin-latte","accent":"#f97316","followSystem":false}',
1919
);
2020
});
21-
22-
test('predicts the encrypted payload length at every padding boundary', () {
23-
final key = getConversationKey(
24-
'0000000000000000000000000000000000000000000000000000000000000001',
25-
'79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
26-
);
27-
for (final length in [
28-
1, 32, 33, 256, 257, 4096, 4097, 32768, 32769, 65535, //
29-
]) {
30-
expect(
31-
nip44PayloadLength(length),
32-
nip44Encrypt(key, 'x' * length).length,
33-
reason: '$length bytes',
34-
);
35-
}
36-
expect(nip44PayloadLength(0), isNull);
37-
expect(nip44PayloadLength(65536), isNull);
38-
});
3921
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,8 @@ const _descriptor = BuzzPushLeaseDescriptor(
423423
executorPubkey: 'pubkey',
424424
transport: 'apns',
425425
maxLeaseTtlSeconds: 3600,
426-
// The relay's NIP-11 limits, which fit a DM lease at the endpoint limit.
427-
maxContentLength: 65536,
428-
maxPlaintextLength: 32768,
426+
maxContentLength: 4096,
427+
maxPlaintextLength: 4096,
429428
maxEndpointLength: 2048,
430429
maxStringLength: 512,
431430
);

0 commit comments

Comments
 (0)