false, 'ERROR' => 'method_not_allowed'], 405); } $messageId = (int) ($_GET['MessageID'] ?? 0); if ($messageId <= 0) jsonResponse(['OK' => false, 'ERROR' => 'message_id_required']); $root = queryOne("SELECT * FROM Hub_Messages WHERE ID = ? AND IsDeleted = 0", [$messageId]); if (!$root) jsonResponse(['OK' => false, 'ERROR' => 'message_not_found']); $replies = queryTimed( "SELECT * FROM Hub_Messages WHERE ParentID = ? AND IsDeleted = 0 ORDER BY CreatedAt ASC", [$messageId] ); $formatMsg = function (array $row): array { return [ 'ID' => (int) $row['ID'], 'ChannelID' => (int) $row['ChannelID'], 'SenderAddress' => $row['SenderAddress'], 'Content' => $row['Content'], 'ParentID' => $row['ParentID'] ? (int) $row['ParentID'] : null, 'IsEdited' => (bool) $row['IsEdited'], 'CreatedAt' => toISO8601($row['CreatedAt']), 'UpdatedAt' => toISO8601($row['UpdatedAt']), ]; }; jsonResponse([ 'OK' => true, 'RootMessage' => $formatMsg($root), 'Replies' => array_map($formatMsg, $replies), 'ReplyCount' => count($replies), ]);