📄 Source: switch_chat.php
<?php
session_start();
require_once 'database.php';
header('Content-Type: application/json');
if (!isset($_SESSION['access_token'])) {
echo json_encode(['error' => 'Not authenticated']);
exit();
}
$input = json_decode(file_get_contents('php://input'), true);
$chatId = $input['chat_id'] ?? 0;
if ($chatId) {
$_SESSION['current_conversation_id'] = $chatId;
$db = new ChatDatabase();
$messages = $db->getMessages($chatId);
echo json_encode(['success' => true, 'messages' => $messages, 'chat_id' => $chatId]);
} else {
echo json_encode(['error' => 'Invalid chat ID']);
}
?>
← Back