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
@@ -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';
|
||||
@@ -403,19 +404,64 @@ class _ChannelChatScreenState extends State<ChannelChatScreen> {
|
||||
Consumer<AppSettingsService>(
|
||||
builder: (context, settings, _) {
|
||||
final muteKey = widget.channel.muteKey;
|
||||
final muted = settings.isChannelMuted(muteKey);
|
||||
return IconButton(
|
||||
tooltip: muted
|
||||
? context.l10n.channels_unmuteChannel
|
||||
: context.l10n.channels_muteChannel,
|
||||
final notificationMode = settings.getChannelNotificationMode(
|
||||
muteKey,
|
||||
);
|
||||
return PopupMenuButton<ChannelNotificationMode>(
|
||||
tooltip: context.l10n.channels_notificationSettings,
|
||||
icon: Icon(
|
||||
muted
|
||||
notificationMode == ChannelNotificationMode.muted
|
||||
? Icons.notifications_off_outlined
|
||||
: notificationMode == ChannelNotificationMode.mentionsOnly
|
||||
? Icons.alternate_email
|
||||
: Icons.notifications_outlined,
|
||||
),
|
||||
onPressed: () => muted
|
||||
? settings.unmuteChannel(muteKey)
|
||||
: settings.muteChannel(muteKey),
|
||||
onSelected: (mode) {
|
||||
settings.setChannelNotificationMode(muteKey, mode);
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
PopupMenuItem(
|
||||
value: ChannelNotificationMode.all,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications_active,
|
||||
color: notificationMode == ChannelNotificationMode.all
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.channels_notifyAll),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: ChannelNotificationMode.mentionsOnly,
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.alternate_email),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.channels_notifyMentionsOnly),
|
||||
],
|
||||
),
|
||||
),
|
||||
PopupMenuItem(
|
||||
value: ChannelNotificationMode.muted,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.notifications_off,
|
||||
color:
|
||||
notificationMode == ChannelNotificationMode.muted
|
||||
? Theme.of(context).colorScheme.primary
|
||||
: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(context.l10n.channels_notifyNone),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -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';
|
||||
@@ -372,9 +373,9 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
int listIndex = 0,
|
||||
}) {
|
||||
final unreadCount = connector.getUnreadCountForChannel(channel);
|
||||
final isMuted = context.watch<AppSettingsService>().isChannelMuted(
|
||||
channel.muteKey,
|
||||
);
|
||||
final notificationMode = context
|
||||
.watch<AppSettingsService>()
|
||||
.getChannelNotificationMode(channel.muteKey);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
|
||||
// Determine icon and colors based on channel type
|
||||
@@ -580,9 +581,11 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isMuted) ...[
|
||||
if (notificationMode != ChannelNotificationMode.all) ...[
|
||||
Icon(
|
||||
Icons.notifications_off,
|
||||
notificationMode == ChannelNotificationMode.muted
|
||||
? Icons.notifications_off
|
||||
: Icons.alternate_email,
|
||||
size: 18,
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
@@ -625,8 +628,6 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
Channel channel,
|
||||
) {
|
||||
final parentContext = context;
|
||||
final settingsService = context.read<AppSettingsService>();
|
||||
final isMuted = settingsService.isChannelMuted(channel.muteKey);
|
||||
|
||||
showMeshSheet(
|
||||
parentContext,
|
||||
@@ -645,24 +646,14 @@ class _ChannelsScreenState extends State<ChannelsScreen>
|
||||
}
|
||||
},
|
||||
),
|
||||
// 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,
|
||||
),
|
||||
onTap: () async {
|
||||
leading: const Icon(Icons.notifications_outlined),
|
||||
title: Text(sheetContext.l10n.channels_notificationSettings),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.pop(sheetContext);
|
||||
if (isMuted) {
|
||||
await settingsService.unmuteChannel(channel.muteKey);
|
||||
} else {
|
||||
await settingsService.muteChannel(channel.muteKey);
|
||||
}
|
||||
_showNotificationModeDialog(sheetContext, connector, channel);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
@@ -690,6 +681,83 @@ 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_active,
|
||||
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.alternate_email),
|
||||
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) {
|
||||
if (index == 1) return;
|
||||
switch (index) {
|
||||
|
||||
Reference in new issue
Block a user