Fix review findings in channel notification modes
- Detect mentions on the original text, as @[name] or a whole-word @name - Save and restore the full mode map in review mode - Open the mode picker from the chat bell and show the mode in its tooltip - Share one mode picker sheet; fix the stale sheet context - Persist modes by name and skip unknown entries - Keep writing muted_channels so older builds keep the user's mutes - Remove the muteChannel/unmuteChannel/isChannelMuted shims - Update notifications docs to match the behaviour
This commit is contained in:
1 parent
705bff2f15
commit
f667320608
32 files changed
+502
-196
No files matched your search
@@ -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.
|
- **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.
|
- **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.
|
- **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.
|
- 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.
|
- Replies are sent as typed; composer translation is not applied.
|
||||||
|
|
||||||
@@ -106,16 +106,17 @@ Each channel supports three notification modes:
|
|||||||
| Mode | Icon | Behavior |
|
| Mode | Icon | Behavior |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| **All messages** | 🔔 | Receive notifications for every message |
|
| **All messages** | 🔔 | Receive notifications for every message |
|
||||||
| **Mentions only** | 🔔! | Only notify when someone mentions you with "@[yourname]" |
|
| **Mentions only** | 🔔! | Only notify when a message mentions your name (see below) |
|
||||||
| **Muted** | 🔕 | No notifications |
|
| **Muted** | 🔕 | No notifications |
|
||||||
|
|
||||||
Set the mode from:
|
Set the mode from:
|
||||||
|
|
||||||
- The notifications icon in the channel chat app bar (tap to cycle through modes)
|
- 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
|
- Long-press a channel in the channels list → **Notification settings** → select mode
|
||||||
- Channel notification actions (Android)
|
|
||||||
|
|
||||||
Mentions are detected by looking for "@[yourname]" (username in brackets, case-insensitive).
|
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
|
## Rate Limiting
|
||||||
|
|
||||||
|
|||||||
@@ -1247,8 +1247,9 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
/// (notification shade, watch, or Android Auto).
|
/// (notification shade, watch, or Android Auto).
|
||||||
Future<void> handleNotificationReply(NotificationReply reply) async {
|
Future<void> handleNotificationReply(NotificationReply reply) async {
|
||||||
if (reply.action == NotificationReplyAction.mute) {
|
if (reply.action == NotificationReplyAction.mute) {
|
||||||
await _appSettingsService?.muteChannel(
|
await _appSettingsService?.setChannelNotificationMode(
|
||||||
_channelDisplayName(reply.channelIndex!),
|
_channelDisplayName(reply.channelIndex!),
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
);
|
);
|
||||||
await _notificationService.clearChannelNotification(
|
await _notificationService.clearChannelNotification(
|
||||||
reply.channelIndex!,
|
reply.channelIndex!,
|
||||||
@@ -7369,9 +7370,11 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
? translationResult.translatedText.trim()
|
? translationResult.translatedText.trim()
|
||||||
: message.text.trim();
|
: message.text.trim();
|
||||||
|
|
||||||
// If mode is mentionsOnly, check if message mentions us
|
// Mentions are matched on the untranslated text.
|
||||||
if (notificationMode == ChannelNotificationMode.mentionsOnly) {
|
if (notificationMode == ChannelNotificationMode.mentionsOnly) {
|
||||||
if (!_doesMessageMentionUs(resolvedText, message)) return;
|
if (!textMentionsName(message.originalText ?? message.text, _selfName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unawaited(() async {
|
unawaited(() async {
|
||||||
@@ -7386,22 +7389,20 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||||||
}());
|
}());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if a message mentions the current user.
|
/// Whether [text] mentions [name], case-insensitively, as either
|
||||||
/// Detects: @[username] format only.
|
/// `@[name]` (the reply/mention prefix the app sends) or a plain `@name`.
|
||||||
bool _doesMessageMentionUs(String messageText, ChannelMessage message) {
|
/// The plain form needs a word boundary on both sides, so `@bobby` does
|
||||||
final selfName = _selfName;
|
/// not mention `bob` and `x@bob.com` is not a mention. Names containing
|
||||||
final lowerMessage = messageText.toLowerCase();
|
/// spaces must be written out in full.
|
||||||
|
@visibleForTesting
|
||||||
// Check for @[username] pattern (bracketed mention format)
|
static bool textMentionsName(String text, String? name) {
|
||||||
if (selfName != null && selfName.isNotEmpty) {
|
if (name == null || name.isEmpty) return false;
|
||||||
final lowerSelfName = selfName.toLowerCase();
|
final escaped = RegExp.escape(name);
|
||||||
final bracketedMentionPattern = RegExp(
|
return RegExp(
|
||||||
r'@\[(' + RegExp.escape(lowerSelfName) + r')\]',
|
'@\\[$escaped\\]|(?<![\\p{L}\\p{N}_])@$escaped(?![\\p{L}\\p{N}_])',
|
||||||
);
|
caseSensitive: false,
|
||||||
if (bracketedMentionPattern.hasMatch(lowerMessage)) return true;
|
unicode: true,
|
||||||
}
|
).hasMatch(text);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles RESP_CODE_CHANNEL_DATA_RECV (GRP_DATA). Frames whose dataType is
|
/// Handles RESP_CODE_CHANNEL_DATA_RECV (GRP_DATA). Frames whose dataType is
|
||||||
|
|||||||
@@ -719,6 +719,14 @@
|
|||||||
"channels_notifyAll": "All messages",
|
"channels_notifyAll": "All messages",
|
||||||
"channels_notifyMentionsOnly": "Mentions only",
|
"channels_notifyMentionsOnly": "Mentions only",
|
||||||
"channels_notifyNone": "Muted",
|
"channels_notifyNone": "Muted",
|
||||||
|
"channels_notificationModeTooltip": "Notifications: {mode}",
|
||||||
|
"@channels_notificationModeTooltip": {
|
||||||
|
"placeholders": {
|
||||||
|
"mode": {
|
||||||
|
"type": "String"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"channels_muteChannel": "Mute channel",
|
"channels_muteChannel": "Mute channel",
|
||||||
"channels_unmuteChannel": "Unmute channel",
|
"channels_unmuteChannel": "Unmute channel",
|
||||||
"channels_deleteChannel": "Delete channel",
|
"channels_deleteChannel": "Delete channel",
|
||||||
|
|||||||
@@ -2644,6 +2644,12 @@ abstract class AppLocalizations {
|
|||||||
/// **'Muted'**
|
/// **'Muted'**
|
||||||
String get channels_notifyNone;
|
String get channels_notifyNone;
|
||||||
|
|
||||||
|
/// No description provided for @channels_notificationModeTooltip.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Notifications: {mode}'**
|
||||||
|
String channels_notificationModeTooltip(String mode);
|
||||||
|
|
||||||
/// No description provided for @channels_muteChannel.
|
/// No description provided for @channels_muteChannel.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -1476,6 +1476,11 @@ class AppLocalizationsBg extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Заглушено';
|
String get channels_notifyNone => 'Заглушено';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Заглуши канала';
|
String get channels_muteChannel => 'Заглуши канала';
|
||||||
|
|
||||||
|
|||||||
@@ -1470,6 +1470,11 @@ class AppLocalizationsDe extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Stummgeschaltet';
|
String get channels_notifyNone => 'Stummgeschaltet';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Kanal stummschalten';
|
String get channels_muteChannel => 'Kanal stummschalten';
|
||||||
|
|
||||||
|
|||||||
@@ -1450,6 +1450,11 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Muted';
|
String get channels_notifyNone => 'Muted';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Mute channel';
|
String get channels_muteChannel => 'Mute channel';
|
||||||
|
|
||||||
|
|||||||
@@ -1469,6 +1469,11 @@ class AppLocalizationsEs extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Silenciado';
|
String get channels_notifyNone => 'Silenciado';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Silenciar canal';
|
String get channels_muteChannel => 'Silenciar canal';
|
||||||
|
|
||||||
|
|||||||
@@ -1474,6 +1474,11 @@ class AppLocalizationsFr extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Désactivé';
|
String get channels_notifyNone => 'Désactivé';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Désactiver les notifications du canal';
|
String get channels_muteChannel => 'Désactiver les notifications du canal';
|
||||||
|
|
||||||
|
|||||||
@@ -1465,6 +1465,11 @@ class AppLocalizationsHu extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Némít';
|
String get channels_notifyNone => 'Némít';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Csatorna némítása';
|
String get channels_muteChannel => 'Csatorna némítása';
|
||||||
|
|
||||||
|
|||||||
@@ -1473,6 +1473,11 @@ class AppLocalizationsIt extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Silenziato';
|
String get channels_notifyNone => 'Silenziato';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Silenzia canale';
|
String get channels_muteChannel => 'Silenzia canale';
|
||||||
|
|
||||||
|
|||||||
@@ -1397,6 +1397,11 @@ class AppLocalizationsJa extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'ミュート';
|
String get channels_notifyNone => 'ミュート';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'チャンネルをミュート';
|
String get channels_muteChannel => 'チャンネルをミュート';
|
||||||
|
|
||||||
|
|||||||
@@ -1402,6 +1402,11 @@ class AppLocalizationsKo extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => '음소거';
|
String get channels_notifyNone => '음소거';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => '음소거 채널';
|
String get channels_muteChannel => '음소거 채널';
|
||||||
|
|
||||||
|
|||||||
@@ -1461,6 +1461,11 @@ class AppLocalizationsNl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Gedempt';
|
String get channels_notifyNone => 'Gedempt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Kanaal dempen';
|
String get channels_muteChannel => 'Kanaal dempen';
|
||||||
|
|
||||||
|
|||||||
@@ -1487,6 +1487,11 @@ class AppLocalizationsPl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Wyciszone';
|
String get channels_notifyNone => 'Wyciszone';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Wycisz kanał';
|
String get channels_muteChannel => 'Wycisz kanał';
|
||||||
|
|
||||||
|
|||||||
@@ -1472,6 +1472,11 @@ class AppLocalizationsPt extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Silenciado';
|
String get channels_notifyNone => 'Silenciado';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Silenciar canal';
|
String get channels_muteChannel => 'Silenciar canal';
|
||||||
|
|
||||||
|
|||||||
@@ -1476,6 +1476,11 @@ class AppLocalizationsRu extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Без звука';
|
String get channels_notifyNone => 'Без звука';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Отключить уведомления канала';
|
String get channels_muteChannel => 'Отключить уведомления канала';
|
||||||
|
|
||||||
|
|||||||
@@ -1464,6 +1464,11 @@ class AppLocalizationsSk extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Stíšené';
|
String get channels_notifyNone => 'Stíšené';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Stlmiť kanál';
|
String get channels_muteChannel => 'Stlmiť kanál';
|
||||||
|
|
||||||
|
|||||||
@@ -1462,6 +1462,11 @@ class AppLocalizationsSl extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Utišano';
|
String get channels_notifyNone => 'Utišano';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Utišaj kanal';
|
String get channels_muteChannel => 'Utišaj kanal';
|
||||||
|
|
||||||
|
|||||||
@@ -1451,6 +1451,11 @@ class AppLocalizationsSv extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Tyst';
|
String get channels_notifyNone => 'Tyst';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Tysta kanal';
|
String get channels_muteChannel => 'Tysta kanal';
|
||||||
|
|
||||||
|
|||||||
@@ -1467,6 +1467,11 @@ class AppLocalizationsUk extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => 'Вимкнено';
|
String get channels_notifyNone => 'Вимкнено';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => 'Вимкнути сповіщення каналу';
|
String get channels_muteChannel => 'Вимкнути сповіщення каналу';
|
||||||
|
|
||||||
|
|||||||
@@ -1379,6 +1379,11 @@ class AppLocalizationsZh extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get channels_notifyNone => '静音';
|
String get channels_notifyNone => '静音';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String channels_notificationModeTooltip(String mode) {
|
||||||
|
return 'Notifications: $mode';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get channels_muteChannel => '静音频道';
|
String get channels_muteChannel => '静音频道';
|
||||||
|
|
||||||
|
|||||||
@@ -198,12 +198,6 @@ class AppSettings {
|
|||||||
return profile.charMap;
|
return profile.charMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backward compatibility: returns true if channel is muted (mode == muted)
|
|
||||||
bool isChannelMuted(String channelName) {
|
|
||||||
return channelNotificationModes[channelName] ==
|
|
||||||
ChannelNotificationMode.muted;
|
|
||||||
}
|
|
||||||
|
|
||||||
AppSettings({
|
AppSettings({
|
||||||
this.clearPathOnMaxRetry = false,
|
this.clearPathOnMaxRetry = false,
|
||||||
this.mapShowRepeaters = true,
|
this.mapShowRepeaters = true,
|
||||||
@@ -330,8 +324,13 @@ class AppSettings {
|
|||||||
'battery_chemistry_by_device_id': batteryChemistryByDeviceId,
|
'battery_chemistry_by_device_id': batteryChemistryByDeviceId,
|
||||||
'battery_chemistry_by_repeater_id': batteryChemistryByRepeaterId,
|
'battery_chemistry_by_repeater_id': batteryChemistryByRepeaterId,
|
||||||
'unit_system': unitSystem.value,
|
'unit_system': unitSystem.value,
|
||||||
|
// 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(
|
'channel_notification_modes': channelNotificationModes.map(
|
||||||
(key, value) => MapEntry(key, value.index),
|
(key, value) => MapEntry(key, value.name),
|
||||||
),
|
),
|
||||||
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
||||||
'evict_discovered_contacts_enabled': evictDiscoveredContactsEnabled,
|
'evict_discovered_contacts_enabled': evictDiscoveredContactsEnabled,
|
||||||
@@ -392,13 +391,10 @@ class AppSettings {
|
|||||||
// Load new modes (overrides old muted channels if present)
|
// Load new modes (overrides old muted channels if present)
|
||||||
if (newModes != null) {
|
if (newModes != null) {
|
||||||
for (final entry in newModes.entries) {
|
for (final entry in newModes.entries) {
|
||||||
final channelName = entry.key;
|
final value = entry.value;
|
||||||
final modeIndex = entry.value as int?;
|
if (value is! String) continue;
|
||||||
if (modeIndex != null &&
|
final mode = ChannelNotificationMode.values.asNameMap()[value];
|
||||||
modeIndex >= 0 &&
|
if (mode != null) result[entry.key.toString()] = mode;
|
||||||
modeIndex < ChannelNotificationMode.values.length) {
|
|
||||||
result[channelName] = ChannelNotificationMode.values[modeIndex];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import '../services/app_settings_service.dart'
|
import '../services/app_settings_service.dart'
|
||||||
show AppSettingsService, ChannelNotificationMode;
|
show AppSettingsService, ChannelNotificationMode;
|
||||||
import '../services/storage_service.dart';
|
import '../services/storage_service.dart';
|
||||||
@@ -6,9 +8,10 @@ import '../storage/legacy_key_migration.dart';
|
|||||||
import '../storage/prefs_manager.dart';
|
import '../storage/prefs_manager.dart';
|
||||||
import 'review_radio.dart';
|
import 'review_radio.dart';
|
||||||
|
|
||||||
/// Muted channel names as they were when review mode started. Persisted so an
|
/// Channel notification modes (JSON map of channel name to mode name) as they
|
||||||
/// interrupted session (crash, app killed) is still undone on the next launch.
|
/// were when review mode started. Persisted so an interrupted session (crash,
|
||||||
const _savedMutedChannelsKey = 'review_mode_saved_muted_channels';
|
/// 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
|
/// 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
|
/// toggles) taken when review mode starts. An empty snapshot means the key did
|
||||||
@@ -32,10 +35,11 @@ Future<void> clearReviewModeData() async {
|
|||||||
/// Starts a review session from a clean slate.
|
/// Starts a review session from a clean slate.
|
||||||
///
|
///
|
||||||
/// The simulated radio's scope never adopts legacy unscoped keys, so real
|
/// 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
|
/// radio data cannot be pulled into it. Channel notification modes are
|
||||||
/// by channel name (muting the simulated "Public" would mute the real one),
|
/// app-wide and keyed by channel name (muting the simulated "Public" would
|
||||||
/// so the current mutes are saved for [endReviewModeSession] to put back, as
|
/// mute the real one), so the current modes are saved for
|
||||||
/// are the app-wide repeater keys. Delivery timing is not recorded meanwhile.
|
/// [endReviewModeSession] to put back, as are the app-wide repeater keys.
|
||||||
|
/// Delivery timing is not recorded meanwhile.
|
||||||
Future<void> beginReviewModeSession(AppSettingsService? settings) async {
|
Future<void> beginReviewModeSession(AppSettingsService? settings) async {
|
||||||
scopesWithoutLegacyMigration.add(ReviewRadio.storagePrefix);
|
scopesWithoutLegacyMigration.add(ReviewRadio.storagePrefix);
|
||||||
TimeoutPredictionService.recordingSuspended = true;
|
TimeoutPredictionService.recordingSuspended = true;
|
||||||
@@ -48,19 +52,16 @@ Future<void> beginReviewModeSession(AppSettingsService? settings) async {
|
|||||||
await prefs.setString(savedKey, prefs.getString(key) ?? '');
|
await prefs.setString(savedKey, prefs.getString(key) ?? '');
|
||||||
}
|
}
|
||||||
// An earlier interrupted session's record holds the real pre-review state.
|
// An earlier interrupted session's record holds the real pre-review state.
|
||||||
if (settings != null && !prefs.containsKey(_savedMutedChannelsKey)) {
|
if (settings != null && !prefs.containsKey(_savedChannelModesKey)) {
|
||||||
// Save all channel notification modes
|
final modes = settings.settings.channelNotificationModes.map(
|
||||||
final channelModes = settings.settings.channelNotificationModes;
|
(channel, mode) => MapEntry(channel, mode.name),
|
||||||
final mutedChannels = channelModes.entries
|
);
|
||||||
.where((e) => e.value == ChannelNotificationMode.muted)
|
await prefs.setString(_savedChannelModesKey, jsonEncode(modes));
|
||||||
.map((e) => e.key)
|
|
||||||
.toList();
|
|
||||||
await prefs.setStringList(_savedMutedChannelsKey, mutedChannels);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deletes the review session's data and restores the channel mutes and
|
/// Deletes the review session's data and restores the channel notification
|
||||||
/// repeater keys saved by [beginReviewModeSession]. Also called at startup to finish a session that
|
/// 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.
|
/// was interrupted; it does nothing when no session was left behind.
|
||||||
Future<void> endReviewModeSession(AppSettingsService? settings) async {
|
Future<void> endReviewModeSession(AppSettingsService? settings) async {
|
||||||
TimeoutPredictionService.recordingSuspended = false;
|
TimeoutPredictionService.recordingSuspended = false;
|
||||||
@@ -77,19 +78,19 @@ Future<void> endReviewModeSession(AppSettingsService? settings) async {
|
|||||||
}
|
}
|
||||||
await prefs.remove(savedKey);
|
await prefs.remove(savedKey);
|
||||||
}
|
}
|
||||||
final savedMutes = prefs.getStringList(_savedMutedChannelsKey);
|
final savedModes = prefs.getString(_savedChannelModesKey);
|
||||||
if (savedMutes == null || settings == null) return;
|
if (savedModes == null || settings == null) return;
|
||||||
final updatedModes = Map<String, ChannelNotificationMode>.from(
|
final restored = <String, ChannelNotificationMode>{};
|
||||||
settings.settings.channelNotificationModes,
|
final decoded = jsonDecode(savedModes);
|
||||||
);
|
if (decoded is Map) {
|
||||||
updatedModes.removeWhere(
|
final byName = ChannelNotificationMode.values.asNameMap();
|
||||||
(key, value) => value == ChannelNotificationMode.muted,
|
for (final entry in decoded.entries) {
|
||||||
);
|
final mode = byName[entry.value];
|
||||||
for (final channelName in savedMutes) {
|
if (mode != null) restored[entry.key.toString()] = mode;
|
||||||
updatedModes[channelName] = ChannelNotificationMode.muted;
|
}
|
||||||
}
|
}
|
||||||
await settings.updateSettings(
|
await settings.updateSettings(
|
||||||
settings.settings.copyWith(channelNotificationModes: updatedModes),
|
settings.settings.copyWith(channelNotificationModes: restored),
|
||||||
);
|
);
|
||||||
await prefs.remove(_savedMutedChannelsKey);
|
await prefs.remove(_savedChannelModesKey);
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,7 @@ import '../utils/image_save.dart';
|
|||||||
import '../utils/lora_airtime.dart';
|
import '../utils/lora_airtime.dart';
|
||||||
import '../widgets/marker_label_dialog.dart';
|
import '../widgets/marker_label_dialog.dart';
|
||||||
import '../widgets/received_image_message.dart';
|
import '../widgets/received_image_message.dart';
|
||||||
|
import '../widgets/channel_notification_mode_sheet.dart';
|
||||||
import '../widgets/chat_day_separator.dart';
|
import '../widgets/chat_day_separator.dart';
|
||||||
import '../widgets/empty_state.dart';
|
import '../widgets/empty_state.dart';
|
||||||
|
|
||||||
@@ -408,7 +409,9 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
muteKey,
|
muteKey,
|
||||||
);
|
);
|
||||||
return IconButton(
|
return IconButton(
|
||||||
tooltip: context.l10n.channels_notificationSettings,
|
tooltip: context.l10n.channels_notificationModeTooltip(
|
||||||
|
channelNotificationModeLabel(context, notificationMode),
|
||||||
|
),
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
notificationMode == ChannelNotificationMode.muted
|
notificationMode == ChannelNotificationMode.muted
|
||||||
? Icons.notifications_off
|
? Icons.notifications_off
|
||||||
@@ -416,21 +419,8 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
|||||||
? Icons.notification_important
|
? Icons.notification_important
|
||||||
: Icons.notifications,
|
: Icons.notifications,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () =>
|
||||||
final currentMode = settings.getChannelNotificationMode(
|
showChannelNotificationModeSheet(context, muteKey),
|
||||||
muteKey,
|
|
||||||
);
|
|
||||||
ChannelNotificationMode newMode;
|
|
||||||
if (currentMode == ChannelNotificationMode.all) {
|
|
||||||
newMode = ChannelNotificationMode.mentionsOnly;
|
|
||||||
} else if (currentMode ==
|
|
||||||
ChannelNotificationMode.mentionsOnly) {
|
|
||||||
newMode = ChannelNotificationMode.muted;
|
|
||||||
} else {
|
|
||||||
newMode = ChannelNotificationMode.all;
|
|
||||||
}
|
|
||||||
settings.setChannelNotificationMode(muteKey, newMode);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import '../theme/mesh_theme.dart';
|
|||||||
import '../utils/dialog_utils.dart';
|
import '../utils/dialog_utils.dart';
|
||||||
import '../utils/disconnect_navigation_mixin.dart';
|
import '../utils/disconnect_navigation_mixin.dart';
|
||||||
import '../utils/route_transitions.dart';
|
import '../utils/route_transitions.dart';
|
||||||
|
import '../widgets/channel_notification_mode_sheet.dart';
|
||||||
import '../widgets/list_filter_widget.dart';
|
import '../widgets/list_filter_widget.dart';
|
||||||
import '../widgets/empty_state.dart';
|
import '../widgets/empty_state.dart';
|
||||||
import '../widgets/mesh_ui.dart';
|
import '../widgets/mesh_ui.dart';
|
||||||
@@ -583,9 +584,7 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
|||||||
children: [
|
children: [
|
||||||
if (notificationMode != ChannelNotificationMode.all) ...[
|
if (notificationMode != ChannelNotificationMode.all) ...[
|
||||||
Icon(
|
Icon(
|
||||||
notificationMode == ChannelNotificationMode.muted
|
channelNotificationModeIcon(notificationMode),
|
||||||
? Icons.notifications_off
|
|
||||||
: Icons.notification_important,
|
|
||||||
size: 18,
|
size: 18,
|
||||||
color: scheme.onSurfaceVariant,
|
color: scheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
@@ -651,9 +650,15 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
|||||||
leading: const Icon(Icons.notifications_outlined),
|
leading: const Icon(Icons.notifications_outlined),
|
||||||
title: Text(sheetContext.l10n.channels_notificationSettings),
|
title: Text(sheetContext.l10n.channels_notificationSettings),
|
||||||
trailing: const Icon(Icons.chevron_right),
|
trailing: const Icon(Icons.chevron_right),
|
||||||
onTap: () {
|
onTap: () async {
|
||||||
Navigator.pop(sheetContext);
|
Navigator.pop(sheetContext);
|
||||||
_showNotificationModeDialog(sheetContext, connector, channel);
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
if (parentContext.mounted) {
|
||||||
|
showChannelNotificationModeSheet(
|
||||||
|
parentContext,
|
||||||
|
channel.muteKey,
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
@@ -681,83 +686,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showNotificationModeDialog(
|
|
||||||
BuildContext context,
|
|
||||||
MeshCoreConnector connector,
|
|
||||||
Channel channel,
|
|
||||||
) {
|
|
||||||
final settingsService = context.read<AppSettingsService>();
|
|
||||||
final currentMode = settingsService.getChannelNotificationMode(
|
|
||||||
channel.muteKey,
|
|
||||||
);
|
|
||||||
|
|
||||||
showMeshSheet(
|
|
||||||
context,
|
|
||||||
builder: (sheetContext) => SafeArea(
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
// All notifications
|
|
||||||
ListTile(
|
|
||||||
leading: Icon(
|
|
||||||
Icons.notifications,
|
|
||||||
color: currentMode == ChannelNotificationMode.all
|
|
||||||
? Theme.of(sheetContext).colorScheme.primary
|
|
||||||
: Theme.of(sheetContext).colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
title: Text(sheetContext.l10n.channels_notifyAll),
|
|
||||||
trailing: currentMode == ChannelNotificationMode.all
|
|
||||||
? const Icon(Icons.check)
|
|
||||||
: null,
|
|
||||||
onTap: () async {
|
|
||||||
Navigator.pop(sheetContext);
|
|
||||||
await settingsService.setChannelNotificationMode(
|
|
||||||
channel.muteKey,
|
|
||||||
ChannelNotificationMode.all,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// Mentions only
|
|
||||||
ListTile(
|
|
||||||
leading: const Icon(Icons.notification_important),
|
|
||||||
title: Text(sheetContext.l10n.channels_notifyMentionsOnly),
|
|
||||||
trailing: currentMode == ChannelNotificationMode.mentionsOnly
|
|
||||||
? const Icon(Icons.check)
|
|
||||||
: null,
|
|
||||||
onTap: () async {
|
|
||||||
Navigator.pop(sheetContext);
|
|
||||||
await settingsService.setChannelNotificationMode(
|
|
||||||
channel.muteKey,
|
|
||||||
ChannelNotificationMode.mentionsOnly,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
// Muted
|
|
||||||
ListTile(
|
|
||||||
leading: Icon(
|
|
||||||
Icons.notifications_off,
|
|
||||||
color: currentMode == ChannelNotificationMode.muted
|
|
||||||
? Theme.of(sheetContext).colorScheme.primary
|
|
||||||
: Theme.of(sheetContext).colorScheme.onSurfaceVariant,
|
|
||||||
),
|
|
||||||
title: Text(sheetContext.l10n.channels_notifyNone),
|
|
||||||
trailing: currentMode == ChannelNotificationMode.muted
|
|
||||||
? const Icon(Icons.check)
|
|
||||||
: null,
|
|
||||||
onTap: () async {
|
|
||||||
Navigator.pop(sheetContext);
|
|
||||||
await settingsService.setChannelNotificationMode(
|
|
||||||
channel.muteKey,
|
|
||||||
ChannelNotificationMode.muted,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handleQuickSwitch(int index, BuildContext context) {
|
void _handleQuickSwitch(int index, BuildContext context) {
|
||||||
if (index == 1) return;
|
if (index == 1) return;
|
||||||
switch (index) {
|
switch (index) {
|
||||||
|
|||||||
@@ -288,11 +288,6 @@ class AppSettingsService extends ChangeNotifier {
|
|||||||
await updateSettings(_settings.copyWith(unitSystem: value));
|
await updateSettings(_settings.copyWith(unitSystem: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Backward compatibility: delegates to AppSettings.isChannelMuted
|
|
||||||
bool isChannelMuted(String channelName) {
|
|
||||||
return _settings.isChannelMuted(channelName);
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelNotificationMode getChannelNotificationMode(String channelName) {
|
ChannelNotificationMode getChannelNotificationMode(String channelName) {
|
||||||
return _settings.channelNotificationModes[channelName] ??
|
return _settings.channelNotificationModes[channelName] ??
|
||||||
ChannelNotificationMode.all;
|
ChannelNotificationMode.all;
|
||||||
@@ -305,21 +300,14 @@ class AppSettingsService extends ChangeNotifier {
|
|||||||
final updated = Map<String, ChannelNotificationMode>.from(
|
final updated = Map<String, ChannelNotificationMode>.from(
|
||||||
_settings.channelNotificationModes,
|
_settings.channelNotificationModes,
|
||||||
);
|
);
|
||||||
updated[channelName] = mode;
|
if (mode == ChannelNotificationMode.all) {
|
||||||
|
updated.remove(channelName);
|
||||||
|
} else {
|
||||||
|
updated[channelName] = mode;
|
||||||
|
}
|
||||||
await updateSettings(_settings.copyWith(channelNotificationModes: updated));
|
await updateSettings(_settings.copyWith(channelNotificationModes: updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> muteChannel(String channelName) async {
|
|
||||||
await setChannelNotificationMode(
|
|
||||||
channelName,
|
|
||||||
ChannelNotificationMode.muted,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> unmuteChannel(String channelName) async {
|
|
||||||
await setChannelNotificationMode(channelName, ChannelNotificationMode.all);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> setTcpServerAddress(String value) async {
|
Future<void> setTcpServerAddress(String value) async {
|
||||||
await updateSettings(_settings.copyWith(tcpServerAddress: value));
|
await updateSettings(_settings.copyWith(tcpServerAddress: value));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<AppSettingsService>();
|
||||||
|
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,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -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,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -24,7 +24,10 @@ void main() {
|
|||||||
test('channel mutes made in review mode are undone on exit', () async {
|
test('channel mutes made in review mode are undone on exit', () async {
|
||||||
final settings = AppSettingsService();
|
final settings = AppSettingsService();
|
||||||
await settings.loadSettings();
|
await settings.loadSettings();
|
||||||
await settings.muteChannel('Hiking Group');
|
await settings.setChannelNotificationMode(
|
||||||
|
'Hiking Group',
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
final connector = MeshCoreConnector();
|
final connector = MeshCoreConnector();
|
||||||
addTearDown(connector.dispose);
|
addTearDown(connector.dispose);
|
||||||
final retryService = MessageRetryService();
|
final retryService = MessageRetryService();
|
||||||
@@ -39,23 +42,41 @@ void main() {
|
|||||||
|
|
||||||
await connector.connectReview();
|
await connector.connectReview();
|
||||||
// Mutes are keyed by channel name, so these would leak into real radios.
|
// Mutes are keyed by channel name, so these would leak into real radios.
|
||||||
await settings.muteChannel('Public');
|
await settings.setChannelNotificationMode(
|
||||||
await settings.unmuteChannel('Hiking Group');
|
'Public',
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
|
await settings.setChannelNotificationMode(
|
||||||
|
'Hiking Group',
|
||||||
|
ChannelNotificationMode.all,
|
||||||
|
);
|
||||||
// Other app preferences are the user's to change, even while reviewing.
|
// Other app preferences are the user's to change, even while reviewing.
|
||||||
await PrefsManager.instance.setString('unrelated_key', 'changed');
|
await PrefsManager.instance.setString('unrelated_key', 'changed');
|
||||||
|
|
||||||
await connector.disconnect(manual: true);
|
await connector.disconnect(manual: true);
|
||||||
|
|
||||||
expect(settings.isChannelMuted('Public'), isFalse);
|
expect(
|
||||||
expect(settings.isChannelMuted('Hiking Group'), isTrue);
|
settings.getChannelNotificationMode('Public'),
|
||||||
|
ChannelNotificationMode.all,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
settings.getChannelNotificationMode('Hiking Group'),
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
expect(PrefsManager.instance.getString('unrelated_key'), 'changed');
|
expect(PrefsManager.instance.getString('unrelated_key'), 'changed');
|
||||||
|
|
||||||
// A fresh launch has nothing left to undo.
|
// A fresh launch has nothing left to undo.
|
||||||
final relaunched = AppSettingsService();
|
final relaunched = AppSettingsService();
|
||||||
await relaunched.loadSettings();
|
await relaunched.loadSettings();
|
||||||
await endReviewModeSession(relaunched);
|
await endReviewModeSession(relaunched);
|
||||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
expect(
|
||||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
relaunched.getChannelNotificationMode('Public'),
|
||||||
|
ChannelNotificationMode.all,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
@@ -63,11 +84,20 @@ void main() {
|
|||||||
() async {
|
() async {
|
||||||
final settings = AppSettingsService();
|
final settings = AppSettingsService();
|
||||||
await settings.loadSettings();
|
await settings.loadSettings();
|
||||||
await settings.muteChannel('Hiking Group');
|
await settings.setChannelNotificationMode(
|
||||||
|
'Hiking Group',
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
|
|
||||||
await beginReviewModeSession(settings);
|
await beginReviewModeSession(settings);
|
||||||
await settings.muteChannel('Public');
|
await settings.setChannelNotificationMode(
|
||||||
await settings.unmuteChannel('Hiking Group');
|
'Public',
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
|
await settings.setChannelNotificationMode(
|
||||||
|
'Hiking Group',
|
||||||
|
ChannelNotificationMode.all,
|
||||||
|
);
|
||||||
await PrefsManager.instance.setString(
|
await PrefsManager.instance.setString(
|
||||||
'contacts${ReviewRadio.storagePrefix}',
|
'contacts${ReviewRadio.storagePrefix}',
|
||||||
'[]',
|
'[]',
|
||||||
@@ -76,11 +106,20 @@ void main() {
|
|||||||
|
|
||||||
final relaunched = AppSettingsService();
|
final relaunched = AppSettingsService();
|
||||||
await relaunched.loadSettings();
|
await relaunched.loadSettings();
|
||||||
expect(relaunched.isChannelMuted('Public'), isTrue);
|
expect(
|
||||||
|
relaunched.getChannelNotificationMode('Public'),
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
await endReviewModeSession(relaunched);
|
await endReviewModeSession(relaunched);
|
||||||
|
|
||||||
expect(relaunched.isChannelMuted('Public'), isFalse);
|
expect(
|
||||||
expect(relaunched.isChannelMuted('Hiking Group'), isTrue);
|
relaunched.getChannelNotificationMode('Public'),
|
||||||
|
ChannelNotificationMode.all,
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
relaunched.getChannelNotificationMode('Hiking Group'),
|
||||||
|
ChannelNotificationMode.muted,
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
PrefsManager.instance.getKeys().where(
|
PrefsManager.instance.getKeys().where(
|
||||||
(k) => k.contains(ReviewRadio.storagePrefix),
|
(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 {
|
test('the review scope never adopts legacy unscoped data', () async {
|
||||||
await PrefsManager.instance.setString('contacts', '[]');
|
await PrefsManager.instance.setString('contacts', '[]');
|
||||||
await beginReviewModeSession(null);
|
await beginReviewModeSession(null);
|
||||||
|
|||||||
+69
-1
@@ -1 +1,69 @@
|
|||||||
{}
|
{
|
||||||
|
"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"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in new issue
Block a user