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() {