feat: Implement clear chat, delete conversation, mute, and report options within the chat screen.
This commit is contained in:
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user