From 1faebd56ef35611e99cbfd5a67a4e7e1f9b035d5 Mon Sep 17 00:00:00 2001 From: marsalva Date: Sat, 14 Mar 2026 12:16:37 +0000 Subject: [PATCH] Actualizar calendario.html --- calendario.html | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/calendario.html b/calendario.html index d27fb33..5938eff 100644 --- a/calendario.html +++ b/calendario.html @@ -650,10 +650,10 @@ safeLoadIcons(); } - async function openService(id) { + async function openService(id) { let s = localServices.find(x => x.id === id); - // šŸ”„ SOLUCIƓN: Si no lo encontramos en memoria, lo pedimos al servidor + // šŸ”„ 1. Si no lo encontramos en memoria, lo pedimos al servidor if (!s) { showToast("Cargando expediente..."); try { @@ -662,23 +662,33 @@ }); const data = await res.json(); if (data.ok) { - // Lo buscamos en la base de datos completa de servicios activos s = data.services.find(x => x.id === id); if (s) { - // Lo aƱadimos a la memoria local para que funcione bien el modal localServices.push(s); } } } catch (e) { - console.error("Error buscando servicio fantasma:", e); + console.error("Error buscando servicio:", e); } } + // šŸ‘» 2. EL MATA-FANTASMAS: Si definitivamente NO existe (estĆ” archivado o reasignado) if (!s || s.provider === 'SYSTEM_BLOCK') { - showToast("No se pudo cargar el expediente", true); + try { + // Lo marcamos como leĆ­do a la fuerza en la base de datos para matar el globo rojo + await fetch(`${API_URL}/services/${id}/chat/read`, { + method: 'POST', + headers: { 'Authorization': `Bearer ${localStorage.getItem("token")}` } + }); + // Refrescamos las notificaciones visuales + if (typeof checkNotifications === "function") checkNotifications(); + } catch(e) {} + + showToast("Expediente archivado o reasignado. Notificación borrada.", true); return; } + // 3. Si existe, lo abrimos normalmente const raw = s.raw_data; currentServiceId = id; @@ -727,7 +737,7 @@ setTimeout(() => modal.classList.remove('translate-y-full'), 10); calculateDistance(fullAddress); - // šŸ”„ MEJORA: Al abrir desde notificación, abrimos el chat automĆ”ticamente + // šŸ”„ AL ABRIR DESDE NOTIFICACIƓN, ABRIMOS EL CHAT AUTOMƁTICAMENTE if (activeNotifications.includes(id)) { document.getElementById('chatContainer').classList.remove('hidden'); document.getElementById('chatContainer').classList.add('flex'); @@ -740,7 +750,6 @@ } safeLoadIcons(); - } function closeModal() {