Use new method to get likes
This commit is contained in:
@@ -7,7 +7,7 @@ $post = getPostData();
|
|||||||
$targetId = (int)$post['targetId'] ?? 0;
|
$targetId = (int)$post['targetId'] ?? 0;
|
||||||
|
|
||||||
$stmt = $conn->prepare("
|
$stmt = $conn->prepare("
|
||||||
SELECT id, content, timestamp, likes, userId
|
SELECT id, content, timestamp, votes, userId
|
||||||
FROM userposts
|
FROM userposts
|
||||||
WHERE userId = ? AND deleted_at = 0
|
WHERE userId = ? AND deleted_at = 0
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
@@ -17,13 +17,18 @@ $stmt->execute();
|
|||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
echo encrypt(json_encode(array_map(
|
echo encrypt(json_encode(array_map(
|
||||||
fn($row) => [
|
function ($row) {
|
||||||
|
$votes = json_decode($row['votes'], true);
|
||||||
|
$likes = is_array($votes) ? array_sum(array_map(fn($v) => $v === true ? 1 : -1, $votes)) : 0;
|
||||||
|
|
||||||
|
return [
|
||||||
'id' => $row['id'],
|
'id' => $row['id'],
|
||||||
'userId' => $row['userId'],
|
'userId' => $row['userId'],
|
||||||
'content' => $row['content'],
|
'content' => $row['content'],
|
||||||
'timestamp' => genTimestamp($row['timestamp']) . " ago",
|
'timestamp' => genTimestamp($row['timestamp']) . " ago",
|
||||||
'likes' => $row['likes']
|
'likes' => $likes
|
||||||
],
|
];
|
||||||
|
},
|
||||||
$result->fetch_all(MYSQLI_ASSOC)
|
$result->fetch_all(MYSQLI_ASSOC)
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user