Update conversations.php

This commit is contained in:
Lizandro Guarnizo
2026-01-26 00:21:29 -05:00
parent 6774cda8ad
commit a14d2dcb1e
+24 -55
View File
@@ -2096,19 +2096,33 @@
}
};
// (Auxiliary attend button deprecated — we use the main Atender/Finalizar button)
// Auxiliary attend button is hidden: we use the main Atender/Finalizar control and show status in-chat
try {
const attendToggleBtn = document.getElementById('attend-toggle-btn');
if (attendToggleBtn) {
attendToggleBtn.style.display = 'none';
attendToggleBtn.onclick = null;
}
if (conv && conv.advisor_requested && !conv.in_service) {
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e) { /* ignore */ }
}
} catch (e) { console.warn('ensure attend button visibility failed', e); }
// 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
// Hide auxiliary attend button to avoid having two 'Finalizar' controls
attendToggleBtn.style.display = 'none';
attendToggleBtn.onclick = null;
attendStatus.textContent = '';
// still update status message in chat when needed
// refresh conv reference
const c = this.conversations.find(x => x.user_id === userId) || conv;
// Update only the in-chat status message based on server/local state
this.getUserState(userId).then(serverState => {
const s = serverState || { in_service: c.in_service, advisor_requested: c.advisor_requested };
if (s.in_service) {
@@ -2123,54 +2137,7 @@
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e) {}
}
});
// refresh conv reference
const c = this.conversations.find(x => x.user_id === userId) || conv;
// request a cached state (fast) to be more preciso
this.getUserState(userId).then(serverState => {
const s = serverState || { in_service: c.in_service, advisor_requested: c.advisor_requested };
if (s.in_service) {
attendToggleBtn.innerHTML = '<i class="fas fa-user-times"></i> Finalizar';
attendToggleBtn.classList.remove('btn-outline-light');
attendToggleBtn.classList.add('btn-light','text-dark');
attendToggleBtn.style.display = 'inline-block';
attendStatus.textContent = `Atendido por ${c.in_service_by_name || 'un asesor'}`;
// show status message in chat
try { this.showStatusMessageInChat(userId, 'Un asesor te está atendiendo'); } catch(e){/* ignore */}
} else if ( (s.advisor_requested) || (c && c.advisor_requested) ) {
// Show Atender if either server reports a request OR local conversation record has it
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';
attendStatus.textContent = '';
// show a subtle status that a request is pending
try { this.showStatusMessageInChat(userId, 'Solicitud de asesor pendiente'); } catch(e){/* ignore */}
} else {
attendToggleBtn.style.display = 'none';
attendStatus.textContent = '';
}
}).catch(e => {
// fallback to local conv fields
if (c.in_service) {
attendToggleBtn.innerHTML = '<i class="fas fa-user-times"></i> Finalizar';
attendToggleBtn.classList.remove('btn-outline-light');
attendToggleBtn.classList.add('btn-light','text-dark');
attendToggleBtn.style.display = 'inline-block';
attendStatus.textContent = `Atendido por ${c.in_service_by_name || 'un asesor'}`;
} else if (c.advisor_requested) {
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';
attendStatus.textContent = '';
} else {
attendToggleBtn.style.display = 'none';
attendStatus.textContent = '';
}
});
};
};
const toggleAttend = async () => {
try {
@@ -2190,7 +2157,7 @@
// hide hold indicator
if (holdIndicator) holdIndicator.style.display = 'none';
// NOTE: release_hold is handled server-side by finish_attend.php to avoid duplicate notifications
// release_hold is performed by finish_attend.php; avoid extra client-side call to prevent duplicate notifications.
// actualizar cache local
this._userStateCache = this._userStateCache || {};
@@ -2239,7 +2206,9 @@
};
if (attendToggleBtn) {
attendToggleBtn.onclick = toggleAttend;
// Auxiliary button intentionally disabled; main control handles attend/finish
attendToggleBtn.style.display = 'none';
attendToggleBtn.onclick = null;
}
// inicializar estado
@@ -2273,7 +2242,7 @@
conv.bot_enabled = true;
if (holdIndicator) holdIndicator.style.display = 'none';
// NOTE: release_hold is handled server-side by finish_attend.php to avoid duplicate notifications
// release_hold is performed by finish_attend.php; avoid extra client-side call to prevent duplicate notifications.
// actualizar cache local
this._userStateCache = this._userStateCache || {};