Update conversations.php

This commit is contained in:
lizandrogd
2026-01-21 11:20:13 -05:00
parent fccaa3b649
commit 932820d02d
+16 -9
View File
@@ -906,27 +906,34 @@
} }
try { try {
const response = await fetch(`api/get_user_conversations.php?user_id=${userId}`); // Usar apiCall para incluir debug=true y manejo de auth/errores
const data = await response.json(); const data = await this.apiCall(`get_user_conversations.php?user_id=${userId}`);
let messages = [];
if (!data) {
throw new Error('No autorizado o error en la petición');
}
if (Array.isArray(data)) { if (Array.isArray(data)) {
this.conversations = data; messages = data;
} else if (data && data.success && Array.isArray(data.data)) {
messages = data.data;
} else if (Array.isArray(data.conversations)) {
messages = data.conversations;
}
this.conversations = messages;
this.renderconversations(); this.renderconversations();
this.scrollToBottom(); this.scrollToBottom();
// Marcar como leídos en el backend // Marcar como leídos en el backend
try { try {
await fetch('api/mark_conversation_read.php', { await this.apiCall('mark_conversation_read.php', { method: 'POST', body: { user_id: userId } });
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId })
});
// Recargar lista de conversaciones para refrescar contadores // Recargar lista de conversaciones para refrescar contadores
await this.loadConversations(); await this.loadConversations();
} catch (e) { } catch (e) {
console.error('Error marking conversation as read', e); console.error('Error marking conversation as read', e);
} }
}
} catch (error) { } catch (error) {
console.error('Error loading conversations:', error); console.error('Error loading conversations:', error);
document.getElementById('chat-conversations').innerHTML = ` document.getElementById('chat-conversations').innerHTML = `