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
@@ -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<String, String> batteryChemistryByDeviceId;
|
||||
final Map<String, String> batteryChemistryByRepeaterId;
|
||||
final UnitSystem unitSystem;
|
||||
final Set<String> mutedChannels;
|
||||
final Map<String, ChannelNotificationMode> channelNotificationModes;
|
||||
final bool mapShowDiscoveryContacts;
|
||||
final bool evictDiscoveredContactsEnabled;
|
||||
final String tcpServerAddress;
|
||||
@@ -196,6 +198,12 @@ class AppSettings {
|
||||
return profile.charMap;
|
||||
}
|
||||
|
||||
// Backward compatibility: returns true if channel is muted (mode == muted)
|
||||
bool isChannelMuted(String channelName) {
|
||||
return channelNotificationModes[channelName] ==
|
||||
ChannelNotificationMode.muted;
|
||||
}
|
||||
|
||||
AppSettings({
|
||||
this.clearPathOnMaxRetry = false,
|
||||
this.mapShowRepeaters = true,
|
||||
@@ -238,7 +246,7 @@ class AppSettings {
|
||||
Map<String, String>? batteryChemistryByDeviceId,
|
||||
Map<String, String>? batteryChemistryByRepeaterId,
|
||||
this.unitSystem = UnitSystem.metric,
|
||||
Set<String>? mutedChannels,
|
||||
Map<String, ChannelNotificationMode>? channelNotificationModes,
|
||||
this.mapShowDiscoveryContacts = true,
|
||||
this.evictDiscoveredContactsEnabled = true,
|
||||
this.tcpServerAddress = '',
|
||||
@@ -264,7 +272,7 @@ class AppSettings {
|
||||
String? selectedCyr2latProfileId,
|
||||
}) : batteryChemistryByDeviceId = batteryChemistryByDeviceId ?? {},
|
||||
batteryChemistryByRepeaterId = batteryChemistryByRepeaterId ?? {},
|
||||
mutedChannels = mutedChannels ?? {},
|
||||
channelNotificationModes = channelNotificationModes ?? {},
|
||||
imageCodecDownloadedModels = imageCodecDownloadedModels ?? const [],
|
||||
translationDownloadedModels = translationDownloadedModels ?? const [],
|
||||
cyr2latProfiles =
|
||||
@@ -322,7 +330,9 @@ class AppSettings {
|
||||
'battery_chemistry_by_device_id': batteryChemistryByDeviceId,
|
||||
'battery_chemistry_by_repeater_id': batteryChemistryByRepeaterId,
|
||||
'unit_system': unitSystem.value,
|
||||
'muted_channels': mutedChannels.toList(),
|
||||
'channel_notification_modes': channelNotificationModes.map(
|
||||
(key, value) => MapEntry(key, value.index),
|
||||
),
|
||||
'map_show_discovery_contacts': mapShowDiscoveryContacts,
|
||||
'evict_discovered_contacts_enabled': evictDiscoveredContactsEnabled,
|
||||
'tcp_server_address': tcpServerAddress,
|
||||
@@ -363,6 +373,38 @@ class AppSettings {
|
||||
return UnitSystem.metric;
|
||||
}
|
||||
|
||||
Map<String, ChannelNotificationMode> parseChannelNotificationModes(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
// Migration from old muted_channels (Set<String>) to new system
|
||||
final mutedList = json['muted_channels'] as List?;
|
||||
final newModes = json['channel_notification_modes'] as Map?;
|
||||
|
||||
final result = <String, ChannelNotificationMode>{};
|
||||
|
||||
// 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 channelName = entry.key;
|
||||
final modeIndex = entry.value as int?;
|
||||
if (modeIndex != null &&
|
||||
modeIndex >= 0 &&
|
||||
modeIndex < ChannelNotificationMode.values.length) {
|
||||
result[channelName] = ChannelNotificationMode.values[modeIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return AppSettings(
|
||||
clearPathOnMaxRetry: json['clear_path_on_max_retry'] as bool? ?? false,
|
||||
mapShowRepeaters: json['map_show_repeaters'] as bool? ?? true,
|
||||
@@ -425,11 +467,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 +592,7 @@ class AppSettings {
|
||||
Map<String, String>? batteryChemistryByDeviceId,
|
||||
Map<String, String>? batteryChemistryByRepeaterId,
|
||||
UnitSystem? unitSystem,
|
||||
Set<String>? mutedChannels,
|
||||
Map<String, ChannelNotificationMode>? channelNotificationModes,
|
||||
bool? mapShowDiscoveryContacts,
|
||||
bool? evictDiscoveredContactsEnabled,
|
||||
String? tcpServerAddress,
|
||||
@@ -639,7 +677,8 @@ class AppSettings {
|
||||
batteryChemistryByRepeaterId:
|
||||
batteryChemistryByRepeaterId ?? this.batteryChemistryByRepeaterId,
|
||||
unitSystem: unitSystem ?? this.unitSystem,
|
||||
mutedChannels: mutedChannels ?? this.mutedChannels,
|
||||
channelNotificationModes:
|
||||
channelNotificationModes ?? this.channelNotificationModes,
|
||||
mapShowDiscoveryContacts:
|
||||
mapShowDiscoveryContacts ?? this.mapShowDiscoveryContacts,
|
||||
evictDiscoveredContactsEnabled:
|
||||
|
||||
Reference in new issue
Block a user