Fix false repeat flags, add repeat-sends setting, limit holiday animations

Message filter:
- Ignore copies of a message already seen (same sender, text and send
  second). Switching between companions re-synced messages the first one
  had delivered; they missed per-radio storage dedup and were flagged as
  repeats.
- Exempt replies and @[name] mentions from repeat detection.
- New "Sends to count as a repeat" setting (2-5, default 2). Each send
  must fall within 10 minutes of the previous one.
- Translations for the new strings in all locales.

Holiday animations:
- Only one plays at a time; greetings arriving while one is playing or
  within 5 seconds after it ends are dropped, not queued.
- Christmas map "self" marker: Santa hat was upside down.
This commit is contained in:
zjs81 committed 2026-11-08 01:33:05 -07:00
1 parent 59e571fb20
commit ddf0b9f553
52 files changed
+526 -24

No files matched your search

+41
View File
@@ -69,8 +69,12 @@ void main() {
group('HolidayTriggerWatcher', () {
late AppSettingsService settings;
late DateTime now;
setUp(() async {
now = DateTime(2026, 12, 25, 12);
holidayAnimationClock = () => now;
resetHolidayAnimationGate();
SharedPreferences.setMockInitialValues({});
await PrefsManager.initialize();
settings = AppSettingsService();
@@ -147,6 +151,7 @@ void main() {
) async {
final ctx = await host(tester);
for (final animation in HolidayAnimation.values) {
now = now.add(holidayAnimationMinInterval);
playHolidayAnimation(ctx, animation, origin: const Offset(80, 500));
await tester.pump();
expect(find.byType(HolidayAnimationView), findsOneWidget);
@@ -157,6 +162,42 @@ void main() {
}
});
testWidgets('one at a time, then 5 quiet seconds after it ends', (
tester,
) async {
final ctx = await host(tester);
void play(HolidayAnimation a) =>
playHolidayAnimation(ctx, a, origin: Offset.zero);
play(HolidayAnimation.christmas);
await tester.pump();
expect(find.byType(HolidayAnimationView), findsOneWidget);
// Still playing: a second greeting is dropped, not stacked or queued.
now = now.add(const Duration(seconds: 30));
play(HolidayAnimation.newYear);
await tester.pump();
expect(find.byType(HolidayAnimationView), findsOneWidget);
await tester.pumpAndSettle(); // christmas ends at `now`
expect(find.byType(HolidayAnimationView), findsNothing);
// Nothing was queued behind it.
await tester.pump(const Duration(seconds: 10));
expect(find.byType(HolidayAnimationView), findsNothing);
// Under 5 seconds after it ended: dropped.
now = now.add(const Duration(seconds: 4));
play(HolidayAnimation.newYear);
await tester.pump();
expect(find.byType(HolidayAnimationView), findsNothing);
// 5 seconds after it ended: plays.
now = now.add(const Duration(seconds: 1));
play(HolidayAnimation.newYear);
await tester.pump();
expect(find.byType(HolidayAnimationView), findsOneWidget);
await tester.pumpAndSettle();
});
testWidgets('respects the setting and reduced motion', (tester) async {
await settings.setHolidayAnimationsEnabled(false);
var ctx = await host(tester);
@@ -27,6 +27,56 @@ void main() {
);
});
test('sameSenderSends sets which send in a row is flagged', () {
final tracker = DuplicateTracker();
const text = 'Anyone on the hill repeater?';
FilterReason? send(int minutes) => tracker.check(
channelId: 'c',
sender: 'Bob',
text: text,
at: t0.add(Duration(minutes: minutes)),
sameSenderSends: 3,
);
expect(send(0), isNull);
// Re-sent because nobody answered.
expect(send(4), isNull);
expect(send(9), FilterReason.duplicate);
// A slow flood keeps the run going: each send is within the window of
// the previous one.
expect(send(17), FilterReason.duplicate);
expect(send(25), FilterReason.duplicate);
});
test('the same message seen again is never a repeat', () {
final tracker = DuplicateTracker();
const text = 'Gday from Brunkerville, how is everyone';
// Another companion syncing messages the first one already delivered:
// same sender, text and send second, arriving later.
for (var i = 0; i < 5; i++) {
expect(
tracker.check(
channelId: 'c',
sender: 'VK2WSL TRACKER',
text: text,
at: t0,
receivedAt: t0.add(Duration(minutes: i)),
),
isNull,
);
}
// Copies are not counted: a real re-send is only the second send.
expect(
tracker.check(
channelId: 'c',
sender: 'VK2WSL TRACKER',
text: text,
at: t0.add(const Duration(minutes: 2)),
sameSenderSends: 3,
),
isNull,
);
});
test('short replies repeated by the same sender are not duplicates', () {
final tracker = DuplicateTracker();
for (final text in ['ok', 'test', 'yes sir', 'ok']) {
@@ -204,8 +204,10 @@ void main() {
test('duplicates setting off still records but does not filter', () async {
await service.updateSettings(service.settings.copyWith(duplicates: false));
expect(eval('a', 'meet at the park'), isNull);
expect(eval('a', 'meet at the park'), isNull);
for (var i = 0; i < 3; i++) {
expect(eval('a', 'meet at the park'), isNull);
now = now.add(const Duration(minutes: 1));
}
await service.updateSettings(service.settings.copyWith(duplicates: true));
expect(eval('a', 'meet at the park')?.reason, FilterReason.duplicate);
});
@@ -216,13 +218,55 @@ void main() {
eval('a', 'buy cheap radios here now')?.reason,
FilterReason.textRule,
);
now = now.add(const Duration(minutes: 1));
expect(
eval('a', 'buy cheap radios here now')?.reason,
FilterReason.textRule,
);
await service.removeRule('x');
now = now.add(const Duration(minutes: 1));
expect(
eval('a', 'buy cheap radios here now')?.reason,
FilterReason.duplicate,
);
});
test('repeatSends setting picks which send is flagged', () async {
await service.updateSettings(service.settings.copyWith(repeatSends: 3));
expect(eval('a', 'meet at the park'), isNull);
now = now.add(const Duration(minutes: 1));
expect(eval('a', 'meet at the park'), isNull);
now = now.add(const Duration(minutes: 1));
expect(eval('a', 'meet at the park')?.reason, FilterReason.duplicate);
});
test('repeatSends is saved and clamped', () {
const settings = MessageFilterSettings(repeatSends: 4);
expect(MessageFilterSettings.fromJson(settings.toJson()).repeatSends, 4);
expect(MessageFilterSettings.fromJson({}).repeatSends, 2);
expect(MessageFilterSettings.fromJson({'repeatSends': 99}).repeatSends, 5);
expect(MessageFilterSettings.fromJson({'repeatSends': 0}).repeatSends, 2);
});
test('messages that mention someone are exempt from duplicates', () {
for (var i = 0; i < 4; i++) {
// Asking several people the same thing.
expect(eval('a', '@[Person$i] are you home yet'), isNull);
expect(
service.evaluate(
channelId: _channel,
sender: 'b',
text: 'did you get my message',
isReply: true,
),
isNull,
);
now = now.add(const Duration(minutes: 1));
}
// Mentions were not recorded, so the plain text starts fresh.
expect(eval('a', 'are you home yet'), isNull);
});
test('not spam exempts duplicates in that channel', () async {
eval('a', 'meet at the park');
await service.markNotSpam(