@@ -4,159 +4,68 @@ import '../../features/channels/channel.dart';
44import '../../features/channels/channel_mutes/channel_mutes_provider.dart' ;
55import '../../features/channels/channels_provider.dart' ;
66import '../auth/auth.dart' ;
7- import '../me/me_sync.dart' ;
87import '../relay/relay_provider.dart' ;
9- import 'dev_push_lease.dart' ;
108import 'push_subscription.dart' ;
119import 'push_relay_capability_provider.dart' ;
1210import '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}
0 commit comments