Update conversations.php

This commit is contained in:
Lizandro Guarnizo
2026-01-26 00:12:47 -05:00
parent 4b9c74e5d7
commit 6774cda8ad
+23 -22
View File
@@ -2096,28 +2096,33 @@
}
};
// Ensure 'Atender' button appears when there's an advisor request (even if other flows didn't initialize it yet)
(function(){
try {
const attendToggleBtn = document.getElementById('attend-toggle-btn');
const attendStatus = document.getElementById('attend-status');
if (attendToggleBtn && conv && conv.advisor_requested && !conv.in_service) {
attendToggleBtn.innerHTML = '<i class="fas fa-user-check"></i> Atender';
attendToggleBtn.classList.remove('btn-light','text-dark');
attendToggleBtn.classList.add('btn-outline-light');
attendToggleBtn.style.display = 'inline-block';
if (attendStatus) attendStatus.textContent = '';
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e) { /* ignore */ }
}
} catch (e) { console.warn('ensure attend button visibility failed', e); }
}).call(this);
// (Auxiliary attend button deprecated — we use the main Atender/Finalizar button)
// Render attend controls (single toggle + status) — compatible con comportamiento de chat_window.php
const attendToggleBtn = document.getElementById('attend-toggle-btn');
const attendStatus = document.getElementById('attend-status');
const renderAttendControls = () => {
if (!attendToggleBtn || !attendStatus) return;
// Hide auxiliary attend button — prefer single main control
attendToggleBtn.style.display = 'none';
attendStatus.textContent = '';
// still update status message in chat when needed
const c = this.conversations.find(x => x.user_id === userId) || conv;
this.getUserState(userId).then(serverState => {
const s = serverState || { in_service: c.in_service, advisor_requested: c.advisor_requested };
if (s.in_service) {
try { this.showStatusMessageInChat(userId, 'Un asesor te está atendiendo'); } catch(e) {}
} else if (s.advisor_requested || c.advisor_requested) {
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e) {}
}
}).catch(e => {
if (c.in_service) {
try { this.showStatusMessageInChat(userId, 'Un asesor te está atendiendo'); } catch(e) {}
} else if (c.advisor_requested) {
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e) {}
}
});
// refresh conv reference
const c = this.conversations.find(x => x.user_id === userId) || conv;
@@ -2185,10 +2190,7 @@
// hide hold indicator
if (holdIndicator) holdIndicator.style.display = 'none';
// Try to ensure hold is released on server as finalizing should free the hold
try {
await this.apiCall('release_hold.php', { body: { user_id: userId } });
} catch (e) { console.warn('release_hold after finish failed', e); }
// NOTE: release_hold is handled server-side by finish_attend.php to avoid duplicate notifications
// actualizar cache local
this._userStateCache = this._userStateCache || {};
@@ -2271,8 +2273,7 @@
conv.bot_enabled = true;
if (holdIndicator) holdIndicator.style.display = 'none';
// Intentar liberar hold en servidor por seguridad
try { await this.apiCall('release_hold.php', { body: { user_id: userId } }); } catch (e) { console.warn('release_hold after finish failed', e); }
// NOTE: release_hold is handled server-side by finish_attend.php to avoid duplicate notifications
// actualizar cache local
this._userStateCache = this._userStateCache || {};