connect('127.0.0.1', 6379); $parentPostId = htmlspecialchars(trim($postData['postId'])); $userid = 'guest'; $commentListKey = "dbcomments:$parentPostId"; $commentIds = $redis->lrange($commentListKey, 0, -1); $posts = []; $adminReplies = []; foreach ($commentIds as $commentId) { // === Fetch comment === $commentJson = $redis->get("posts:$commentId"); $comment = json_decode($commentJson, true); if ($comment) { $likesKey = "likes:$commentId"; $likesCount = $redis->get($likesKey); $commentlikedkeys = "likedby:$commentId"; $allLikedBy = $redis->lrange($commentlikedkeys, 0, -1); $userliked = in_array($userid, $allLikedBy) ? 'yes' : 'no'; $media = []; if (!empty($comment['mediaurl'])) { $decoded = json_decode($comment['mediaurl'], true); if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { $media = $decoded; } } $posts[] = [ 'id' => $comment['id'], 'accountId' => (int)($comment['accountId'] ?? 0), 'username' => $comment['username'] ?? 'guest', 'content' => $comment['content'] ?? '', 'media' => $media, 'audiofilename' => $comment['audiofilename'] ?? '', 'originals' => $comment['originals'] ?? [], 'hashtags' => $comment['hashtags'] ?? [], 'niche' => $comment['niche'] ?? '', 'ip' => $comment['ip'] ?? '', 'replyingto' => $comment['replyingto'] ?? '', 'mainparentpostid' => $comment['mainparentpostid'] ?? '', 'userAgent' => $comment['userAgent'] ?? '', 'postId' => $comment['postId'] ?? $commentId, 'likes' => $likesCount !== false ? (int)$likesCount : 0, 'comments' => $comment['comments'] ?? 0, 'shares' => $comment['shares'] ?? 0, 'viewType' => $comment['viewType'] ?? 'organic', 'svd' => $comment['svd'] ?? 'no', 'bookmarks' => $comment['bookmarks'] ?? 0, 'mutestatus' => $comment['mutestatus'] ?? 'no', 'following' => $comment['following'] ?? 'no', 'notintrested' => $comment['notintrested'] ?? 'no', 'shlink' => $comment['shlink'] ?? 'https://voidvenus.online/sharelink', 'blockedstatus' => $comment['blockedstatus'] ?? 'no', 'adminreply' => $comment['adminreply'] ?? '', 'potentialImpressions' => (int)($comment['potentialImpressions'] ?? 0), 'impressions' => (int)($comment['impressions'] ?? 0), 'liked' => $userliked, 'nsfw' => $comment['nsfw'] ?? 'no', ]; } // === Fetch all admin replies for this comment === $adminThreadKey = "adminreplythread:$commentId"; $adminReplyIds = $redis->lrange($adminThreadKey, 0, -1); foreach ($adminReplyIds as $adminPostId) { $adminJson = $redis->get("posts:$adminPostId"); if (!$adminJson) continue; $adminReply = json_decode($adminJson, true); $media = []; if (!empty($adminReply['mediaurl'])) { $decoded = json_decode($adminReply['mediaurl'], true); if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { $media = $decoded; } } $adminReplies[] = [ 'id' => $adminReply['id'], 'accountId' => (int)($adminReply['accountId'] ?? 0), 'username' => $adminReply['username'] ?? 'admin', 'content' => $adminReply['content'] ?? '', 'media' => $media, 'audiofilename' => $adminReply['audiofilename'] ?? '', 'originals' => $adminReply['originals'] ?? [], 'hashtags' => $adminReply['hashtags'] ?? [], 'niche' => $adminReply['niche'] ?? '', 'ip' => $adminReply['ip'] ?? '', 'replyingto' => $adminReply['replyingto'] ?? '', 'mainparentpostid' => $adminReply['mainparentpostid'] ?? '', 'userAgent' => $adminReply['userAgent'] ?? '', 'postId' => $adminReply['postId'] ?? '', 'likes' => 0, 'comments' => 0, 'shares' => 0, 'viewType' => $adminReply['viewType'] ?? 'organic', 'svd' => $adminReply['svd'] ?? 'no', 'bookmarks' => $adminReply['bookmarks'] ?? 0, 'mutestatus' => $adminReply['mutestatus'] ?? 'no', 'following' => $adminReply['following'] ?? 'no', 'notintrested' => $adminReply['notintrested'] ?? 'no', 'shlink' => $adminReply['shlink'] ?? 'https://voidvenus.online/sharelink', 'blockedstatus' => $adminReply['blockedstatus'] ?? 'no', 'adminreply' => $adminReply['adminreply'] ?? '', 'potentialImpressions' => 0, 'impressions' => 0, 'liked' => 'no', 'nsfw' => $adminReply['nsfw'] ?? 'no', ]; } } echo json_encode([ 'status' => 'success', 'posts' => $posts, 'adminReplies' => $adminReplies ]); } ?>