diff --git a/assets/themes/christmas/map_self.jxl b/assets/themes/christmas/map_self.jxl index 5c5ac7de..ee6dfe7f 100644 Binary files a/assets/themes/christmas/map_self.jxl and b/assets/themes/christmas/map_self.jxl differ diff --git a/documentation/message-filter.md b/documentation/message-filter.md index 072896eb..9416f791 100644 --- a/documentation/message-filter.md +++ b/documentation/message-filter.md @@ -27,8 +27,9 @@ The message is then checked in this order. The first check that matches decides, 2. **Text rule**: one of your rules matches the message text. 3. **Repeated characters** (automatic): one character repeated 20 or more times in a row, such as "aaaaaaaaaaaaaaaaaaaa". Digits and spaces don't count, so long numbers (frequencies, coordinates) are safe. Shorter runs, like "Noooooooo!", a `--------` separator or a row of emoji, are ordinary chat and are left alone. 4. **Repeated messages** (automatic): - - The **same sender** sends the same message again within 10 minutes. This only applies to messages of at least 3 words and 10 characters, because people naturally repeat short replies such as "ok", "yes" or "test". + - The **same sender** sends the same message again, each send within 10 minutes of the previous one. By default the second send is caught; **Sends to count as a repeat** (2–5) lets people re-send a few times first, for example when they see no repeat or reply. This only applies to messages of at least 3 words and 10 characters, because people naturally repeat short replies such as "ok", "yes" or "test". - The **same text from 3 or more different senders** within 30 minutes. This only applies to longer messages, at least 10 characters and at least 6 words, so short greetings such as "Happy New Year!" are never caught. + - Replies and messages that mention someone (`@[name]`) are never checked for repeats, so asking several people the same question is fine. 5. **Learned from your Spam taps** (automatic): a small classifier scores how much the message looks like the messages you marked as spam (see below). It needs at least 2 messages marked as spam, and it hides a message only when it is at least 80% confident. ### Matching text @@ -37,12 +38,12 @@ Before comparing, both your rule and the message are normalised: - Capital letters, accents and zero-width (invisible) characters are ignored. - Look-alike letters are treated as the letter they imitate: Cyrillic or Greek letters that look Latin, fullwidth letters, and "styled" letters such as 𝐛𝐨𝐥𝐝 or 𝘪𝘵𝘢𝘭𝘪𝘤. Swapping in look-alike letters doesn't get a message past a rule. -- Repeated-message checks also ignore punctuation, emoji and `@[name]` mentions, so "Meet at the park!" and "meet at the park" count as the same text. +- Repeated-message checks also ignore punctuation and emoji, so "Meet at the park!" and "meet at the park" count as the same text. - A reply's leading `@[name]` mention is not part of the text that is checked. ### Repeated-message memory -The app keeps a short in-memory list of recent messages for each channel: up to 1,000 per channel, for 30 minutes. Each new message is compared against it. Every checked message is added, including ones a rule already hid, so a flood keeps being caught even after you add a rule for part of it. +The app keeps a short in-memory list of recent messages for each channel: up to 1,000 per channel, for 30 minutes. Each new message is compared against it. A message with the same sender, text and send time as one already in the list is the same message seen again (for example, synced again when you connect a different companion) and never counts as a repeat. Every checked message is added, including ones a rule already hid, so a flood keeps being caught even after you add a rule for part of it. Time windows use the time the message was **sent**, not when it reached your phone. History synced in a burst after you reconnect was sent hours apart, so it is not mistaken for a flood. Old entries are forgotten by the time they *arrived*, so a sender with a wrong clock can't push everyone else out of the list. @@ -109,6 +110,7 @@ Other effects of filtering: | **Show a small placeholder** / **Hide completely** | Placeholder | How filtered messages appear in chat. | | **Your rules** | None | Your own rules (see above). | | **Repeated messages** | On | "The same message sent again, or by several senders". | +| **Sends to count as a repeat** | 2 | Which send of the same message by the same sender is hidden (2–5). Available while Repeated messages is on. | | **Repeated characters** | On | Long runs of one character, like "aaaaaaaaaaaaaaaaaaaa". | | **Learn from Spam taps** | On | Shows how many "spam and not-spam examples" the app is using. | | **Reset learning** | | Asks for confirmation, then forgets everything learned from your Spam and Not spam taps. Your rules are kept. | diff --git a/documentation/themes.md b/documentation/themes.md index cf882766..95307ec1 100644 --- a/documentation/themes.md +++ b/documentation/themes.md @@ -99,5 +99,6 @@ When a new message containing a holiday greeting arrives in, or is sent from, th - Only new messages play; messages already in the chat when you open it, and synced messages more than 2 minutes old, stay quiet. - Animations play any day of the year, not only during the holiday windows. +- Only one animation plays at a time. A greeting that arrives while one is playing, or within 5 seconds after it ends, is skipped (not queued), so a burst of greetings plays once. - Touches pass through the animation. - Turn them off with **App Settings → Appearance → Holiday message animations**. They are also skipped when the system's reduce-motion / remove-animations setting is on. diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index b79ac686..257a5fb2 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -1110,6 +1110,10 @@ class MeshCoreConnector extends ChangeNotifier { // after reconnecting arrives in a burst but was sent spread out. sentAt: message.timestamp, isReaction: message.parseReaction() != null, + // The reply mention may already be stripped into reply metadata. + isReply: + message.replyToSenderName != null || + ChannelMessage.parseReplyMention(message.text) != null, ); return applyFilterVerdict(message, verdict); } diff --git a/lib/l10n/app_bg.arb b/lib/l10n/app_bg.arb index e52c88ee..160c1d4d 100644 --- a/lib/l10n/app_bg.arb +++ b/lib/l10n/app_bg.arb @@ -3563,6 +3563,8 @@ "messageFilter_automaticSection": "Автоматично", "messageFilter_duplicates": "Повтарящи се съобщения", "messageFilter_duplicatesSubtitle": "Същото съобщение, изпратено отново или от няколко подателя", + "messageFilter_repeatSends": "Изпращания, броени за повторение", + "messageFilter_repeatSendsSubtitle": "Скриване на съобщение, когато същият подател го изпрати {count} пъти в рамките на 10 минути", "messageFilter_repeatedCharacters": "Повтарящи се символи", "messageFilter_repeatedCharactersSubtitle": "Дълги поредици от един и същ знак, като „aaaaaaaaaaaaaaaaaaaa“", "messageFilter_learning": "Учи се от натискането на „Спам“", diff --git a/lib/l10n/app_cs.arb b/lib/l10n/app_cs.arb index b78a9eee..e6afdc10 100644 --- a/lib/l10n/app_cs.arb +++ b/lib/l10n/app_cs.arb @@ -4117,6 +4117,8 @@ "messageFilter_automaticSection": "Automatické", "messageFilter_duplicates": "Opakované zprávy", "messageFilter_duplicatesSubtitle": "Stejná zpráva odeslaná znovu nebo více odesílateli", + "messageFilter_repeatSends": "Počet odeslání pro opakování", + "messageFilter_repeatSendsSubtitle": "Skrýt zprávu, když ji stejný odesílatel odešle {count}× během 10 minut", "messageFilter_repeatedCharacters": "Opakované znaky", "messageFilter_repeatedCharactersSubtitle": "Dlouhé řady jednoho znaku, například \"aaaaaaaaaaaaaaaaaaaa\"", "messageFilter_learning": "Učit se z klepnutí na Spam", diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index 1e61aa6b..c1494418 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -3698,6 +3698,8 @@ "messageFilter_automaticSection": "Automatisch", "messageFilter_duplicates": "Wiederholte Nachrichten", "messageFilter_duplicatesSubtitle": "Dieselbe Nachricht erneut gesendet oder von mehreren Absendern", + "messageFilter_repeatSends": "Sendungen bis zur Wiederholung", + "messageFilter_repeatSendsSubtitle": "Nachricht ausblenden, wenn derselbe Absender sie innerhalb von 10 Minuten {count}-mal sendet", "messageFilter_repeatedCharacters": "Wiederholte Zeichen", "messageFilter_repeatedCharactersSubtitle": "Lange Folgen desselben Zeichens, z. B. „aaaaaaaaaaaaaaaaaaaa“", "messageFilter_learning": "Aus Spam-Markierungen lernen", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index c528ce51..cd3a46c6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -3958,6 +3958,19 @@ "@messageFilter_duplicatesSubtitle": { "description": "Message filter: The same message sent again, or by several senders" }, + "messageFilter_repeatSends": "Sends to count as a repeat", + "@messageFilter_repeatSends": { + "description": "Message filter: title of the setting for which send of the same message by the same sender is hidden as a repeat" + }, + "messageFilter_repeatSendsSubtitle": "Hide a message when the same sender sends it {count} times within 10 minutes", + "@messageFilter_repeatSendsSubtitle": { + "description": "Message filter: subtitle of the repeat-sends setting", + "placeholders": { + "count": { + "type": "int" + } + } + }, "messageFilter_repeatedCharacters": "Repeated characters", "@messageFilter_repeatedCharacters": { "description": "Message filter: Repeated characters" diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 29c3d693..ec2b8dda 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -3697,6 +3697,8 @@ "messageFilter_automaticSection": "Automático", "messageFilter_duplicates": "Mensajes repetidos", "messageFilter_duplicatesSubtitle": "El mismo mensaje enviado de nuevo, o por varios remitentes", + "messageFilter_repeatSends": "Envíos para contar como repetición", + "messageFilter_repeatSendsSubtitle": "Ocultar un mensaje cuando el mismo remitente lo envía {count} veces en 10 minutos", "messageFilter_repeatedCharacters": "Caracteres repetidos", "messageFilter_repeatedCharactersSubtitle": "Secuencias largas de un mismo carácter, como \"aaaaaaaaaaaaaaaaaaaa\"", "messageFilter_learning": "Aprender de los toques en Spam", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 2b6a68ae..de82eb66 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -3697,6 +3697,8 @@ "messageFilter_automaticSection": "Automatique", "messageFilter_duplicates": "Messages répétés", "messageFilter_duplicatesSubtitle": "Le même message envoyé de nouveau, ou par plusieurs expéditeurs", + "messageFilter_repeatSends": "Envois comptés comme répétition", + "messageFilter_repeatSendsSubtitle": "Masquer un message lorsque le même expéditeur l'envoie {count} fois en 10 minutes", "messageFilter_repeatedCharacters": "Caractères répétés", "messageFilter_repeatedCharactersSubtitle": "Longues séquences d'un même caractère, comme « aaaaaaaaaaaaaaaaaaaa »", "messageFilter_learning": "Apprendre des appuis sur Spam", diff --git a/lib/l10n/app_hu.arb b/lib/l10n/app_hu.arb index a786058c..f9a00c2a 100644 --- a/lib/l10n/app_hu.arb +++ b/lib/l10n/app_hu.arb @@ -3602,6 +3602,8 @@ "messageFilter_automaticSection": "Automatikus", "messageFilter_duplicates": "Ismétlődő üzenetek", "messageFilter_duplicatesSubtitle": "Ugyanaz az üzenet újra elküldve, vagy több feladótól", + "messageFilter_repeatSends": "Ismétlésnek számító küldések", + "messageFilter_repeatSendsSubtitle": "Üzenet elrejtése, ha ugyanaz a feladó {count}× elküldi 10 percen belül", "messageFilter_repeatedCharacters": "Ismétlődő karakterek", "messageFilter_repeatedCharactersSubtitle": "Ugyanazon karakter hosszú sorozata, például „aaaaaaaaaaaaaaaaaaaa”", "messageFilter_learning": "Tanulás a Spam gombokból", diff --git a/lib/l10n/app_it.arb b/lib/l10n/app_it.arb index 9cfba865..85bb2a02 100644 --- a/lib/l10n/app_it.arb +++ b/lib/l10n/app_it.arb @@ -3697,6 +3697,8 @@ "messageFilter_automaticSection": "Automatico", "messageFilter_duplicates": "Messaggi ripetuti", "messageFilter_duplicatesSubtitle": "Lo stesso messaggio inviato di nuovo, o da più mittenti", + "messageFilter_repeatSends": "Invii da considerare ripetizione", + "messageFilter_repeatSendsSubtitle": "Nascondi un messaggio quando lo stesso mittente lo invia {count} volte entro 10 minuti", "messageFilter_repeatedCharacters": "Caratteri ripetuti", "messageFilter_repeatedCharactersSubtitle": "Lunghe sequenze dello stesso carattere, come «aaaaaaaaaaaaaaaaaaaa»", "messageFilter_learning": "Impara dai tocchi su Spam", diff --git a/lib/l10n/app_ja.arb b/lib/l10n/app_ja.arb index cf67e6a4..bf0b6b1f 100644 --- a/lib/l10n/app_ja.arb +++ b/lib/l10n/app_ja.arb @@ -3778,6 +3778,8 @@ "@messageFilter_duplicatesSubtitle": { "description": "Message filter: The same message sent again, or by several senders" }, + "messageFilter_repeatSends": "繰り返しと見なす送信回数", + "messageFilter_repeatSendsSubtitle": "同じ送信者が10分以内に同じメッセージを{count}回送信したら非表示にします", "messageFilter_repeatedCharacters": "繰り返しの文字", "@messageFilter_repeatedCharacters": { "description": "Message filter: Repeated characters" diff --git a/lib/l10n/app_ko.arb b/lib/l10n/app_ko.arb index b3e4f8aa..7a8f7e29 100644 --- a/lib/l10n/app_ko.arb +++ b/lib/l10n/app_ko.arb @@ -3778,6 +3778,8 @@ "@messageFilter_duplicatesSubtitle": { "description": "Message filter: The same message sent again, or by several senders" }, + "messageFilter_repeatSends": "반복으로 간주할 전송 횟수", + "messageFilter_repeatSendsSubtitle": "같은 발신자가 10분 안에 같은 메시지를 {count}번 보내면 숨깁니다", "messageFilter_repeatedCharacters": "반복된 문자", "@messageFilter_repeatedCharacters": { "description": "Message filter: Repeated characters" diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index a42e4484..6d6ceaf5 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -11889,6 +11889,18 @@ abstract class AppLocalizations { /// **'The same message sent again, or by several senders'** String get messageFilter_duplicatesSubtitle; + /// Message filter: title of the setting for which send of the same message by the same sender is hidden as a repeat + /// + /// In en, this message translates to: + /// **'Sends to count as a repeat'** + String get messageFilter_repeatSends; + + /// Message filter: subtitle of the repeat-sends setting + /// + /// In en, this message translates to: + /// **'Hide a message when the same sender sends it {count} times within 10 minutes'** + String messageFilter_repeatSendsSubtitle(int count); + /// Message filter: Repeated characters /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index f5b8ae90..57f0c5bb 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -7087,6 +7087,14 @@ class AppLocalizationsBg extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Същото съобщение, изпратено отново или от няколко подателя'; + @override + String get messageFilter_repeatSends => 'Изпращания, броени за повторение'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Скриване на съобщение, когато същият подател го изпрати $count пъти в рамките на 10 минути'; + } + @override String get messageFilter_repeatedCharacters => 'Повтарящи се символи'; diff --git a/lib/l10n/app_localizations_cs.dart b/lib/l10n/app_localizations_cs.dart index 01e37b3a..993370b1 100644 --- a/lib/l10n/app_localizations_cs.dart +++ b/lib/l10n/app_localizations_cs.dart @@ -7053,6 +7053,14 @@ class AppLocalizationsCs extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Stejná zpráva odeslaná znovu nebo více odesílateli'; + @override + String get messageFilter_repeatSends => 'Počet odeslání pro opakování'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Skrýt zprávu, když ji stejný odesílatel odešle $count× během 10 minut'; + } + @override String get messageFilter_repeatedCharacters => 'Opakované znaky'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index c3f77622..6bf8cde5 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -7098,6 +7098,14 @@ class AppLocalizationsDe extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Dieselbe Nachricht erneut gesendet oder von mehreren Absendern'; + @override + String get messageFilter_repeatSends => 'Sendungen bis zur Wiederholung'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Nachricht ausblenden, wenn derselbe Absender sie innerhalb von 10 Minuten $count-mal sendet'; + } + @override String get messageFilter_repeatedCharacters => 'Wiederholte Zeichen'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index 841a22ee..5a2ffe14 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -6982,6 +6982,14 @@ class AppLocalizationsEn extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'The same message sent again, or by several senders'; + @override + String get messageFilter_repeatSends => 'Sends to count as a repeat'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Hide a message when the same sender sends it $count times within 10 minutes'; + } + @override String get messageFilter_repeatedCharacters => 'Repeated characters'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 64a0ddec..c7cf495a 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -7084,6 +7084,14 @@ class AppLocalizationsEs extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'El mismo mensaje enviado de nuevo, o por varios remitentes'; + @override + String get messageFilter_repeatSends => 'Envíos para contar como repetición'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Ocultar un mensaje cuando el mismo remitente lo envía $count veces en 10 minutos'; + } + @override String get messageFilter_repeatedCharacters => 'Caracteres repetidos'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index e4016dc9..5af8327d 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -7110,6 +7110,14 @@ class AppLocalizationsFr extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Le même message envoyé de nouveau, ou par plusieurs expéditeurs'; + @override + String get messageFilter_repeatSends => 'Envois comptés comme répétition'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Masquer un message lorsque le même expéditeur l\'envoie $count fois en 10 minutes'; + } + @override String get messageFilter_repeatedCharacters => 'Caractères répétés'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 9ee118d7..e79d8376 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -7073,6 +7073,14 @@ class AppLocalizationsHu extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Ugyanaz az üzenet újra elküldve, vagy több feladótól'; + @override + String get messageFilter_repeatSends => 'Ismétlésnek számító küldések'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Üzenet elrejtése, ha ugyanaz a feladó $count× elküldi 10 percen belül'; + } + @override String get messageFilter_repeatedCharacters => 'Ismétlődő karakterek'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 5bac30cf..8a81f63f 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -7094,6 +7094,14 @@ class AppLocalizationsIt extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Lo stesso messaggio inviato di nuovo, o da più mittenti'; + @override + String get messageFilter_repeatSends => 'Invii da considerare ripetizione'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Nascondi un messaggio quando lo stesso mittente lo invia $count volte entro 10 minuti'; + } + @override String get messageFilter_repeatedCharacters => 'Caratteri ripetuti'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 8017eeb1..8d3b4601 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -6758,6 +6758,14 @@ class AppLocalizationsJa extends AppLocalizations { String get messageFilter_duplicatesSubtitle => '同じメッセージが再送されたり、複数の送信者から届いたりしたもの'; + @override + String get messageFilter_repeatSends => '繰り返しと見なす送信回数'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return '同じ送信者が10分以内に同じメッセージを$count回送信したら非表示にします'; + } + @override String get messageFilter_repeatedCharacters => '繰り返しの文字'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 4cf017ce..c18c5fe3 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -6766,6 +6766,14 @@ class AppLocalizationsKo extends AppLocalizations { String get messageFilter_duplicatesSubtitle => '같은 메시지를 다시 보냈거나 여러 발신자가 보낸 경우'; + @override + String get messageFilter_repeatSends => '반복으로 간주할 전송 횟수'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return '같은 발신자가 10분 안에 같은 메시지를 $count번 보내면 숨깁니다'; + } + @override String get messageFilter_repeatedCharacters => '반복된 문자'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 89830e91..e1d30f94 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -7048,6 +7048,15 @@ class AppLocalizationsNl extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Hetzelfde bericht opnieuw verstuurd, of door meerdere afzenders'; + @override + String get messageFilter_repeatSends => + 'Verzendingen die als herhaling tellen'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Verberg een bericht wanneer dezelfde afzender het $count keer verstuurt binnen 10 minuten'; + } + @override String get messageFilter_repeatedCharacters => 'Herhaalde tekens'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 39e18cad..62d38fd0 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -7112,6 +7112,14 @@ class AppLocalizationsPl extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Ta sama wiadomość wysłana ponownie lub przez kilku nadawców'; + @override + String get messageFilter_repeatSends => 'Liczba wysłań uznawana za powtórkę'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Ukryj wiadomość, gdy ten sam nadawca wyśle ją w ciągu 10 minut tyle razy: $count'; + } + @override String get messageFilter_repeatedCharacters => 'Powtarzające się znaki'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 8a4a1746..ef5fe24b 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -7076,6 +7076,14 @@ class AppLocalizationsPt extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'A mesma mensagem enviada de novo, ou por vários remetentes'; + @override + String get messageFilter_repeatSends => 'Envios que contam como repetição'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Ocultar uma mensagem quando o mesmo remetente a envia $count vezes em 10 minutos'; + } + @override String get messageFilter_repeatedCharacters => 'Caracteres repetidos'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index ec63c701..255ee4fa 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -7099,6 +7099,14 @@ class AppLocalizationsRu extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Одно и то же сообщение, отправленное снова или несколькими отправителями'; + @override + String get messageFilter_repeatSends => 'Отправка, считающаяся повтором'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Скрывать сообщение, если один отправитель отправляет его повторно в течение 10 минут (число отправок: $count)'; + } + @override String get messageFilter_repeatedCharacters => 'Повторяющиеся символы'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index fbf65869..2b2fe46b 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -7067,6 +7067,14 @@ class AppLocalizationsSk extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Rovnaká správa odoslaná znova alebo viacerými odosielateľmi'; + @override + String get messageFilter_repeatSends => 'Odoslanie počítané ako opakovanie'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Skryť správu, ak ju ten istý odosielateľ pošle opakovane do 10 minút (počet odoslaní: $count)'; + } + @override String get messageFilter_repeatedCharacters => 'Opakované znaky'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index b476c0d1..259b492e 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -7053,6 +7053,14 @@ class AppLocalizationsSl extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Isto sporočilo, poslano znova ali od več pošiljateljev'; + @override + String get messageFilter_repeatSends => 'Pošiljanje, šteto kot ponovitev'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Skrij sporočilo, ko ga isti pošiljatelj v 10 minutah pošlje ponovno (število pošiljanj: $count)'; + } + @override String get messageFilter_repeatedCharacters => 'Ponavljajoči se znaki'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index c60a0786..3d1eea20 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -7023,6 +7023,14 @@ class AppLocalizationsSv extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Samma meddelande skickas igen, eller av flera avsändare'; + @override + String get messageFilter_repeatSends => 'Utskick som räknas som upprepning'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Dölj ett meddelande när samma avsändare skickar det $count gånger inom 10 minuter'; + } + @override String get messageFilter_repeatedCharacters => 'Upprepade tecken'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 493ef29f..4d4a91ad 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -7107,6 +7107,14 @@ class AppLocalizationsUk extends AppLocalizations { String get messageFilter_duplicatesSubtitle => 'Те саме повідомлення, надіслане знову або кількома відправниками'; + @override + String get messageFilter_repeatSends => 'Яка відправка вважається повтором'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return 'Приховувати повідомлення, якщо той самий відправник надсилає його повторно протягом 10 хвилин (кількість відправлень: $count)'; + } + @override String get messageFilter_repeatedCharacters => 'Повторювані символи'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 29d7811a..65264a5d 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -6602,6 +6602,14 @@ class AppLocalizationsZh extends AppLocalizations { @override String get messageFilter_duplicatesSubtitle => '重复发送的相同消息,或多个发送者发送的相同消息'; + @override + String get messageFilter_repeatSends => '视为重复的发送次数'; + + @override + String messageFilter_repeatSendsSubtitle(int count) { + return '同一发送者在 10 分钟内发送同一消息 $count 次时隐藏该消息'; + } + @override String get messageFilter_repeatedCharacters => '重复字符'; diff --git a/lib/l10n/app_nl.arb b/lib/l10n/app_nl.arb index fa0f4f26..68f83542 100644 --- a/lib/l10n/app_nl.arb +++ b/lib/l10n/app_nl.arb @@ -3464,6 +3464,8 @@ "messageFilter_automaticSection": "Automatisch", "messageFilter_duplicates": "Herhaalde berichten", "messageFilter_duplicatesSubtitle": "Hetzelfde bericht opnieuw verstuurd, of door meerdere afzenders", + "messageFilter_repeatSends": "Verzendingen die als herhaling tellen", + "messageFilter_repeatSendsSubtitle": "Verberg een bericht wanneer dezelfde afzender het {count} keer verstuurt binnen 10 minuten", "messageFilter_repeatedCharacters": "Herhaalde tekens", "messageFilter_repeatedCharactersSubtitle": "Lange reeksen van hetzelfde teken, zoals „aaaaaaaaaaaaaaaaaaaa”", "messageFilter_learning": "Leren van Spam-tikken", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 3828b5c7..d43d534b 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -3677,6 +3677,8 @@ "@messageFilter_duplicatesSubtitle": { "description": "Message filter: The same message sent again, or by several senders" }, + "messageFilter_repeatSends": "Liczba wysłań uznawana za powtórkę", + "messageFilter_repeatSendsSubtitle": "Ukryj wiadomość, gdy ten sam nadawca wyśle ją w ciągu 10 minut tyle razy: {count}", "messageFilter_repeatedCharacters": "Powtarzające się znaki", "@messageFilter_repeatedCharacters": { "description": "Message filter: Repeated characters" diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index f55670df..56168c3f 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -3563,6 +3563,8 @@ "messageFilter_automaticSection": "Automático", "messageFilter_duplicates": "Mensagens repetidas", "messageFilter_duplicatesSubtitle": "A mesma mensagem enviada de novo, ou por vários remetentes", + "messageFilter_repeatSends": "Envios que contam como repetição", + "messageFilter_repeatSendsSubtitle": "Ocultar uma mensagem quando o mesmo remetente a envia {count} vezes em 10 minutos", "messageFilter_repeatedCharacters": "Caracteres repetidos", "messageFilter_repeatedCharactersSubtitle": "Sequências longas de um mesmo caractere, como \"aaaaaaaaaaaaaaaaaaaa\"", "messageFilter_learning": "Aprender com os toques em Spam", diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index d385a651..c8890b14 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -2860,6 +2860,8 @@ "messageFilter_automaticSection": "Автоматически", "messageFilter_duplicates": "Повторяющиеся сообщения", "messageFilter_duplicatesSubtitle": "Одно и то же сообщение, отправленное снова или несколькими отправителями", + "messageFilter_repeatSends": "Отправка, считающаяся повтором", + "messageFilter_repeatSendsSubtitle": "Скрывать сообщение, если один отправитель отправляет его повторно в течение 10 минут (число отправок: {count})", "messageFilter_repeatedCharacters": "Повторяющиеся символы", "messageFilter_repeatedCharactersSubtitle": "Длинные последовательности одного символа, например «aaaaaaaaaaaaaaaaaaaa»", "messageFilter_learning": "Учиться на нажатиях «Спам»", diff --git a/lib/l10n/app_sk.arb b/lib/l10n/app_sk.arb index d9b36e3f..804862d2 100644 --- a/lib/l10n/app_sk.arb +++ b/lib/l10n/app_sk.arb @@ -3564,6 +3564,8 @@ "messageFilter_automaticSection": "Automatické", "messageFilter_duplicates": "Opakované správy", "messageFilter_duplicatesSubtitle": "Rovnaká správa odoslaná znova alebo viacerými odosielateľmi", + "messageFilter_repeatSends": "Odoslanie počítané ako opakovanie", + "messageFilter_repeatSendsSubtitle": "Skryť správu, ak ju ten istý odosielateľ pošle opakovane do 10 minút (počet odoslaní: {count})", "messageFilter_repeatedCharacters": "Opakované znaky", "messageFilter_repeatedCharactersSubtitle": "Dlhé rady jedného znaku, napríklad „aaaaaaaaaaaaaaaaaaaa“", "messageFilter_learning": "Učiť sa z klepnutí na Spam", diff --git a/lib/l10n/app_sl.arb b/lib/l10n/app_sl.arb index 7e261529..3e4d09e1 100644 --- a/lib/l10n/app_sl.arb +++ b/lib/l10n/app_sl.arb @@ -3645,6 +3645,8 @@ "@messageFilter_duplicatesSubtitle": { "description": "Message filter: The same message sent again, or by several senders" }, + "messageFilter_repeatSends": "Pošiljanje, šteto kot ponovitev", + "messageFilter_repeatSendsSubtitle": "Skrij sporočilo, ko ga isti pošiljatelj v 10 minutah pošlje ponovno (število pošiljanj: {count})", "messageFilter_repeatedCharacters": "Ponavljajoči se znaki", "@messageFilter_repeatedCharacters": { "description": "Message filter: Repeated characters" diff --git a/lib/l10n/app_sv.arb b/lib/l10n/app_sv.arb index 7c8eb94d..c0aa523e 100644 --- a/lib/l10n/app_sv.arb +++ b/lib/l10n/app_sv.arb @@ -3558,6 +3558,8 @@ "messageFilter_automaticSection": "Automatiskt", "messageFilter_duplicates": "Upprepade meddelanden", "messageFilter_duplicatesSubtitle": "Samma meddelande skickas igen, eller av flera avsändare", + "messageFilter_repeatSends": "Utskick som räknas som upprepning", + "messageFilter_repeatSendsSubtitle": "Dölj ett meddelande när samma avsändare skickar det {count} gånger inom 10 minuter", "messageFilter_repeatedCharacters": "Upprepade tecken", "messageFilter_repeatedCharactersSubtitle": "Långa följder av samma tecken, som ”aaaaaaaaaaaaaaaaaaaa”", "messageFilter_learning": "Lär av tryck på Skräppost", diff --git a/lib/l10n/app_uk.arb b/lib/l10n/app_uk.arb index 0f62f71b..dbc16927 100644 --- a/lib/l10n/app_uk.arb +++ b/lib/l10n/app_uk.arb @@ -3543,6 +3543,8 @@ "messageFilter_automaticSection": "Автоматично", "messageFilter_duplicates": "Повідомлення, що повторюються", "messageFilter_duplicatesSubtitle": "Те саме повідомлення, надіслане знову або кількома відправниками", + "messageFilter_repeatSends": "Яка відправка вважається повтором", + "messageFilter_repeatSendsSubtitle": "Приховувати повідомлення, якщо той самий відправник надсилає його повторно протягом 10 хвилин (кількість відправлень: {count})", "messageFilter_repeatedCharacters": "Повторювані символи", "messageFilter_repeatedCharactersSubtitle": "Довгі послідовності одного символа, наприклад «aaaaaaaaaaaaaaaaaaaa»", "messageFilter_learning": "Навчання на натисканнях «Спам»", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 3b4aa865..407ccdc9 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -3568,6 +3568,8 @@ "messageFilter_automaticSection": "自动", "messageFilter_duplicates": "重复消息", "messageFilter_duplicatesSubtitle": "重复发送的相同消息,或多个发送者发送的相同消息", + "messageFilter_repeatSends": "视为重复的发送次数", + "messageFilter_repeatSendsSubtitle": "同一发送者在 10 分钟内发送同一消息 {count} 次时隐藏该消息", "messageFilter_repeatedCharacters": "重复字符", "messageFilter_repeatedCharactersSubtitle": "同一字符的长串重复,例如“aaaaaaaaaaaaaaaaaaaa”", "messageFilter_learning": "从“垃圾消息”点击中学习", diff --git a/lib/models/message_filter.dart b/lib/models/message_filter.dart index 850e06b6..b95024a0 100644 --- a/lib/models/message_filter.dart +++ b/lib/models/message_filter.dart @@ -143,6 +143,10 @@ class MessageFilterSettings { final bool enabled; final FilterDisplayMode displayMode; final bool duplicates; + + /// Which send in a row of the same message by the same sender is flagged + /// as a repeat (2 = the first re-send). + final int repeatSends; final bool repeatedCharacters; final bool learning; final Set excludedChannelIds; @@ -151,6 +155,7 @@ class MessageFilterSettings { this.enabled = true, this.displayMode = FilterDisplayMode.placeholder, this.duplicates = true, + this.repeatSends = defaultRepeatSends, this.repeatedCharacters = true, this.learning = true, this.excludedChannelIds = const {}, @@ -158,10 +163,15 @@ class MessageFilterSettings { static const MessageFilterSettings defaults = MessageFilterSettings(); + static const int defaultRepeatSends = 2; + static const int minRepeatSends = 2; + static const int maxRepeatSends = 5; + MessageFilterSettings copyWith({ bool? enabled, FilterDisplayMode? displayMode, bool? duplicates, + int? repeatSends, bool? repeatedCharacters, bool? learning, Set? excludedChannelIds, @@ -170,6 +180,7 @@ class MessageFilterSettings { enabled: enabled ?? this.enabled, displayMode: displayMode ?? this.displayMode, duplicates: duplicates ?? this.duplicates, + repeatSends: repeatSends ?? this.repeatSends, repeatedCharacters: repeatedCharacters ?? this.repeatedCharacters, learning: learning ?? this.learning, excludedChannelIds: excludedChannelIds ?? this.excludedChannelIds, @@ -180,6 +191,7 @@ class MessageFilterSettings { 'enabled': enabled, 'displayMode': displayMode.name, 'duplicates': duplicates, + 'repeatSends': repeatSends, 'repeatedCharacters': repeatedCharacters, 'learning': learning, 'excludedChannelIds': excludedChannelIds.toList()..sort(), @@ -195,6 +207,11 @@ class MessageFilterSettings { FilterDisplayMode.placeholder, ), duplicates: json['duplicates'] as bool? ?? true, + repeatSends: + ((json['repeatSends'] as num?)?.toInt() ?? defaultRepeatSends).clamp( + minRepeatSends, + maxRepeatSends, + ), repeatedCharacters: json['repeatedCharacters'] as bool? ?? true, learning: json['learning'] as bool? ?? true, excludedChannelIds: excluded is List diff --git a/lib/screens/message_filter_settings_screen.dart b/lib/screens/message_filter_settings_screen.dart index c98e4064..f6f02db4 100644 --- a/lib/screens/message_filter_settings_screen.dart +++ b/lib/screens/message_filter_settings_screen.dart @@ -366,6 +366,36 @@ class _AutomaticOptions extends StatelessWidget { service.settings.copyWith(duplicates: value), ), ), + ListTile( + key: const ValueKey('messageFilter_repeatSends'), + contentPadding: padding, + enabled: settings.duplicates, + leading: const Icon(Icons.repeat, size: 24), + title: Text(l10n.messageFilter_repeatSends), + subtitle: Text( + l10n.messageFilter_repeatSendsSubtitle(settings.repeatSends), + ), + trailing: DropdownButton( + key: const ValueKey('messageFilter_repeatSendsDropdown'), + value: settings.repeatSends, + onChanged: settings.duplicates + ? (value) { + if (value == null) return; + service.updateSettings( + service.settings.copyWith(repeatSends: value), + ); + } + : null, + items: [ + for ( + var n = MessageFilterSettings.minRepeatSends; + n <= MessageFilterSettings.maxRepeatSends; + n++ + ) + DropdownMenuItem(value: n, child: Text('$n')), + ], + ), + ), const Divider(height: 1, indent: 16), SwitchListTile( key: const ValueKey('messageFilter_repeatedCharactersSwitch'), diff --git a/lib/services/message_filter/duplicate_tracker.dart b/lib/services/message_filter/duplicate_tracker.dart index 7b8a66ce..563f725b 100644 --- a/lib/services/message_filter/duplicate_tracker.dart +++ b/lib/services/message_filter/duplicate_tracker.dart @@ -12,7 +12,17 @@ class _SeenMessage { /// When this device saw it (local clock). Only used to forget entries. final DateTime receivedAt; - const _SeenMessage(this.sender, this.key, this.sentAt, this.receivedAt); + + /// How many sends of this text by this sender, each within the + /// same-sender window of the previous one, end with this one (1 = first). + final int sends; + const _SeenMessage( + this.sender, + this.key, + this.sentAt, + this.receivedAt, { + this.sends = 1, + }); } /// In-memory, per-channel tracker of recently seen channel texts used to catch @@ -28,6 +38,16 @@ class _SeenMessage { /// so a sender whose clock is far off cannot push everyone else's entries /// out early or keep its own around forever. /// +/// A copy with the same sender, text and send second as an entry already +/// recorded is the same message seen again (another companion syncing it, +/// a mesh repeat that slipped past storage dedup), never a repeat, and is +/// not recorded twice. +/// +/// The same-sender rule flags the [sameSenderSends]th send of a text in a +/// row, each send within [sameSenderWindow] of the previous one (2 = the +/// first re-send). Higher values tolerate people re-sending when they see +/// no repeat or reply. +/// /// The same-sender rule only applies to texts of at least /// [sameSenderMinWords] words and [sameSenderMinLength] characters: people /// naturally repeat short replies ("ok", "yes", "test" when checking reach), @@ -42,6 +62,7 @@ class DuplicateTracker { this.sameSenderWindow = const Duration(minutes: 10), this.sameSenderMinLength = 10, this.sameSenderMinWords = 3, + this.sameSenderSends = 2, this.crossSenderWindow = const Duration(minutes: 30), this.crossSenderMinSenders = 3, this.crossSenderMinLength = 10, @@ -54,6 +75,10 @@ class DuplicateTracker { /// Minimum length / word count for the same-sender rule (see class docs). final int sameSenderMinLength; final int sameSenderMinWords; + + /// Which send in a row of the same text is flagged; can be overridden per + /// call so a settings change applies immediately. + final int sameSenderSends; final Duration crossSenderWindow; final int crossSenderMinSenders; final int crossSenderMinLength; @@ -95,7 +120,11 @@ class DuplicateTracker { required String text, required DateTime at, DateTime? receivedAt, + int? sameSenderSends, }) { + final flagAt = (sameSenderSends ?? this.sameSenderSends) < 2 + ? 2 + : (sameSenderSends ?? this.sameSenderSends); final arrived = receivedAt ?? at; final key = MessageFilterText.normalizeForDuplicates(text); if (key.isEmpty) return null; @@ -103,21 +132,38 @@ class DuplicateTracker { final entries = _seen.putIfAbsent(channelId, ListQueue<_SeenMessage>.new); _prune(entries, arrived); + final atSecond = _second(at); + for (final entry in entries) { + if (entry.key == key && + entry.sender == senderKey && + _second(entry.sentAt) == atSecond) { + // The same message seen again, not a new send. + return null; + } + } + + // The longest run of sends this one continues: earlier sends of this + // text by this sender within the window, each already carrying its run. + var sends = 1; + for (final entry in entries) { + if (entry.key != key || entry.sender != senderKey) continue; + if (entry.sentAt.difference(at).abs() <= sameSenderWindow && + entry.sends + 1 > sends) { + sends = entry.sends + 1; + } + } + FilterReason? result; if (!isAllowed(channelId, text)) { final senders = {senderKey}; - var sameSender = false; for (final entry in entries) { - if (entry.key != key) continue; + if (entry.key != key || entry.sender == senderKey) continue; // Absolute gap between send times: delivery order does not matter. - final gap = entry.sentAt.difference(at).abs(); - if (entry.sender == senderKey) { - if (gap <= sameSenderWindow) sameSender = true; - } else if (gap <= crossSenderWindow) { + if (entry.sentAt.difference(at).abs() <= crossSenderWindow) { senders.add(entry.sender); } } - if (sameSender && + if (sends >= flagAt && key.length >= sameSenderMinLength && _wordCount(key) >= sameSenderMinWords) { result = FilterReason.duplicate; @@ -128,11 +174,13 @@ class DuplicateTracker { } } - entries.addLast(_SeenMessage(senderKey, key, at, arrived)); + entries.addLast(_SeenMessage(senderKey, key, at, arrived, sends: sends)); if (entries.length > maxEntriesPerChannel) entries.removeFirst(); return result; } + static int _second(DateTime time) => time.millisecondsSinceEpoch ~/ 1000; + /// [key] is already whitespace-collapsed by `normalizeForDuplicates`. static int _wordCount(String key) => key.isEmpty ? 0 : key.split(' ').length; diff --git a/lib/services/message_filter/message_filter_service.dart b/lib/services/message_filter/message_filter_service.dart index 5f679c7d..355cccaa 100644 --- a/lib/services/message_filter/message_filter_service.dart +++ b/lib/services/message_filter/message_filter_service.dart @@ -139,6 +139,10 @@ class MessageFilterService extends ChangeNotifier { /// [sentAt] is the message's own timestamp. Duplicate windows are measured /// between send times, so history synced in a burst after reconnecting is /// not mistaken for a flood; without it the local clock is used. + /// + /// Messages addressed to someone ([isReply], or an `@[name]` mention in + /// [text]) are exempt from duplicate detection and not recorded for it: + /// asking several people the same thing is conversation, not a repeat. FilterVerdict? evaluate({ required String channelId, required String sender, @@ -146,6 +150,7 @@ class MessageFilterService extends ChangeNotifier { DateTime? sentAt, bool isOutgoing = false, bool isReaction = false, + bool isReply = false, }) { if (!isChannelFiltered(channelId)) return null; if (isOutgoing || isReaction) return null; @@ -153,13 +158,17 @@ class MessageFilterService extends ChangeNotifier { if (MessageFilterText.isStructuredPayload(text)) return null; // Always record (even when a rule matches) so floods keep being caught. - final duplicateReason = _tracker.check( - channelId: channelId, - sender: sender, - text: text, - at: sentAt ?? _clock(), - receivedAt: _clock(), - ); + final mentionsSomeone = isReply || MessageFilterText.hasMention(text); + final duplicateReason = mentionsSomeone + ? null + : _tracker.check( + channelId: channelId, + sender: sender, + text: text, + at: sentAt ?? _clock(), + receivedAt: _clock(), + sameSenderSends: _settings.repeatSends, + ); final byRule = _matchRules(sender, text); if (byRule != null) return byRule; diff --git a/lib/services/message_filter/message_filter_text.dart b/lib/services/message_filter/message_filter_text.dart index 557eb903..26d9d93d 100644 --- a/lib/services/message_filter/message_filter_text.dart +++ b/lib/services/message_filter/message_filter_text.dart @@ -141,6 +141,9 @@ class MessageFilterText { return _fold(text).replaceAll(_whitespace, ' ').trim(); } + /// True when [text] contains an `@[name]` mention. + static bool hasMention(String text) => _mention.hasMatch(text); + /// Looser form used to detect repeated messages: also drops `@[name]` /// mentions, punctuation and emoji so trivial variations still match. static String normalizeForDuplicates(String text) { diff --git a/lib/widgets/holiday_animations.dart b/lib/widgets/holiday_animations.dart index 5a8c2254..c03a1bf7 100644 --- a/lib/widgets/holiday_animations.dart +++ b/lib/widgets/holiday_animations.dart @@ -16,12 +16,32 @@ Duration holidayAnimationDuration(HolidayAnimation animation) => HolidayAnimation.newYear => const Duration(milliseconds: 5600), }; +/// Quiet time after a holiday animation ends before another may start. +const Duration holidayAnimationMinInterval = Duration(seconds: 5); + +/// Clock for the rate limit; tests replace it. +@visibleForTesting +DateTime Function() holidayAnimationClock = DateTime.now; + +OverlayEntry? _activeHolidayEntry; +DateTime? _holidayQuietUntil; + +/// Forgets the playing animation and the quiet period (tests only). +@visibleForTesting +void resetHolidayAnimationGate() { + _activeHolidayEntry = null; + _holidayQuietUntil = null; +} + /// Plays [animation] over the whole screen, starting from [origin] (global /// coordinates of the message it came from). Touches pass through, and the /// overlay removes itself when done. /// -/// Skipped when the user turned holiday animations off or the platform asks -/// for reduced motion. +/// Skipped when the user turned holiday animations off, the platform asks +/// for reduced motion, another holiday animation is still playing, or the +/// last one ended less than [holidayAnimationMinInterval] ago (so a burst of +/// greetings plays once instead of piling up). Skipped animations are +/// dropped, not queued. void playHolidayAnimation( BuildContext context, HolidayAnimation animation, { @@ -30,6 +50,11 @@ void playHolidayAnimation( final settings = context.read().settings; if (!settings.holidayAnimationsEnabled) return; if (MediaQuery.maybeDisableAnimationsOf(context) ?? false) return; + // Unmounted when it finished or its overlay went away. + if (_activeHolidayEntry?.mounted ?? false) return; + final now = holidayAnimationClock(); + final quietUntil = _holidayQuietUntil; + if (quietUntil != null && now.isBefore(quietUntil)) return; final overlay = Overlay.maybeOf(context, rootOverlay: true); if (overlay == null) return; late final OverlayEntry entry; @@ -37,9 +62,23 @@ void playHolidayAnimation( builder: (_) => HolidayAnimationView( animation: animation, origin: origin, - onDone: () => entry.remove(), + onDone: () { + if (identical(_activeHolidayEntry, entry)) { + _activeHolidayEntry = null; + _holidayQuietUntil = holidayAnimationClock().add( + holidayAnimationMinInterval, + ); + } + entry.remove(); + }, ), ); + _activeHolidayEntry = entry; + // Until it reports its end: the end it should reach, plus the quiet time, + // in case the overlay goes away without finishing it. + _holidayQuietUntil = now + .add(holidayAnimationDuration(animation)) + .add(holidayAnimationMinInterval); overlay.insert(entry); } diff --git a/test/helpers/holiday_triggers_test.dart b/test/helpers/holiday_triggers_test.dart index bae8752d..3a43b016 100644 --- a/test/helpers/holiday_triggers_test.dart +++ b/test/helpers/holiday_triggers_test.dart @@ -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); diff --git a/test/services/message_filter/duplicate_tracker_test.dart b/test/services/message_filter/duplicate_tracker_test.dart index 2a2e28c3..f6be0ef8 100644 --- a/test/services/message_filter/duplicate_tracker_test.dart +++ b/test/services/message_filter/duplicate_tracker_test.dart @@ -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']) { diff --git a/test/services/message_filter/message_filter_service_test.dart b/test/services/message_filter/message_filter_service_test.dart index 865adff3..a6166dbd 100644 --- a/test/services/message_filter/message_filter_service_test.dart +++ b/test/services/message_filter/message_filter_service_test.dart @@ -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(