diff --git a/database/deleteChatroomMessage.php b/database/deleteChatroomMessage.php new file mode 100644 index 0000000..46f6c9f --- /dev/null +++ b/database/deleteChatroomMessage.php @@ -0,0 +1,29 @@ +prepare("SELECT * FROM users WHERE token = ? AND username = ?"); +$stmt->bind_param("ss", $token, $username); +$stmt->execute(); +$result = $stmt->get_result(); +$row = $result->fetch_assoc(); +if (!$row) exit; +$stmt->close(); + +$user_id = $row["id"]; +$time = time(); + +$stmt = $conn->prepare("UPDATE chats SET deleted_at = ? WHERE userId = ? AND id = ?"); +$stmt->bind_param("iii", $time, $user_id, $id); +$stmt->execute(); +$stmt->close(); + +$conn->close(); \ No newline at end of file diff --git a/database/getChatroomMessages.php b/database/getChatroomMessages.php index ea7ebab..9172338 100644 --- a/database/getChatroomMessages.php +++ b/database/getChatroomMessages.php @@ -5,15 +5,15 @@ checkClientDatabaseVersion(); $conn = newConnection(); $stmt = $conn->prepare(" - SELECT c.id AS chat_id, c.content, u.username, u.icon, u.overlay, u.id AS user_id, u.birdColor, u.overlayColor + SELECT c.id AS chat_id, c.content, u.username, u.icon, u.overlay, u.id AS user_id, u.birdColor, u.overlayColor, c.deleted_at FROM chats c JOIN users u ON c.userId = u.id - WHERE u.banned = 0 AND c.deleted = 0 + WHERE u.banned = 0 ORDER BY c.id DESC LIMIT 50 "); $stmt->execute(); $result = $stmt->get_result(); -echo encrypt(json_encode(array_reverse(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['user_id'], 'content' => $row['content'], 'id' => $row['chat_id'], 'icon' => $row['icon'], 'overlay' => $row['overlay'], 'birdColor' => json_decode($row['birdColor']), 'overlayColor' => json_decode($row['overlayColor'])], $result->fetch_all(MYSQLI_ASSOC))))); +echo encrypt(json_encode(array_reverse(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['user_id'], 'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null, 'deleted' => (int)$row['deleted_at'] != 0, 'id' => $row['chat_id'], 'icon' => $row['icon'], 'overlay' => $row['overlay'], 'birdColor' => json_decode($row['birdColor']), 'overlayColor' => json_decode($row['overlayColor'])], $result->fetch_all(MYSQLI_ASSOC))))); $conn->close(); \ No newline at end of file diff --git a/database/getChatroomMessagesAPI.php b/database/getChatroomMessagesAPI.php index 9f7fad8..bd7fb6f 100644 --- a/database/getChatroomMessagesAPI.php +++ b/database/getChatroomMessagesAPI.php @@ -7,7 +7,7 @@ $stmt = $conn->prepare(" SELECT c.id, c.content, u.username FROM chats c JOIN users u ON c.userId = u.id - WHERE u.banned = 0 AND c.deleted = 0 + WHERE u.banned = 0 AND c.deleted_at = 0 ORDER BY c.id ASC LIMIT 50 "); $stmt->execute();