From 6774cda8adbf6d6e9d32b3adecaa0c9abc11f807 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Mon, 26 Jan 2026 00:12:47 -0500 Subject: [PATCH] Update conversations.php --- conversations.php | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/conversations.php b/conversations.php index dee9ea2..d697ace 100644 --- a/conversations.php +++ b/conversations.php @@ -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 = ' 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 || {};