Revert "Update conversations.php"

This reverts commit 38237eaf13.
This commit is contained in:
Lizandro Guarnizo
2026-01-24 09:18:34 -05:00
parent 38237eaf13
commit aa59b0561c
-26
View File
@@ -2091,8 +2091,6 @@
}
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)}`;
@@ -2141,14 +2139,6 @@
}
}
// 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) {
@@ -2186,22 +2176,6 @@
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;