From 38237eaf13e1109d74c2a79b9df40ec5c86f5ef3 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Sat, 24 Jan 2026 09:17:54 -0500 Subject: [PATCH] Update conversations.php --- conversations.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/conversations.php b/conversations.php index 6f57b13..f14a539 100644 --- a/conversations.php +++ b/conversations.php @@ -2091,6 +2091,8 @@ } try { + console.debug('loadMessages called', { userId, initial, earliestMessage: this.earliestMessage, earliestMessageId: this.earliestMessageId, currentCount: this.conversations ? this.conversations.length : 0 }); + let url = `get_user_messages.php?user_id=${userId}&limit=${this.messageLimit}`; if (!initial && this.earliestMessage) { url += `&before=${encodeURIComponent(this.earliestMessage)}`; @@ -2139,6 +2141,14 @@ } } + // Si estamos en carga inicial y el servidor devolvió array vacío, pero ya teníamos mensajes en la vista, + // *no* reemplazaremos el arreglo existente (evita borrar la conversación por un fallo temporal del API). + if (initial && Array.isArray(messages) && messages.length === 0 && Array.isArray(this.conversations) && this.conversations.length > 0) { + console.warn('Initial load returned empty but existing view contains messages - preserving current conversation'); + if (typeof showAlert === 'function') showAlert('No se pudieron recargar mensajes; manteniendo historial actual', 'warning'); + return; + } + // Guard: cuando paginamos (initial=false) y la respuesta no trae mensajes, // no reemplazar ni limpiar la conversación actual; solo indicar que no hay más. if (!initial && Array.isArray(messages) && messages.length === 0) { @@ -2176,6 +2186,22 @@ this.conversations = messages.concat(this.conversations); } + // Limpieza: eliminar mensajes vacíos persistentes en la vista (text vacíos sin media) + try { + if (Array.isArray(this.conversations) && this.conversations.length > 0) { + const before = this.conversations.length; + this.conversations = this.conversations.filter(m => { + if (!m) return false; + const content = (typeof m.content !== 'undefined' && m.content !== null) ? String(m.content).trim() : ''; + const hasMedia = !!(m.local_thumb || m.local_file || m.media_url_external || m.media_url); + const nonText = m.message_type && m.message_type !== 'text'; + return (hasMedia || nonText || content.length > 0); + }); + const cleaned = before - this.conversations.length; + if (cleaned > 0) console.info('Removed', cleaned, 'empty text-only messages from conversation view'); + } + } catch (e) { console.warn('Failed to clean conversation entries', e); } + // Actualizar paginación (earliest timestamp y id) if (earliest) this.earliestMessage = earliest; if (typeof earliestId !== 'undefined' && earliestId !== null) this.earliestMessageId = earliestId;