mirror of
https://github.com/block/buzz.git
synced 2026-11-05 17:01:35 +00:00
fix(mobile): treat muted Solo chats like muted channels in the push lease
Muted Solo chats stay out of the lease, as muted channels always have, so they push only on mention. This removes the separate muted budget, past which some muted Solo chats were silent and others notified on mention. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
@@ -139,22 +139,18 @@ desiredBuzzPushSubscriptions({
|
||||
for (final channel in joined)
|
||||
if (channel.isDm) channel.id,
|
||||
];
|
||||
// Muted Solo chats stay out, like muted channels, so they push only on
|
||||
// mention.
|
||||
final ordered = [
|
||||
for (final channel in joined)
|
||||
if (!channel.isDm && channel.isPersonalChat(pubkey, legacySoloChannelIds))
|
||||
if (!channel.isDm &&
|
||||
!isMuted(channel.id) &&
|
||||
channel.isPersonalChat(pubkey, legacySoloChannelIds))
|
||||
channel,
|
||||
]..sort(_mostRecentFirst);
|
||||
|
||||
var unmutedRoom =
|
||||
final room =
|
||||
buzzPushMaxChannelWideChannels - dms.where((id) => !isMuted(id)).length;
|
||||
var mutedRoom = buzzPushMaxMutedChannels - dms.where(isMuted).length;
|
||||
final solos = <String>[];
|
||||
for (final solo in ordered) {
|
||||
final soloMuted = isMuted(solo.id);
|
||||
if ((soloMuted ? mutedRoom : unmutedRoom) <= 0) continue;
|
||||
solos.add(solo.id);
|
||||
soloMuted ? mutedRoom-- : unmutedRoom--;
|
||||
}
|
||||
final solos = [for (final solo in ordered.take(room < 0 ? 0 : room)) solo.id];
|
||||
return (dms: dms, solos: solos, omitted: ordered.length - solos.length);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +87,10 @@ void main() {
|
||||
mutedChannelIds: const [mutedSoloID],
|
||||
)?.subscriptions;
|
||||
|
||||
// A muted Solo chat is left out, like a muted channel, so only a
|
||||
// mention pushes it.
|
||||
expect(subscriptions, hasLength(2));
|
||||
expect(subscriptions!.first.ignore.last.hTags, [mutedSoloID]);
|
||||
expect(subscriptions!.first.ignore, hasLength(1));
|
||||
expect(subscriptions.last.filter.kinds, buzzPushChannelKinds);
|
||||
expect(subscriptions.last.filter.hTags, [dmID, soloID, legacySoloID]);
|
||||
});
|
||||
@@ -132,21 +134,14 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
for (final (limit, descriptor, soloCount, mutedSolos) in [
|
||||
for (final (limit, descriptor, soloCount) in [
|
||||
(
|
||||
'plaintext',
|
||||
_descriptor(contentLength: 65536, plaintextLength: 32768),
|
||||
_descriptor(contentLength: 65536, plaintextLength: 16384),
|
||||
400,
|
||||
100,
|
||||
),
|
||||
(
|
||||
'content',
|
||||
_descriptor(contentLength: 24000, plaintextLength: 32768),
|
||||
400,
|
||||
100,
|
||||
),
|
||||
('muted channel count', _descriptor(), 400, 400),
|
||||
('NIP-44 plaintext', _descriptor(), 600, 200),
|
||||
('content', _descriptor(contentLength: 24000, plaintextLength: 32768), 400),
|
||||
('NIP-44 plaintext', _descriptor(endpointLength: 40000), 700),
|
||||
]) {
|
||||
test('keeps the newest Solo chats within the $limit limit', () async {
|
||||
final keys = nostr.Keys.generate();
|
||||
@@ -156,24 +151,16 @@ void main() {
|
||||
for (var n = dmCount; n < dmCount + soloCount; n++)
|
||||
_solo(n, keys.public),
|
||||
];
|
||||
// Muted chats are the newest, so every lease filter ignores them.
|
||||
final muted = [
|
||||
for (var n = channels.length - mutedSolos; n < channels.length; n++)
|
||||
_id(n),
|
||||
];
|
||||
|
||||
final desired = desiredBuzzPushSubscriptions(
|
||||
community: _community(keys),
|
||||
descriptor: descriptor,
|
||||
channels: channels,
|
||||
mutedChannelIds: muted,
|
||||
mutedChannelIds: const [],
|
||||
)!;
|
||||
|
||||
final kept = {
|
||||
for (final subscription in desired.subscriptions.skip(1))
|
||||
...?subscription.filter.hTags,
|
||||
for (final ignore in desired.subscriptions.first.ignore.skip(1))
|
||||
...?ignore.hTags,
|
||||
};
|
||||
final keptSolos = soloCount - desired.omittedSoloChats;
|
||||
expect(keptSolos, inInclusiveRange(1, soloCount - 1));
|
||||
|
||||
Reference in New Issue
Block a user