diff --git a/documentation/notifications.md b/documentation/notifications.md index eae2fad6..535570c3 100644 --- a/documentation/notifications.md +++ b/documentation/notifications.md @@ -42,7 +42,7 @@ Message notifications can be answered without opening the app, from the notifica - **Reply** sends through the connected radio exactly like the chat screen: same length limits, SMAZ and Cyr2Lat handling, and retries. Your reply is then added to the notification. - **Replies over the message limit** are split at word boundaries into up to 3 messages. Longer replies are not sent; a "Reply not sent" notification asks you to open the app. - **Mark as read** clears the unread count on the phone only. MeshCore has no read receipts, so nothing is sent over the mesh. -- **Mute channel** (phone and watch) mutes that channel, the same as the bell icon in the channel chat. +- **Mute channel** (phone and watch) sets that channel to **Muted**, the same as choosing Muted from the bell icon in the channel chat. - If the radio is disconnected, the conversation is no longer on the radio, the radio reports a send error, or the app isn't running, a "Reply not sent" notification explains why. The reply is not queued. If a split reply fails partway, earlier parts may already have been sent. - Replies are sent as typed; composer translation is not applied. @@ -107,15 +107,24 @@ Access via **App Settings → Notifications**: | Channel Message Notifications | On | Channel alerts (greyed out if master is off) | | Advertisement Notifications | On | New node alerts (greyed out if master is off) | -### Per-Channel Muting +### Per-Channel Notification Modes -Mute or unmute a channel from any of these places. Muted channels do not generate OS notifications. +Each channel supports three notification modes: -- The bell icon in the channel chat app bar -- Long-press a channel in the channels list → "Mute channel" / "Unmute channel" -- **Mute channel** on a channel notification (Android) +| Mode | Icon | Behavior | +|---|---|---| +| **All messages** | 🔔 | Receive notifications for every message | +| **Mentions only** | 🔔! | Only notify when a message mentions your name (see below) | +| **Muted** | 🔕 | No notifications | -There is no per-contact muting. +Set the mode from: + +- The notifications icon in the channel chat app bar (tap to open the mode picker) +- Long-press a channel in the channels list → **Notification settings** → select mode + +The Android **Mute channel** notification action sets the channel to **Muted**; it cannot choose another mode. + +A message mentions you if it contains `@[yourname]` or `@yourname`, case-insensitively. The plain `@yourname` form must stand alone as a word, so `@bobby` does not mention `bob` and `x@bob.com` is not a mention; names with spaces must be written in full. Detection (`MeshCoreConnector.textMentionsName`) runs on the original text, before any automatic translation. ## Rate Limiting diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 6d6569e4..49bdcbd8 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -38,7 +38,8 @@ import '../services/image_codec_service.dart'; import '../services/received_image_store.dart'; import '../services/message_retry_service.dart'; import '../services/path_history_service.dart'; -import '../services/app_settings_service.dart'; +import '../services/app_settings_service.dart' + show AppSettingsService, ChannelNotificationMode; import '../services/background_service.dart'; import '../services/timeout_prediction_service.dart'; import '../services/translation_service.dart'; @@ -1265,8 +1266,9 @@ class MeshCoreConnector extends ChangeNotifier { /// (notification shade, watch, or Android Auto). Future handleNotificationReply(NotificationReply reply) async { if (reply.action == NotificationReplyAction.mute) { - await _appSettingsService?.muteChannel( + await _appSettingsService?.setChannelNotificationMode( _channelDisplayName(reply.channelIndex!), + ChannelNotificationMode.muted, ); await _notificationService.clearChannelNotification( reply.channelIndex!, @@ -7431,7 +7433,12 @@ class MeshCoreConnector extends ChangeNotifier { } final label = channelName ?? _channelDisplayName(channelIndex); - if (_appSettingsService!.isChannelMuted(label)) return; + final notificationMode = _appSettingsService!.getChannelNotificationMode( + label, + ); + + // Check if channel is muted + if (notificationMode == ChannelNotificationMode.muted) return; // Reuse translation result only if completed and non-empty; else use original text final resolvedText = @@ -7440,6 +7447,14 @@ class MeshCoreConnector extends ChangeNotifier { translationResult.translatedText.trim().isNotEmpty) ? translationResult.translatedText.trim() : message.text.trim(); + + // Mentions are matched on the untranslated text. + if (notificationMode == ChannelNotificationMode.mentionsOnly) { + if (!textMentionsName(message.originalText ?? message.text, _selfName)) { + return; + } + } + unawaited(() async { await _notificationService.showChannelMessageNotification( channelName: label, @@ -7452,6 +7467,22 @@ class MeshCoreConnector extends ChangeNotifier { }()); } + /// Whether [text] mentions [name], case-insensitively, as either + /// `@[name]` (the reply/mention prefix the app sends) or a plain `@name`. + /// The plain form needs a word boundary on both sides, so `@bobby` does + /// not mention `bob` and `x@bob.com` is not a mention. Names containing + /// spaces must be written out in full. + @visibleForTesting + static bool textMentionsName(String text, String? name) { + if (name == null || name.isEmpty) return false; + final escaped = RegExp.escape(name); + return RegExp( + '@\\[$escaped\\]|(? 'Редактирай канал'; + @override + String get channels_notificationSettings => 'Настройки за известия'; + + @override + String get channels_notifyAll => 'Всички съобщения'; + + @override + String get channels_notifyMentionsOnly => 'Само споменавания'; + + @override + String get channels_notifyNone => 'Заглушено'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Заглуши канала'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index cf8e7f72..0468aef4 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -1462,6 +1462,23 @@ class AppLocalizationsDe extends AppLocalizations { @override String get channels_editChannel => 'Kanal bearbeiten'; + @override + String get channels_notificationSettings => 'Benachrichtigungseinstellungen'; + + @override + String get channels_notifyAll => 'Alle Nachrichten'; + + @override + String get channels_notifyMentionsOnly => 'Nur Erwähnungen'; + + @override + String get channels_notifyNone => 'Stummgeschaltet'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Kanal stummschalten'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index cf0ba706..e3fea170 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1442,6 +1442,23 @@ class AppLocalizationsEn extends AppLocalizations { @override String get channels_editChannel => 'Edit channel'; + @override + String get channels_notificationSettings => 'Notification settings'; + + @override + String get channels_notifyAll => 'All messages'; + + @override + String get channels_notifyMentionsOnly => 'Mentions only'; + + @override + String get channels_notifyNone => 'Muted'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Mute channel'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index 1bdc26b9..f7042239 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -1461,6 +1461,23 @@ class AppLocalizationsEs extends AppLocalizations { @override String get channels_editChannel => 'Editar canal'; + @override + String get channels_notificationSettings => 'Configuración de notificaciones'; + + @override + String get channels_notifyAll => 'Todos los mensajes'; + + @override + String get channels_notifyMentionsOnly => 'Solo menciones'; + + @override + String get channels_notifyNone => 'Silenciado'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Silenciar canal'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 8e9fac45..20d1006b 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -1466,6 +1466,23 @@ class AppLocalizationsFr extends AppLocalizations { @override String get channels_editChannel => 'Modifier le canal'; + @override + String get channels_notificationSettings => 'Paramètres des notifications'; + + @override + String get channels_notifyAll => 'Tous les messages'; + + @override + String get channels_notifyMentionsOnly => 'Mentions uniquement'; + + @override + String get channels_notifyNone => 'Désactivé'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Désactiver les notifications du canal'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 1553aaa0..3734f7d4 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -1457,6 +1457,23 @@ class AppLocalizationsHu extends AppLocalizations { @override String get channels_editChannel => 'Csatorna szerkesztése'; + @override + String get channels_notificationSettings => 'Értesítési beállítások'; + + @override + String get channels_notifyAll => 'Összes üzenet'; + + @override + String get channels_notifyMentionsOnly => 'Csak említések'; + + @override + String get channels_notifyNone => 'Némít'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Csatorna némítása'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index d98b87a3..eedf31ab 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -1465,6 +1465,23 @@ class AppLocalizationsIt extends AppLocalizations { @override String get channels_editChannel => 'Modifica canale'; + @override + String get channels_notificationSettings => 'Impostazioni notifiche'; + + @override + String get channels_notifyAll => 'Tutti i messaggi'; + + @override + String get channels_notifyMentionsOnly => 'Solo menzioni'; + + @override + String get channels_notifyNone => 'Silenziato'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Silenzia canale'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index 33f33727..814b326e 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -1389,6 +1389,23 @@ class AppLocalizationsJa extends AppLocalizations { @override String get channels_editChannel => 'チャンネルを編集'; + @override + String get channels_notificationSettings => '通知設定'; + + @override + String get channels_notifyAll => 'すべてのメッセージ'; + + @override + String get channels_notifyMentionsOnly => 'メンションのみ'; + + @override + String get channels_notifyNone => 'ミュート'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'チャンネルをミュート'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index 6cce3e0e..9bfaf12a 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -1394,6 +1394,23 @@ class AppLocalizationsKo extends AppLocalizations { @override String get channels_editChannel => '채널 편집'; + @override + String get channels_notificationSettings => '알림 설정'; + + @override + String get channels_notifyAll => '모든 메시지'; + + @override + String get channels_notifyMentionsOnly => '언급만'; + + @override + String get channels_notifyNone => '음소거'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => '음소거 채널'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 29bbfcd7..4576bff6 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -1453,6 +1453,23 @@ class AppLocalizationsNl extends AppLocalizations { @override String get channels_editChannel => 'Kanaal bewerken'; + @override + String get channels_notificationSettings => 'Meldingsinstellingen'; + + @override + String get channels_notifyAll => 'Alle berichten'; + + @override + String get channels_notifyMentionsOnly => 'Alleen vermeldingen'; + + @override + String get channels_notifyNone => 'Gedempt'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Kanaal dempen'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index c8c731ae..b934f462 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -1479,6 +1479,23 @@ class AppLocalizationsPl extends AppLocalizations { @override String get channels_editChannel => 'Edytuj kanał'; + @override + String get channels_notificationSettings => 'Ustawienia powiadomień'; + + @override + String get channels_notifyAll => 'Wszystkie wiadomości'; + + @override + String get channels_notifyMentionsOnly => 'Tylko wzmianki'; + + @override + String get channels_notifyNone => 'Wyciszone'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Wycisz kanał'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index 98426c0c..b50bb8e5 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -1464,6 +1464,23 @@ class AppLocalizationsPt extends AppLocalizations { @override String get channels_editChannel => 'Editar canal'; + @override + String get channels_notificationSettings => 'Configurações de notificação'; + + @override + String get channels_notifyAll => 'Todas as mensagens'; + + @override + String get channels_notifyMentionsOnly => 'Apenas menções'; + + @override + String get channels_notifyNone => 'Silenciado'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Silenciar canal'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 7f26de70..51969eb2 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -1468,6 +1468,23 @@ class AppLocalizationsRu extends AppLocalizations { @override String get channels_editChannel => 'Изменить канал'; + @override + String get channels_notificationSettings => 'Настройки уведомлений'; + + @override + String get channels_notifyAll => 'Все сообщения'; + + @override + String get channels_notifyMentionsOnly => 'Только упоминания'; + + @override + String get channels_notifyNone => 'Без звука'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Отключить уведомления канала'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 35f33b96..e8ed7d1d 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -1456,6 +1456,23 @@ class AppLocalizationsSk extends AppLocalizations { @override String get channels_editChannel => 'Upraviť kanál'; + @override + String get channels_notificationSettings => 'Nastavenia notifikácií'; + + @override + String get channels_notifyAll => 'Všetky správy'; + + @override + String get channels_notifyMentionsOnly => 'Iba zmienky'; + + @override + String get channels_notifyNone => 'Stíšené'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Stlmiť kanál'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index b1064852..1df96cc4 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -1454,6 +1454,23 @@ class AppLocalizationsSl extends AppLocalizations { @override String get channels_editChannel => 'Uredi kanal'; + @override + String get channels_notificationSettings => 'Nastavitve obvestil'; + + @override + String get channels_notifyAll => 'Vsa sporočila'; + + @override + String get channels_notifyMentionsOnly => 'Samo omembe'; + + @override + String get channels_notifyNone => 'Utišano'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Utišaj kanal'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index 1180ed78..ea1bdd03 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -1443,6 +1443,23 @@ class AppLocalizationsSv extends AppLocalizations { @override String get channels_editChannel => 'Redigera kanal'; + @override + String get channels_notificationSettings => 'Aviseringsinställningar'; + + @override + String get channels_notifyAll => 'Alla meddelanden'; + + @override + String get channels_notifyMentionsOnly => 'Endast omnämnanden'; + + @override + String get channels_notifyNone => 'Tyst'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Tysta kanal'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 2aea01f9..79cb0673 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -1459,6 +1459,23 @@ class AppLocalizationsUk extends AppLocalizations { @override String get channels_editChannel => 'Редагувати канал'; + @override + String get channels_notificationSettings => 'Налаштування сповіщень'; + + @override + String get channels_notifyAll => 'Усі повідомлення'; + + @override + String get channels_notifyMentionsOnly => 'Лише згадки'; + + @override + String get channels_notifyNone => 'Вимкнено'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => 'Вимкнути сповіщення каналу'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index c65a1f4f..3a5a509e 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -1371,6 +1371,23 @@ class AppLocalizationsZh extends AppLocalizations { @override String get channels_editChannel => '编辑频道'; + @override + String get channels_notificationSettings => '通知设置'; + + @override + String get channels_notifyAll => '所有消息'; + + @override + String get channels_notifyMentionsOnly => '仅提及'; + + @override + String get channels_notifyNone => '静音'; + + @override + String channels_notificationModeTooltip(String mode) { + return 'Notifications: $mode'; + } + @override String get channels_muteChannel => '静音频道'; diff --git a/lib/l10n/app_nl.arb b/lib/l10n/app_nl.arb index 4f7d8d61..3cbd275f 100644 --- a/lib/l10n/app_nl.arb +++ b/lib/l10n/app_nl.arb @@ -375,6 +375,10 @@ "channels_addSectionCreate": "Nieuw aanmaken", "channels_dragToReorder": "Sleep om te herschikken", "channels_editChannel": "Kanaal bewerken", + "channels_notificationSettings": "Meldingsinstellingen", + "channels_notifyAll": "Alle berichten", + "channels_notifyMentionsOnly": "Alleen vermeldingen", + "channels_notifyNone": "Gedempt", "channels_muteChannel": "Kanaal dempen", "channels_unmuteChannel": "Kanaal dempen opheffen", "channels_deleteChannel": "Kanaal verwijderen", diff --git a/lib/l10n/app_pl.arb b/lib/l10n/app_pl.arb index 77ca42b7..eb429796 100644 --- a/lib/l10n/app_pl.arb +++ b/lib/l10n/app_pl.arb @@ -369,6 +369,10 @@ "channels_public": "Publiczny", "channels_private": "Prywatny", "channels_editChannel": "Edytuj kanał", + "channels_notificationSettings": "Ustawienia powiadomień", + "channels_notifyAll": "Wszystkie wiadomości", + "channels_notifyMentionsOnly": "Tylko wzmianki", + "channels_notifyNone": "Wyciszone", "channels_muteChannel": "Wycisz kanał", "channels_unmuteChannel": "Wyłącz wyciszenie kanału", "channels_deleteChannel": "Usuń kanał", diff --git a/lib/l10n/app_pt.arb b/lib/l10n/app_pt.arb index d211e265..997bd295 100644 --- a/lib/l10n/app_pt.arb +++ b/lib/l10n/app_pt.arb @@ -359,6 +359,10 @@ "channels_public": "Público", "channels_private": "Privado", "channels_editChannel": "Editar canal", + "channels_notificationSettings": "Configurações de notificação", + "channels_notifyAll": "Todas as mensagens", + "channels_notifyMentionsOnly": "Apenas menções", + "channels_notifyNone": "Silenciado", "channels_muteChannel": "Silenciar canal", "channels_unmuteChannel": "Ativar canal", "channels_deleteChannel": "Excluir canal", diff --git a/lib/l10n/app_ru.arb b/lib/l10n/app_ru.arb index f2d3baeb..d8b9ff79 100644 --- a/lib/l10n/app_ru.arb +++ b/lib/l10n/app_ru.arb @@ -251,6 +251,10 @@ "channels_public": "Публичный", "channels_private": "Приватный", "channels_editChannel": "Изменить канал", + "channels_notificationSettings": "Настройки уведомлений", + "channels_notifyAll": "Все сообщения", + "channels_notifyMentionsOnly": "Только упоминания", + "channels_notifyNone": "Без звука", "channels_muteChannel": "Отключить уведомления канала", "channels_unmuteChannel": "Включить уведомления канала", "channels_deleteChannel": "Удалить канал", diff --git a/lib/l10n/app_sk.arb b/lib/l10n/app_sk.arb index d2525a42..58454b8b 100644 --- a/lib/l10n/app_sk.arb +++ b/lib/l10n/app_sk.arb @@ -359,6 +359,10 @@ "channels_public": "Veľké verejné", "channels_private": "Osobné", "channels_editChannel": "Upraviť kanál", + "channels_notificationSettings": "Nastavenia notifikácií", + "channels_notifyAll": "Všetky správy", + "channels_notifyMentionsOnly": "Iba zmienky", + "channels_notifyNone": "Stíšené", "channels_muteChannel": "Stlmiť kanál", "channels_unmuteChannel": "Zrušiť stlmenie kanála", "channels_deleteChannel": "Odstrániť kanál", diff --git a/lib/l10n/app_sl.arb b/lib/l10n/app_sl.arb index 5bc612a0..2e9fcdc0 100644 --- a/lib/l10n/app_sl.arb +++ b/lib/l10n/app_sl.arb @@ -359,6 +359,10 @@ "channels_public": "Javni", "channels_private": "Zasebni", "channels_editChannel": "Uredi kanal", + "channels_notificationSettings": "Nastavitve obvestil", + "channels_notifyAll": "Vsa sporočila", + "channels_notifyMentionsOnly": "Samo omembe", + "channels_notifyNone": "Utišano", "channels_muteChannel": "Utišaj kanal", "channels_unmuteChannel": "Vklopi obvestila kanala", "channels_deleteChannel": "Pošlji kanal", diff --git a/lib/l10n/app_sv.arb b/lib/l10n/app_sv.arb index 1857b8a5..a138085a 100644 --- a/lib/l10n/app_sv.arb +++ b/lib/l10n/app_sv.arb @@ -359,6 +359,10 @@ "channels_public": "Publik", "channels_private": "Privat", "channels_editChannel": "Redigera kanal", + "channels_notificationSettings": "Aviseringsinställningar", + "channels_notifyAll": "Alla meddelanden", + "channels_notifyMentionsOnly": "Endast omnämnanden", + "channels_notifyNone": "Tyst", "channels_muteChannel": "Tysta kanal", "channels_unmuteChannel": "Slå på ljud för kanal", "channels_deleteChannel": "Ta bort kanal", diff --git a/lib/l10n/app_uk.arb b/lib/l10n/app_uk.arb index d8d3b7db..d7cee3fc 100644 --- a/lib/l10n/app_uk.arb +++ b/lib/l10n/app_uk.arb @@ -362,6 +362,10 @@ "channels_via": "через {path}", "channels_private": "Приватний", "channels_editChannel": "Редагувати канал", + "channels_notificationSettings": "Налаштування сповіщень", + "channels_notifyAll": "Усі повідомлення", + "channels_notifyMentionsOnly": "Лише згадки", + "channels_notifyNone": "Вимкнено", "channels_muteChannel": "Вимкнути сповіщення каналу", "channels_unmuteChannel": "Увімкнути сповіщення каналу", "channels_deleteChannel": "Видалити канал", diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 410b3a42..644435c8 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -374,6 +374,10 @@ "channels_public": "公共", "channels_private": "私有", "channels_editChannel": "编辑频道", + "channels_notificationSettings": "通知设置", + "channels_notifyAll": "所有消息", + "channels_notifyMentionsOnly": "仅提及", + "channels_notifyNone": "静音", "channels_muteChannel": "静音频道", "channels_unmuteChannel": "取消静音频道", "channels_deleteChannel": "删除频道", diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index b3632585..f664f083 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -3,6 +3,8 @@ import 'translation_support.dart'; enum UnitSystem { metric, imperial } +enum ChannelNotificationMode { all, mentionsOnly, muted } + extension UnitSystemValue on UnitSystem { String get value { switch (this) { @@ -123,7 +125,7 @@ class AppSettings { final Map batteryChemistryByDeviceId; final Map batteryChemistryByRepeaterId; final UnitSystem unitSystem; - final Set mutedChannels; + final Map channelNotificationModes; final bool mapShowDiscoveryContacts; final bool evictDiscoveredContactsEnabled; final String tcpServerAddress; @@ -238,7 +240,7 @@ class AppSettings { Map? batteryChemistryByDeviceId, Map? batteryChemistryByRepeaterId, this.unitSystem = UnitSystem.metric, - Set? mutedChannels, + Map? channelNotificationModes, this.mapShowDiscoveryContacts = true, this.evictDiscoveredContactsEnabled = true, this.tcpServerAddress = '', @@ -264,7 +266,7 @@ class AppSettings { String? selectedCyr2latProfileId, }) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {}, batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {}, - mutedChannels = mutedChannels ?? {}, + channelNotificationModes = channelNotificationModes ?? {}, imageCodecDownloadedModels = imageCodecDownloadedModels ?? const [], translationDownloadedModels = translationDownloadedModels ?? const [], cyr2latProfiles = @@ -322,7 +324,14 @@ class AppSettings { 'battery_chemistry_by_device_id': batteryChemistryByDeviceId, 'battery_chemistry_by_repeater_id': batteryChemistryByRepeaterId, 'unit_system': unitSystem.value, - 'muted_channels': mutedChannels.toList(), + // Written for older builds that only read the muted set. + 'muted_channels': [ + for (final entry in channelNotificationModes.entries) + if (entry.value == ChannelNotificationMode.muted) entry.key, + ], + 'channel_notification_modes': channelNotificationModes.map( + (key, value) => MapEntry(key, value.name), + ), 'map_show_discovery_contacts': mapShowDiscoveryContacts, 'evict_discovered_contacts_enabled': evictDiscoveredContactsEnabled, 'tcp_server_address': tcpServerAddress, @@ -363,6 +372,35 @@ class AppSettings { return UnitSystem.metric; } + Map parseChannelNotificationModes( + Map json, + ) { + // Migration from old muted_channels (Set) to new system + final mutedList = json['muted_channels'] as List?; + final newModes = json['channel_notification_modes'] as Map?; + + final result = {}; + + // Migrate old muted channels + if (mutedList != null) { + for (final channelName in mutedList) { + result[channelName.toString()] = ChannelNotificationMode.muted; + } + } + + // Load new modes (overrides old muted channels if present) + if (newModes != null) { + for (final entry in newModes.entries) { + final value = entry.value; + if (value is! String) continue; + final mode = ChannelNotificationMode.values.asNameMap()[value]; + if (mode != null) result[entry.key.toString()] = mode; + } + } + + return result; + } + return AppSettings( clearPathOnMaxRetry: json['clear_path_on_max_retry'] as bool? ?? false, mapShowRepeaters: json['map_show_repeaters'] as bool? ?? true, @@ -425,11 +463,7 @@ class AppSettings { ) ?? {}, unitSystem: parseUnitSystem(json['unit_system']), - mutedChannels: - ((json['muted_channels'] as List?) - ?.map((e) => e.toString()) - .toSet()) ?? - {}, + channelNotificationModes: parseChannelNotificationModes(json), mapShowDiscoveryContacts: json['map_show_discovery_contacts'] as bool? ?? true, evictDiscoveredContactsEnabled: @@ -554,7 +588,7 @@ class AppSettings { Map? batteryChemistryByDeviceId, Map? batteryChemistryByRepeaterId, UnitSystem? unitSystem, - Set? mutedChannels, + Map? channelNotificationModes, bool? mapShowDiscoveryContacts, bool? evictDiscoveredContactsEnabled, String? tcpServerAddress, @@ -639,7 +673,8 @@ class AppSettings { batteryChemistryByRepeaterId: batteryChemistryByRepeaterId ?? this.batteryChemistryByRepeaterId, unitSystem: unitSystem ?? this.unitSystem, - mutedChannels: mutedChannels ?? this.mutedChannels, + channelNotificationModes: + channelNotificationModes ?? this.channelNotificationModes, mapShowDiscoveryContacts: mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts, evictDiscoveredContactsEnabled: diff --git a/lib/review_mode/review_mode_storage.dart b/lib/review_mode/review_mode_storage.dart index 2ccfc569..de787edb 100644 --- a/lib/review_mode/review_mode_storage.dart +++ b/lib/review_mode/review_mode_storage.dart @@ -1,13 +1,17 @@ -import '../services/app_settings_service.dart'; +import 'dart:convert'; + +import '../services/app_settings_service.dart' + show AppSettingsService, ChannelNotificationMode; import '../services/storage_service.dart'; import '../services/timeout_prediction_service.dart'; import '../storage/legacy_key_migration.dart'; import '../storage/prefs_manager.dart'; import 'review_radio.dart'; -/// Muted channel names as they were when review mode started. Persisted so an -/// interrupted session (crash, app killed) is still undone on the next launch. -const _savedMutedChannelsKey = 'review_mode_saved_muted_channels'; +/// Channel notification modes (JSON map of channel name to mode name) as they +/// were when review mode started. Persisted so an interrupted session (crash, +/// app killed) is still undone on the next launch. +const _savedChannelModesKey = 'review_mode_saved_channel_modes'; /// Prefix for snapshots of app-wide repeater keys (saved passwords, clock sync /// toggles) taken when review mode starts. An empty snapshot means the key did @@ -31,10 +35,11 @@ Future clearReviewModeData() async { /// Starts a review session from a clean slate. /// /// The simulated radio's scope never adopts legacy unscoped keys, so real -/// radio data cannot be pulled into it. Channel mutes are app-wide and keyed -/// by channel name (muting the simulated "Public" would mute the real one), -/// so the current mutes are saved for [endReviewModeSession] to put back, as -/// are the app-wide repeater keys. Delivery timing is not recorded meanwhile. +/// radio data cannot be pulled into it. Channel notification modes are +/// app-wide and keyed by channel name (muting the simulated "Public" would +/// mute the real one), so the current modes are saved for +/// [endReviewModeSession] to put back, as are the app-wide repeater keys. +/// Delivery timing is not recorded meanwhile. Future beginReviewModeSession(AppSettingsService? settings) async { scopesWithoutLegacyMigration.add(ReviewRadio.storagePrefix); TimeoutPredictionService.recordingSuspended = true; @@ -47,16 +52,16 @@ Future beginReviewModeSession(AppSettingsService? settings) async { await prefs.setString(savedKey, prefs.getString(key) ?? ''); } // An earlier interrupted session's record holds the real pre-review state. - if (settings != null && !prefs.containsKey(_savedMutedChannelsKey)) { - await prefs.setStringList( - _savedMutedChannelsKey, - settings.settings.mutedChannels.toList(), + if (settings != null && !prefs.containsKey(_savedChannelModesKey)) { + final modes = settings.settings.channelNotificationModes.map( + (channel, mode) => MapEntry(channel, mode.name), ); + await prefs.setString(_savedChannelModesKey, jsonEncode(modes)); } } -/// Deletes the review session's data and restores the channel mutes and -/// repeater keys saved by [beginReviewModeSession]. Also called at startup to finish a session that +/// Deletes the review session's data and restores the channel notification +/// modes and repeater keys saved by [beginReviewModeSession]. Also called at startup to finish a session that /// was interrupted; it does nothing when no session was left behind. Future endReviewModeSession(AppSettingsService? settings) async { TimeoutPredictionService.recordingSuspended = false; @@ -73,10 +78,19 @@ Future endReviewModeSession(AppSettingsService? settings) async { } await prefs.remove(savedKey); } - final savedMutes = prefs.getStringList(_savedMutedChannelsKey); - if (savedMutes == null || settings == null) return; + final savedModes = prefs.getString(_savedChannelModesKey); + if (savedModes == null || settings == null) return; + final restored = {}; + final decoded = jsonDecode(savedModes); + if (decoded is Map) { + final byName = ChannelNotificationMode.values.asNameMap(); + for (final entry in decoded.entries) { + final mode = byName[entry.value]; + if (mode != null) restored[entry.key.toString()] = mode; + } + } await settings.updateSettings( - settings.settings.copyWith(mutedChannels: savedMutes.toSet()), + settings.settings.copyWith(channelNotificationModes: restored), ); - await prefs.remove(_savedMutedChannelsKey); + await prefs.remove(_savedChannelModesKey); } diff --git a/lib/screens/channel_chat_screen.dart b/lib/screens/channel_chat_screen.dart index 358ea298..7f5049dd 100644 --- a/lib/screens/channel_chat_screen.dart +++ b/lib/screens/channel_chat_screen.dart @@ -26,7 +26,8 @@ import '../l10n/l10n.dart'; import '../models/channel.dart'; import '../models/channel_message.dart'; import '../models/image_codec_support.dart' show aeicRatePointForUi; -import '../services/app_settings_service.dart'; +import '../services/app_settings_service.dart' + show AppSettingsService, ChannelNotificationMode; import '../services/chat_text_scale_service.dart'; import '../services/image_chunk_transport.dart'; import '../services/image_codec_service.dart'; @@ -36,6 +37,7 @@ import '../utils/image_save.dart'; import '../utils/lora_airtime.dart'; import '../widgets/marker_label_dialog.dart'; import '../widgets/received_image_message.dart'; +import '../widgets/channel_notification_mode_sheet.dart'; import '../widgets/chat_day_separator.dart'; import '../widgets/empty_state.dart'; @@ -403,19 +405,22 @@ class _ChannelChatScreenState extends State { Consumer( builder: (context, settings, _) { final muteKey = widget.channel.muteKey; - final muted = settings.isChannelMuted(muteKey); + final notificationMode = settings.getChannelNotificationMode( + muteKey, + ); return IconButton( - tooltip: muted - ? context.l10n.channels_unmuteChannel - : context.l10n.channels_muteChannel, - icon: Icon( - muted - ? Icons.notifications_off_outlined - : Icons.notifications_outlined, + tooltip: context.l10n.channels_notificationModeTooltip( + channelNotificationModeLabel(context, notificationMode), ), - onPressed: () => muted - ? settings.unmuteChannel(muteKey) - : settings.muteChannel(muteKey), + icon: Icon( + notificationMode == ChannelNotificationMode.muted + ? Icons.notifications_off + : notificationMode == ChannelNotificationMode.mentionsOnly + ? Icons.notification_important + : Icons.notifications, + ), + onPressed: () => + showChannelNotificationModeSheet(context, muteKey), ); }, ), diff --git a/lib/screens/channels_screen.dart b/lib/screens/channels_screen.dart index f0c0bb35..53d561ac 100644 --- a/lib/screens/channels_screen.dart +++ b/lib/screens/channels_screen.dart @@ -10,7 +10,8 @@ import 'package:uuid/uuid.dart'; import '../connector/meshcore_connector.dart'; import '../l10n/l10n.dart'; -import '../services/app_settings_service.dart'; +import '../services/app_settings_service.dart' + show AppSettingsService, ChannelNotificationMode; import '../services/ui_view_state_service.dart'; import '../models/channel.dart'; import '../models/community.dart'; @@ -19,6 +20,7 @@ import '../theme/mesh_theme.dart'; import '../utils/dialog_utils.dart'; import '../utils/disconnect_navigation_mixin.dart'; import '../utils/route_transitions.dart'; +import '../widgets/channel_notification_mode_sheet.dart'; import '../widgets/list_filter_widget.dart'; import '../widgets/empty_state.dart'; import '../widgets/mesh_ui.dart'; @@ -372,9 +374,9 @@ class _ChannelsScreenState extends State int listIndex = 0, }) { final unreadCount = connector.getUnreadCountForChannel(channel); - final isMuted = context.watch().isChannelMuted( - channel.muteKey, - ); + final notificationMode = context + .watch() + .getChannelNotificationMode(channel.muteKey); final scheme = Theme.of(context).colorScheme; // Determine icon and colors based on channel type @@ -580,9 +582,9 @@ class _ChannelsScreenState extends State Row( mainAxisSize: MainAxisSize.min, children: [ - if (isMuted) ...[ + if (notificationMode != ChannelNotificationMode.all) ...[ Icon( - Icons.notifications_off, + channelNotificationModeIcon(notificationMode), size: 18, color: scheme.onSurfaceVariant, ), @@ -625,8 +627,6 @@ class _ChannelsScreenState extends State Channel channel, ) { final parentContext = context; - final settingsService = context.read(); - final isMuted = settingsService.isChannelMuted(channel.muteKey); showMeshSheet( parentContext, @@ -645,23 +645,19 @@ class _ChannelsScreenState extends State } }, ), + // Notification mode selection ListTile( - leading: Icon( - isMuted - ? Icons.notifications_outlined - : Icons.notifications_off_outlined, - ), - title: Text( - isMuted - ? sheetContext.l10n.channels_unmuteChannel - : sheetContext.l10n.channels_muteChannel, - ), + leading: const Icon(Icons.notifications_outlined), + title: Text(sheetContext.l10n.channels_notificationSettings), + trailing: const Icon(Icons.chevron_right), onTap: () async { Navigator.pop(sheetContext); - if (isMuted) { - await settingsService.unmuteChannel(channel.muteKey); - } else { - await settingsService.muteChannel(channel.muteKey); + await Future.delayed(const Duration(milliseconds: 100)); + if (parentContext.mounted) { + showChannelNotificationModeSheet( + parentContext, + channel.muteKey, + ); } }, ), diff --git a/lib/services/app_settings_service.dart b/lib/services/app_settings_service.dart index 3cf9e7d9..d5d4b433 100644 --- a/lib/services/app_settings_service.dart +++ b/lib/services/app_settings_service.dart @@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart'; import '../models/app_settings.dart'; import '../models/image_codec_support.dart'; import '../models/translation_support.dart'; + +export '../models/app_settings.dart' show ChannelNotificationMode; import '../storage/prefs_manager.dart'; import '../utils/app_logger.dart'; import '../helpers/cyr2lat.dart'; @@ -286,19 +288,24 @@ class AppSettingsService extends ChangeNotifier { await updateSettings(_settings.copyWith(unitSystem: value)); } - bool isChannelMuted(String channelName) { - return _settings.mutedChannels.contains(channelName); + ChannelNotificationMode getChannelNotificationMode(String channelName) { + return _settings.channelNotificationModes[channelName] ?? + ChannelNotificationMode.all; } - Future muteChannel(String channelName) async { - final updated = Set.from(_settings.mutedChannels)..add(channelName); - await updateSettings(_settings.copyWith(mutedChannels: updated)); - } - - Future unmuteChannel(String channelName) async { - final updated = Set.from(_settings.mutedChannels) - ..remove(channelName); - await updateSettings(_settings.copyWith(mutedChannels: updated)); + Future setChannelNotificationMode( + String channelName, + ChannelNotificationMode mode, + ) async { + final updated = Map.from( + _settings.channelNotificationModes, + ); + if (mode == ChannelNotificationMode.all) { + updated.remove(channelName); + } else { + updated[channelName] = mode; + } + await updateSettings(_settings.copyWith(channelNotificationModes: updated)); } Future setTcpServerAddress(String value) async { diff --git a/lib/widgets/channel_notification_mode_sheet.dart b/lib/widgets/channel_notification_mode_sheet.dart new file mode 100644 index 00000000..9239aff2 --- /dev/null +++ b/lib/widgets/channel_notification_mode_sheet.dart @@ -0,0 +1,65 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../l10n/l10n.dart'; +import '../services/app_settings_service.dart' + show AppSettingsService, ChannelNotificationMode; +import 'mesh_ui.dart'; + +/// Localized label for a channel notification [mode]. +String channelNotificationModeLabel( + BuildContext context, + ChannelNotificationMode mode, +) => switch (mode) { + ChannelNotificationMode.all => context.l10n.channels_notifyAll, + ChannelNotificationMode.mentionsOnly => + context.l10n.channels_notifyMentionsOnly, + ChannelNotificationMode.muted => context.l10n.channels_notifyNone, +}; + +/// Icon for a channel notification [mode]. +IconData channelNotificationModeIcon(ChannelNotificationMode mode) => + switch (mode) { + ChannelNotificationMode.all => Icons.notifications, + ChannelNotificationMode.mentionsOnly => Icons.notification_important, + ChannelNotificationMode.muted => Icons.notifications_off, + }; + +/// Shows the per-channel notification mode picker (all / mentions only / +/// muted) for the channel identified by [muteKey]. +void showChannelNotificationModeSheet(BuildContext context, String muteKey) { + final settingsService = context.read(); + final currentMode = settingsService.getChannelNotificationMode(muteKey); + + showMeshSheet( + context, + builder: (sheetContext) { + final scheme = Theme.of(sheetContext).colorScheme; + return SafeArea( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + for (final mode in ChannelNotificationMode.values) + ListTile( + leading: Icon( + channelNotificationModeIcon(mode), + color: mode == currentMode + ? scheme.primary + : scheme.onSurfaceVariant, + ), + title: Text(channelNotificationModeLabel(sheetContext, mode)), + trailing: mode == currentMode ? const Icon(Icons.check) : null, + onTap: () async { + Navigator.pop(sheetContext); + await settingsService.setChannelNotificationMode( + muteKey, + mode, + ); + }, + ), + ], + ), + ); + }, + ); +} diff --git a/test/connector/mention_detection_test.dart b/test/connector/mention_detection_test.dart new file mode 100644 index 00000000..91e84e54 --- /dev/null +++ b/test/connector/mention_detection_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/connector/meshcore_connector.dart'; + +void main() { + bool mentions(String text, String? name) => + MeshCoreConnector.textMentionsName(text, name); + + test('matches bracketed and plain mentions case-insensitively', () { + expect(mentions('@[Bob] hello', 'Bob'), isTrue); + expect(mentions('hey @[bob]', 'Bob'), isTrue); + expect(mentions('hey @bob, look', 'Bob'), isTrue); + expect(mentions('@BOB', 'Bob'), isTrue); + expect(mentions('ping @Иван!', 'иван'), isTrue); + }); + + test('requires a word boundary for plain mentions', () { + expect(mentions('hey @bobby', 'Bob'), isFalse); + expect(mentions('mail x@bob.com', 'Bob'), isFalse); + expect(mentions('hey bob', 'Bob'), isFalse); + }); + + test('names with spaces or regex characters must match in full', () { + expect(mentions('hi @Bob Smith', 'Bob Smith'), isTrue); + expect(mentions('hi @Bob', 'Bob Smith'), isFalse); + expect(mentions('@[Node (1)] ok', 'Node (1)'), isTrue); + expect(mentions('@[Node 1] ok', 'Node (1)'), isFalse); + }); + + test('no self name never matches', () { + expect(mentions('@[Bob] hi', null), isFalse); + expect(mentions('@ hi', ''), isFalse); + }); +} diff --git a/test/models/channel_notification_modes_json_test.dart b/test/models/channel_notification_modes_json_test.dart new file mode 100644 index 00000000..abd2bbef --- /dev/null +++ b/test/models/channel_notification_modes_json_test.dart @@ -0,0 +1,37 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:meshcore_open/models/app_settings.dart'; + +void main() { + test('channel notification modes round-trip by name', () { + final settings = AppSettings( + channelNotificationModes: { + 'a': ChannelNotificationMode.mentionsOnly, + 'b': ChannelNotificationMode.muted, + }, + ); + final json = settings.toJson(); + expect(json['channel_notification_modes'], { + 'a': 'mentionsOnly', + 'b': 'muted', + }); + expect(json['muted_channels'], ['b']); + expect( + AppSettings.fromJson(json).channelNotificationModes, + settings.channelNotificationModes, + ); + }); + + test('invalid channel notification mode entries are skipped', () { + final settings = AppSettings.fromJson({ + 'channel_notification_modes': { + 'ok': 'muted', + 'unknown': 'loud', + 'int': 2, + 'null': null, + }, + }); + expect(settings.channelNotificationModes, { + 'ok': ChannelNotificationMode.muted, + }); + }); +} diff --git a/test/review_mode/review_mode_settings_revert_test.dart b/test/review_mode/review_mode_settings_revert_test.dart index fcd6ce3c..493163dd 100644 --- a/test/review_mode/review_mode_settings_revert_test.dart +++ b/test/review_mode/review_mode_settings_revert_test.dart @@ -24,7 +24,10 @@ void main() { test('channel mutes made in review mode are undone on exit', () async { final settings = AppSettingsService(); await settings.loadSettings(); - await settings.muteChannel('Hiking Group'); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.muted, + ); final connector = MeshCoreConnector(); addTearDown(connector.dispose); final retryService = MessageRetryService(); @@ -39,23 +42,41 @@ void main() { await connector.connectReview(); // Mutes are keyed by channel name, so these would leak into real radios. - await settings.muteChannel('Public'); - await settings.unmuteChannel('Hiking Group'); + await settings.setChannelNotificationMode( + 'Public', + ChannelNotificationMode.muted, + ); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.all, + ); // Other app preferences are the user's to change, even while reviewing. await PrefsManager.instance.setString('unrelated_key', 'changed'); await connector.disconnect(manual: true); - expect(settings.isChannelMuted('Public'), isFalse); - expect(settings.isChannelMuted('Hiking Group'), isTrue); + expect( + settings.getChannelNotificationMode('Public'), + ChannelNotificationMode.all, + ); + expect( + settings.getChannelNotificationMode('Hiking Group'), + ChannelNotificationMode.muted, + ); expect(PrefsManager.instance.getString('unrelated_key'), 'changed'); // A fresh launch has nothing left to undo. final relaunched = AppSettingsService(); await relaunched.loadSettings(); await endReviewModeSession(relaunched); - expect(relaunched.isChannelMuted('Public'), isFalse); - expect(relaunched.isChannelMuted('Hiking Group'), isTrue); + expect( + relaunched.getChannelNotificationMode('Public'), + ChannelNotificationMode.all, + ); + expect( + relaunched.getChannelNotificationMode('Hiking Group'), + ChannelNotificationMode.muted, + ); }); test( @@ -63,11 +84,20 @@ void main() { () async { final settings = AppSettingsService(); await settings.loadSettings(); - await settings.muteChannel('Hiking Group'); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.muted, + ); await beginReviewModeSession(settings); - await settings.muteChannel('Public'); - await settings.unmuteChannel('Hiking Group'); + await settings.setChannelNotificationMode( + 'Public', + ChannelNotificationMode.muted, + ); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.all, + ); await PrefsManager.instance.setString( 'contacts${ReviewRadio.storagePrefix}', '[]', @@ -76,11 +106,20 @@ void main() { final relaunched = AppSettingsService(); await relaunched.loadSettings(); - expect(relaunched.isChannelMuted('Public'), isTrue); + expect( + relaunched.getChannelNotificationMode('Public'), + ChannelNotificationMode.muted, + ); await endReviewModeSession(relaunched); - expect(relaunched.isChannelMuted('Public'), isFalse); - expect(relaunched.isChannelMuted('Hiking Group'), isTrue); + expect( + relaunched.getChannelNotificationMode('Public'), + ChannelNotificationMode.all, + ); + expect( + relaunched.getChannelNotificationMode('Hiking Group'), + ChannelNotificationMode.muted, + ); expect( PrefsManager.instance.getKeys().where( (k) => k.contains(ReviewRadio.storagePrefix), @@ -90,6 +129,61 @@ void main() { }, ); + test('every channel notification mode is restored on exit', () async { + final settings = AppSettingsService(); + await settings.loadSettings(); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.mentionsOnly, + ); + await settings.setChannelNotificationMode( + 'Noisy', + ChannelNotificationMode.muted, + ); + + await beginReviewModeSession(settings); + await settings.setChannelNotificationMode( + 'Hiking Group', + ChannelNotificationMode.all, + ); + await settings.setChannelNotificationMode( + 'Noisy', + ChannelNotificationMode.mentionsOnly, + ); + await settings.setChannelNotificationMode( + 'Public', + ChannelNotificationMode.mentionsOnly, + ); + await endReviewModeSession(settings); + + expect( + settings.getChannelNotificationMode('Hiking Group'), + ChannelNotificationMode.mentionsOnly, + ); + expect( + settings.getChannelNotificationMode('Noisy'), + ChannelNotificationMode.muted, + ); + expect( + settings.getChannelNotificationMode('Public'), + ChannelNotificationMode.all, + ); + }); + + test('setting a channel back to all drops its stored mode', () async { + final settings = AppSettingsService(); + await settings.loadSettings(); + await settings.setChannelNotificationMode( + 'Public', + ChannelNotificationMode.muted, + ); + await settings.setChannelNotificationMode( + 'Public', + ChannelNotificationMode.all, + ); + expect(settings.settings.channelNotificationModes, isEmpty); + }); + test('the review scope never adopts legacy unscoped data', () async { await PrefsManager.instance.setString('contacts', '[]'); await beginReviewModeSession(null); diff --git a/untranslated.json b/untranslated.json index 648cd980..0782702d 100644 --- a/untranslated.json +++ b/untranslated.json @@ -1,5 +1,70 @@ { "bg": [ + "channels_notificationModeTooltip" + ], + + "de": [ + "channels_notificationModeTooltip" + ], + + "es": [ + "channels_notificationModeTooltip" + ], + + "fr": [ + "channels_notificationModeTooltip" + ], + + "hu": [ + "channels_notificationModeTooltip" + ], + + "it": [ + "channels_notificationModeTooltip" + ], + + "ja": [ + "channels_notificationModeTooltip" + ], + + "ko": [ + "channels_notificationModeTooltip" + ], + + "nl": [ + "channels_notificationModeTooltip" + ], + + "pl": [ + "channels_notificationModeTooltip" + ], + + "pt": [ + "channels_notificationModeTooltip" + ], + + "ru": [ + "channels_notificationModeTooltip" + ], + + "sk": [ + "channels_notificationModeTooltip" + ], + + "sl": [ + "channels_notificationModeTooltip" + ], + + "sv": [ + "channels_notificationModeTooltip" + ], + + "uk": [ + "channels_notificationModeTooltip" + ], + + "zh": [ + "channels_notificationModeTooltip" "settings_pathHashModeNotApplied" ],