feat: Implement clear chat, delete conversation, mute, and report options within the chat screen.

This commit is contained in:
pradeepkumar
2026-03-19 13:57:14 +05:30
parent b848b0260b
commit a837e5ac12
5 changed files with 217 additions and 23 deletions

View File

@@ -527,6 +527,48 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
return null;
}
}
Future<void> clearChat(String conversationId) async {
try {
await _repository.clearChat(conversationId);
// Clear local messages
final updatedMessages =
Map<String, List<ChatMessage>>.from(state.messages)
..[conversationId] = [];
// Update conversation preview
final updatedConversations = state.conversations.map((c) {
if (c.id == conversationId) {
return c.copyWith(lastMessageText: '', unreadCount: 0);
}
return c;
}).toList();
state = state.copyWith(
messages: updatedMessages,
conversations: updatedConversations,
);
} catch (_) {
state = state.copyWith(error: 'Failed to clear chat');
}
}
Future<void> deleteConversation(String conversationId) async {
try {
await _repository.deleteConversation(conversationId);
// Remove from local state
final updatedMessages =
Map<String, List<ChatMessage>>.from(state.messages)
..remove(conversationId);
final updatedConversations =
state.conversations.where((c) => c.id != conversationId).toList();
state = state.copyWith(
messages: updatedMessages,
conversations: updatedConversations,
clearActiveConversation: true,
);
} catch (_) {
state = state.copyWith(error: 'Failed to delete conversation');
}
}
}
final messagingProvider =