prepare(" SELECT s.* FROM servers s JOIN server_members sm ON s.id = sm.server_id WHERE sm.user_id = ? LIMIT 20 "); $stmt->execute([$current_user_id]); $servers = $stmt->fetchAll(); $active_server_id = $_GET['server_id'] ?? ($servers[0]['id'] ?? 1); // If no servers found, we might want to show a default or an empty state // For now, let's assume the seed data or the first server works // Fetch channels $stmt = db()->prepare("SELECT * FROM channels WHERE server_id = ?"); $stmt->execute([$active_server_id]); $channels = $stmt->fetchAll(); $active_channel_id = $_GET['channel_id'] ?? ($channels[0]['id'] ?? 1); // Fetch messages $stmt = db()->prepare(" SELECT m.*, u.username, u.avatar_url FROM messages m JOIN users u ON m.user_id = u.id WHERE m.channel_id = ? ORDER BY m.created_at ASC LIMIT 50 "); $stmt->execute([$active_channel_id]); $messages = $stmt->fetchAll(); $current_channel_name = 'general'; foreach($channels as $c) if($c['id'] == $active_channel_id) $current_channel_name = $c['name']; // Fetch members $stmt = db()->prepare(" SELECT u.username, u.avatar_url, u.status FROM users u JOIN server_members sm ON u.id = sm.user_id WHERE sm.server_id = ? "); $stmt->execute([$active_server_id]); $members = $stmt->fetchAll(); // SEO & Env tags $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Discord-like messaging app built with PHP'; $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; ?>