From 932820d02dd37cda869113fbcb77fa989eaf8e5f Mon Sep 17 00:00:00 2001 From: lizandrogd <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 21 Jan 2026 11:20:13 -0500 Subject: [PATCH] Update conversations.php --- conversations.php | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/conversations.php b/conversations.php index 1d96bf0..3ba1b16 100644 --- a/conversations.php +++ b/conversations.php @@ -906,26 +906,33 @@ } try { - const response = await fetch(`api/get_user_conversations.php?user_id=${userId}`); - const data = await response.json(); - - if (Array.isArray(data)) { - this.conversations = data; - this.renderconversations(); - this.scrollToBottom(); + // Usar apiCall para incluir debug=true y manejo de auth/errores + const data = await this.apiCall(`get_user_conversations.php?user_id=${userId}`); - // Marcar como leídos en el backend - try { - await fetch('api/mark_conversation_read.php', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ user_id: userId }) - }); - // Recargar lista de conversaciones para refrescar contadores - await this.loadConversations(); - } catch (e) { - console.error('Error marking conversation as read', e); - } + let messages = []; + if (!data) { + throw new Error('No autorizado o error en la petición'); + } + + if (Array.isArray(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.scrollToBottom(); + + // Marcar como leídos en el backend + try { + await this.apiCall('mark_conversation_read.php', { method: 'POST', body: { user_id: userId } }); + // Recargar lista de conversaciones para refrescar contadores + await this.loadConversations(); + } catch (e) { + console.error('Error marking conversation as read', e); } } catch (error) { console.error('Error loading conversations:', error);