Update get_user_messages.php

This commit is contained in:
Lizandro Guarnizo
2026-01-24 08:32:50 -05:00
parent 04857c773d
commit e695a61af9
+16 -1
View File
@@ -75,7 +75,22 @@ try {
$conversations = $db->fetchAll($sql, $params);
// Si no hay mensajes, devolver array vacío
// Si no hay mensajes, intentar fallback si se pidió paginación con 'before'
if (empty($conversations) && $before) {
error_log('get_user_messages.php - initial query returned empty, attempting fallback with inclusive <= for before param');
try {
$sqlFallback = str_replace('c.created_at < :before', 'c.created_at <= :before', $sql);
$conversationsFallback = $db->fetchAll($sqlFallback, $params);
if (!empty($conversationsFallback)) {
error_log('get_user_messages.php - fallback query returned ' . count($conversationsFallback) . ' rows');
$conversations = $conversationsFallback;
}
} catch (Exception $e) {
error_log('get_user_messages.php - fallback query failed: ' . $e->getMessage());
}
}
// Si todavía no hay mensajes, devolver array vacío
if (empty($conversations)) {
echo json_encode(['success' => true, 'data' => [], 'has_more' => false], JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR);
exit;