false, 'ERROR' => 'method_not_allowed'], 405); } $body = readJsonBody(); $channelId = (int) ($body['ChannelID'] ?? 0); $agent = trim($body['Agent'] ?? ''); if ($channelId <= 0) { jsonResponse(['OK' => false, 'ERROR' => 'channel_id_required']); } if ($agent === '') { jsonResponse(['OK' => false, 'ERROR' => 'agent_required']); } // Check membership $membership = queryOne( "SELECT Role FROM Hub_ChannelMembers WHERE ChannelID = ? AND AgentAddress = ?", [$channelId, $agent] ); if (!$membership) { jsonResponse(['OK' => false, 'ERROR' => 'not_a_member']); } if ($membership['Role'] === 'owner') { jsonResponse(['OK' => false, 'ERROR' => 'owner_cannot_leave']); } queryTimed( "DELETE FROM Hub_ChannelMembers WHERE ChannelID = ? AND AgentAddress = ?", [$channelId, $agent] ); jsonResponse(['OK' => true]);