feat: add per-channel notification modes (all/mentions only/muted)
- Add ChannelNotificationMode enum with all, mentionsOnly, muted options - Replace mutedChannels Set with channelNotificationModes Map for per-channel settings - Add mention detection for @username in channel messages - Update channels list and chat UI with notification mode selector - Add localization strings for new notification modes - Automatic migration from old mutedChannels to new system - Update user documentation - Preserve backward compatibility with existing mute/unmute API
This commit is contained in:
1 parent
caee4d5c19
commit
caad3dd703
29 files changed
+647
-66
No files matched your search
@@ -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';
|
||||
@@ -7353,7 +7354,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 =
|
||||
@@ -7362,6 +7368,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
translationResult.translatedText.trim().isNotEmpty)
|
||||
? translationResult.translatedText.trim()
|
||||
: message.text.trim();
|
||||
|
||||
// If mode is mentionsOnly, check if message mentions us
|
||||
if (notificationMode == ChannelNotificationMode.mentionsOnly) {
|
||||
if (!_doesMessageMentionUs(resolvedText)) return;
|
||||
}
|
||||
|
||||
unawaited(() async {
|
||||
await _notificationService.showChannelMessageNotification(
|
||||
channelName: label,
|
||||
@@ -7374,6 +7386,22 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}());
|
||||
}
|
||||
|
||||
/// Checks if a message text mentions the current user.
|
||||
/// Looks for "@username" pattern where username matches our self name.
|
||||
bool _doesMessageMentionUs(String messageText) {
|
||||
final selfName = _selfName;
|
||||
if (selfName == null || selfName.isEmpty) return false;
|
||||
|
||||
// Check for @username at word boundaries (start of message or after whitespace)
|
||||
// Case-insensitive comparison
|
||||
final lowerSelfName = selfName.toLowerCase();
|
||||
final lowerMessage = messageText.toLowerCase();
|
||||
final mentionPattern = RegExp(
|
||||
r'\b@(' + RegExp.escape(lowerSelfName) + r')\b',
|
||||
);
|
||||
return mentionPattern.hasMatch(lowerMessage);
|
||||
}
|
||||
|
||||
/// Handles RESP_CODE_CHANNEL_DATA_RECV (GRP_DATA). Frames whose dataType is
|
||||
/// not 0xAE1C — or that arrive before an [ImageChunkTransport] is installed —
|
||||
/// are ignored without disturbing any other behaviour.
|
||||
|
||||
Reference in new issue
Block a user