feat: Implement conversation mute and favorite features with UI integration and state management.

This commit is contained in:
pradeepkumar
2026-03-19 17:03:44 +05:30
parent 32ec839016
commit 858c912df9
4 changed files with 121 additions and 3 deletions

View File

@@ -45,6 +45,17 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
notifier.setActiveConversation(widget.conversationId);
notifier.loadMessages(widget.conversationId);
notifier.markAsRead(widget.conversationId);
// Initialize mute/star state from conversation data
final conversations = ref.read(messagingProvider).conversations;
final conv = conversations.where((c) => c.id == widget.conversationId).firstOrNull;
if (conv != null) {
final currentUserId = ref.read(currentUserIdProvider);
final isUser = conv.userId == currentUserId;
setState(() {
_isMuted = isUser ? conv.userMuted : conv.agentMuted;
_isStarred = isUser ? conv.userFavorited : conv.agentFavorited;
});
}
// Suppress push notifications for this conversation while viewing
PushNotificationService().activeConversationId = widget.conversationId;
// Ensure socket is connected and join room for real-time updates
@@ -159,10 +170,12 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
);
break;
case 'mute':
setState(() => _isMuted = !_isMuted);
final newMuted = !_isMuted;
setState(() => _isMuted = newMuted);
ref.read(messagingProvider.notifier).toggleMute(widget.conversationId, newMuted);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(_isMuted ? 'Notifications muted' : 'Notifications unmuted'),
content: Text(newMuted ? 'Notifications muted' : 'Notifications unmuted'),
duration: const Duration(seconds: 2),
),
);
@@ -540,7 +553,11 @@ class _ChatScreenState extends ConsumerState<ChatScreen>
),
// Star icon
GestureDetector(
onTap: () => setState(() => _isStarred = !_isStarred),
onTap: () {
final newStarred = !_isStarred;
setState(() => _isStarred = newStarred);
ref.read(messagingProvider.notifier).toggleFavorite(widget.conversationId, newStarred);
},
child: Padding(
padding: const EdgeInsets.only(right: 4),
child: Icon(