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

@@ -569,6 +569,55 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
state = state.copyWith(error: 'Failed to delete conversation');
}
}
Future<void> toggleMute(String conversationId, bool muted) async {
try {
await _repository.toggleMute(conversationId, muted);
final currentUserId = _ref.read(currentUserIdProvider);
final updatedConversations = state.conversations.map((c) {
if (c.id == conversationId) {
final isUser = c.userId == currentUserId;
return isUser
? c.copyWith(userMuted: muted)
: c.copyWith(agentMuted: muted);
}
return c;
}).toList();
state = state.copyWith(conversations: updatedConversations);
} catch (_) {
state = state.copyWith(error: 'Failed to toggle mute');
}
}
Future<void> toggleFavorite(String conversationId, bool favorited) async {
try {
await _repository.toggleFavorite(conversationId, favorited);
final currentUserId = _ref.read(currentUserIdProvider);
var updatedConversations = state.conversations.map((c) {
if (c.id == conversationId) {
final isUser = c.userId == currentUserId;
return isUser
? c.copyWith(userFavorited: favorited)
: c.copyWith(agentFavorited: favorited);
}
return c;
}).toList();
// Sort: favorites first, then by lastMessageAt
updatedConversations.sort((a, b) {
final aFav = a.userId == currentUserId ? a.userFavorited : a.agentFavorited;
final bFav = b.userId == currentUserId ? b.userFavorited : b.agentFavorited;
if (aFav != bFav) {
return aFav ? -1 : 1;
}
final aTime = a.lastMessageAt ?? '';
final bTime = b.lastMessageAt ?? '';
return bTime.compareTo(aTime);
});
state = state.copyWith(conversations: updatedConversations);
} catch (_) {
state = state.copyWith(error: 'Failed to toggle favorite');
}
}
}
final messagingProvider =