📄 Source: delete_chat.php
<?php
session_start();
require_once 'database.php';
header('Content-Type: application/json');
$input = json_decode(file_get_contents('php://input'), true);
$chatId = $input['chat_id'] ?? 0;
if ($chatId) {
$db = new ChatDatabase();
$db->deleteConversation($chatId);
if (isset($_SESSION['current_conversation_id']) && $_SESSION['current_conversation_id'] == $chatId) {
// Create a new conversation for the user
$userEmail = $_SESSION['user_email'] ?? 'guest_' . session_id();
$newChatId = $db->createConversation($userEmail);
$_SESSION['current_conversation_id'] = $newChatId;
}
echo json_encode(['success' => true]);
} else {
echo json_encode(['error' => 'Invalid chat ID']);
}
?>
← Back