Skip to content

Commit 0ca4874

Browse files
browclaude
andcommitted
fix(mobile): warn when muted Solo chats are past the push lease limit
A muted Solo chat the lease has no room for loses its mute ignore, so a mention there still notifies. Count those chats, whether dropped by the mute budget or by size trimming, and say so in Notifications settings. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent ba699a4 commit 0ca4874

4 files changed

Lines changed: 73 additions & 26 deletions

File tree

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ 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;
28+
final overflow = community.pushNotificationsEnabled
29+
? ref.watch(pushSubscriptionSyncProvider).value
30+
: null;
3131

3232
void setEnabled(bool enabled) {
3333
unawaited(
@@ -75,15 +75,26 @@ class _NotificationsSection extends ConsumerWidget {
7575
],
7676
),
7777
),
78-
if (omittedSoloChats > 0)
78+
if (overflow != null && overflow.chats > 0)
7979
AppListRow(
8080
key: const ValueKey('push-solo-coverage'),
8181
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.',
82+
subtitle: _soloOverflowText(overflow),
8583
),
8684
],
8785
);
8886
}
8987
}
88+
89+
String _soloOverflowText(SoloOverflow overflow) {
90+
final past = overflow.chats == 1
91+
? '1 chat is past this relay’s notification limit.'
92+
: '${overflow.chats} chats are past this relay’s notification limit.';
93+
if (overflow.muted == 0) return past;
94+
if (overflow.chats == 1) {
95+
return '$past It is muted but still notifies on mention.';
96+
}
97+
return overflow.muted == 1
98+
? '$past 1 of them is muted but still notifies on mention.'
99+
: '$past ${overflow.muted} of them are muted but still notify on mention.';
100+
}

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

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ import 'push_setup_recovery.dart';
1515
/// the active identity, joined channels, and mute state. This is desired client
1616
/// policy only. Relay-accepted authority is introduced by lease publication.
1717
///
18-
/// Yields how many Solo chats the lease had no room for.
19-
final pushSubscriptionSyncProvider = FutureProvider.autoDispose<int>((
18+
/// Yields the Solo chats the lease had no room for.
19+
final pushSubscriptionSyncProvider = FutureProvider.autoDispose<SoloOverflow>((
2020
ref,
2121
) async {
2222
try {
2323
if (ref.watch(authProvider).value?.status != AuthStatus.authenticated) {
24-
return 0;
24+
return _noOverflow;
2525
}
2626
final active = ref.watch(activeCommunityProvider).value;
2727
final descriptor = ref.watch(currentRelayPushDescriptorProvider).value;
2828
if (active == null ||
2929
!active.pushNotificationsEnabled ||
3030
descriptor == null) {
31-
return 0;
31+
return _noOverflow;
3232
}
3333
final channels = ref.watch(channelsProvider).value;
3434
final mutes = ref.watch(channelMutesProvider);
3535
if (channels == null || !mutes.isReady) {
36-
return 0;
36+
return _noOverflow;
3737
}
3838

3939
// Legacy Solo chats are listed only in the Solo record. Wait while it
4040
// loads so an unresolved record never drops them. If it fails without a
4141
// cached copy, keep DMs and mentions current; the Solo tab cannot list
4242
// those chats either, and recovery republishes them.
4343
final soloRecord = ref.watch(meGroupsProvider);
44-
if (soloRecord.isLoading && !soloRecord.hasValue) return 0;
44+
if (soloRecord.isLoading && !soloRecord.hasValue) return _noOverflow;
4545

4646
final desired = desiredBuzzPushSubscriptions(
4747
community: active,
@@ -53,19 +53,25 @@ final pushSubscriptionSyncProvider = FutureProvider.autoDispose<int>((
5353
if (entry.value.muted) entry.key,
5454
],
5555
);
56-
if (desired == null) return 0;
56+
if (desired == null) return _noOverflow;
5757
await ref
5858
.read(communityListProvider.notifier)
5959
.updateDesiredPushSubscriptions(active.id, desired.subscriptions);
60-
return desired.omittedSoloChats;
60+
return desired.overflow;
6161
} catch (error, stack) {
6262
reportPushSetupError('subscription synchronization', error, stack);
6363
rethrow;
6464
}
6565
}, retry: pushSetupRetry);
6666

67-
/// The desired lease, and how many Solo chats it had no room for.
68-
({List<BuzzPushSubscription> subscriptions, int omittedSoloChats})?
67+
/// Solo chats a lease had no room for, and how many of those are muted.
68+
/// Mentions in a muted one still notify, since its mute ignore did not fit.
69+
typedef SoloOverflow = ({int chats, int muted});
70+
71+
const SoloOverflow _noOverflow = (chats: 0, muted: 0);
72+
73+
/// The desired lease, and the Solo chats it had no room for.
74+
({List<BuzzPushSubscription> subscriptions, SoloOverflow overflow})?
6975
desiredBuzzPushSubscriptions({
7076
required Community community,
7177
required BuzzPushLeaseDescriptor descriptor,
@@ -112,9 +118,15 @@ desiredBuzzPushSubscriptions({
112118
}
113119
fitting = low;
114120
}
121+
final trimmed = candidates.solos.skip(fitting);
115122
return (
116123
subscriptions: lease(fitting),
117-
omittedSoloChats: candidates.omitted + candidates.solos.length - fitting,
124+
overflow: (
125+
chats: candidates.omitted + trimmed.length,
126+
muted:
127+
candidates.omittedMuted +
128+
trimmed.where((id) => muted.contains(id.toLowerCase())).length,
129+
),
118130
);
119131
}
120132

@@ -124,7 +136,8 @@ desiredBuzzPushSubscriptions({
124136
///
125137
/// DMs always stay, as before. Solo chats follow most recent first, within the
126138
/// lease's channel counts; the rest push only on mention.
127-
({List<String> dms, List<String> solos, int omitted}) _channelWideCandidates({
139+
({List<String> dms, List<String> solos, int omitted, int omittedMuted})
140+
_channelWideCandidates({
128141
required String pubkey,
129142
required Iterable<Channel> channels,
130143
required Set<String> muted,
@@ -149,13 +162,22 @@ desiredBuzzPushSubscriptions({
149162
buzzPushMaxChannelWideChannels - dms.where((id) => !isMuted(id)).length;
150163
var mutedRoom = buzzPushMaxMutedChannels - dms.where(isMuted).length;
151164
final solos = <String>[];
165+
var omittedMuted = 0;
152166
for (final solo in ordered) {
153167
final soloMuted = isMuted(solo.id);
154-
if ((soloMuted ? mutedRoom : unmutedRoom) <= 0) continue;
168+
if ((soloMuted ? mutedRoom : unmutedRoom) <= 0) {
169+
if (soloMuted) omittedMuted++;
170+
continue;
171+
}
155172
solos.add(solo.id);
156173
soloMuted ? mutedRoom-- : unmutedRoom--;
157174
}
158-
return (dms: dms, solos: solos, omitted: ordered.length - solos.length);
175+
return (
176+
dms: dms,
177+
solos: solos,
178+
omitted: ordered.length - solos.length,
179+
omittedMuted: omittedMuted,
180+
);
159181
}
160182

161183
int _mostRecentFirst(Channel a, Channel b) {

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ void main() {
171171
savedPrefsProvider.overrideWithValue(prefs),
172172
activeCommunityProvider.overrideWith((ref) async => community),
173173
currentRelayPushDescriptorProvider.overrideWith((ref) => capability),
174-
// The lease had no room for 12 older Solo chats.
175-
pushSubscriptionSyncProvider.overrideWith((ref) async => 12),
174+
// The lease had no room for 12 older Solo chats, 3 of them muted.
175+
pushSubscriptionSyncProvider.overrideWith(
176+
(ref) async => (chats: 12, muted: 3),
177+
),
176178
appLifecycleProvider.overrideWith(_SettingsLifecycleNotifier.new),
177179
buzzPushAuthorizationStatusReaderProvider.overrideWithValue(
178180
() async => BuzzPushAuthorizationStatus.authorized,
@@ -199,7 +201,10 @@ void main() {
199201
findsOneWidget,
200202
);
201203
expect(
202-
find.text('12 chats are past this relay’s notification limit.'),
204+
find.text(
205+
'12 chats are past this relay’s notification limit. '
206+
'3 of them are muted but still notify on mention.',
207+
),
203208
findsOneWidget,
204209
);
205210
debugDefaultTargetPlatformOverride = null;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dart:async';
2+
import 'dart:math' as math;
23

34
import 'package:buzz/features/channels/channel.dart';
45
import 'package:buzz/features/channels/channel_mutes/channel_mutes_provider.dart';
@@ -118,7 +119,7 @@ void main() {
118119
expect(followed, containsAll([for (var n = 0; n < dmCount; n++) _id(n)]));
119120
expect(followed, contains(_id(channels.length - 1)));
120121
expect(followed, isNot(contains(_id(dmCount + dmCount - 1))));
121-
expect(desired.omittedSoloChats, dmCount);
122+
expect(desired.overflow, (chats: dmCount, muted: 0));
122123

123124
// A relay may advertise any endpoint limit; sizing must not allocate it.
124125
expect(
@@ -145,6 +146,12 @@ void main() {
145146
400,
146147
100,
147148
),
149+
(
150+
'content, trimming muted chats,',
151+
_descriptor(contentLength: 24000, plaintextLength: 32768),
152+
400,
153+
300,
154+
),
148155
('muted channel count', _descriptor(), 400, 400),
149156
('NIP-44 plaintext', _descriptor(), 600, 200),
150157
]) {
@@ -175,8 +182,10 @@ void main() {
175182
for (final ignore in desired.subscriptions.first.ignore.skip(1))
176183
...?ignore.hTags,
177184
};
178-
final keptSolos = soloCount - desired.omittedSoloChats;
185+
final keptSolos = soloCount - desired.overflow.chats;
179186
expect(keptSolos, inInclusiveRange(1, soloCount - 1));
187+
// Omitted muted chats lose their mute ignore, so Settings counts them.
188+
expect(desired.overflow.muted, math.max(0, mutedSolos - keptSolos));
180189
expect(kept, {
181190
for (var n = 0; n < dmCount; n++) _id(n),
182191
for (var n = channels.length - keptSolos; n < channels.length; n++)

0 commit comments

Comments
 (0)