@@ -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})?
6975desiredBuzzPushSubscriptions ({
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
161183int _mostRecentFirst (Channel a, Channel b) {
0 commit comments