This commit is contained in:
Lizandro Guarnizo
2026-01-28 14:05:01 -05:00
parent 2bf7d6c9a8
commit 3b63defba9
2 changed files with 49 additions and 10 deletions
+14 -7
View File
@@ -24,6 +24,9 @@ if (!isset($_SESSION['user_id'])) {
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>💬 Conversaciones - WhatsApp Bot</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
@@ -1862,7 +1865,7 @@ if (!isset($_SESSION['user_id'])) {
const mid = this._pendingReactionMessage;
if (!mid) return;
try {
const resp = await fetch('api/react_message.php', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ message_id: mid, emoji: emoji }) });
const resp = await fetch('api/react_message.php', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify({ message_id: mid, emoji: emoji }), cache: 'no-store' });
const j = await resp.json();
if (j && j.success) {
// update local model and UI
@@ -2459,7 +2462,7 @@ if (!isset($_SESSION['user_id'])) {
if (loadMoreBtn) loadMoreBtn.disabled = true;
try {
const url = `api/get_conversations.php?page=${page}&limit=${this.conversationsLimit}&filter=${encodeURIComponent(this.conversationFilter)}`;
const resp = await fetch(url, { credentials: 'same-origin' });
const resp = await fetch(url, { credentials: 'same-origin', cache: 'no-store' });
if (!resp.ok) {
throw new Error(`HTTP ${resp.status}: ${resp.statusText}`);
@@ -2789,7 +2792,8 @@ if (!isset($_SESSION['user_id'])) {
const resp = await fetch('api/mark_conversation_unread.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId })
body: JSON.stringify({ user_id: userId }),
cache: 'no-store'
});
if (resp.status === 401) {
alert('Sesión expirada. Por favor inicie sesión de nuevo.');
@@ -2840,7 +2844,8 @@ if (!isset($_SESSION['user_id'])) {
const resp = await fetch('api/release_hold.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId })
body: JSON.stringify({ user_id: userId }),
cache: 'no-store'
});
if (resp.status === 401) {
alert('Sesión expirada. Por favor inicie sesión de nuevo.');
@@ -4554,7 +4559,7 @@ if (!isset($_SESSION['user_id'])) {
if (!msg) {
// intentar obtener mensaje por API
try {
const resp = await fetch(`api/get_message.php?message_id=${encodeURIComponent(messageId)}`);
const resp = await fetch(`api/get_message.php?message_id=${encodeURIComponent(messageId)}`, { cache: 'no-store' });
if (resp.ok) {
const j = await resp.json();
if (j && j.success && j.data) {
@@ -4695,7 +4700,8 @@ if (!isset($_SESSION['user_id'])) {
const resp = await fetch('api/update_user.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: this.currentUserId, name: newName })
body: JSON.stringify({ user_id: this.currentUserId, name: newName }),
cache: 'no-store'
});
const json = await resp.json();
if (json && json.success) {
@@ -4717,7 +4723,8 @@ if (!isset($_SESSION['user_id'])) {
const resp = await fetch('api/delete_conversation.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: this.currentUserId })
body: JSON.stringify({ user_id: this.currentUserId }),
cache: 'no-store'
});
const json = await resp.json();
if (json && json.success) {
+35 -3
View File
@@ -1,11 +1,43 @@
// Minimal service worker stub to avoid 404s during development.
// Service worker - Force no-cache for API requests
const CACHE_VERSION = 'v1.0.1';
self.addEventListener('install', (event) => {
// activate immediately
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(self.clients.claim());
event.waitUntil(
caches.keys().then(keys => {
// Clear all caches on activation
return Promise.all(keys.map(key => caches.delete(key)));
}).then(() => self.clients.claim())
);
});
self.addEventListener('fetch', (event) => {
// No-op: default network behaviour
const url = new URL(event.request.url);
// For API requests, always go to network with no-cache
if (url.pathname.startsWith('/api/') || url.pathname.includes('/api/')) {
event.respondWith(
fetch(event.request, {
cache: 'no-store',
headers: {
...Object.fromEntries(event.request.headers),
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache'
}
}).catch(err => {
console.error('SW fetch error:', err);
return new Response(JSON.stringify({ error: 'Network error' }), {
status: 503,
headers: { 'Content-Type': 'application/json' }
});
})
);
return;
}
// For other requests, use default network behavior (no caching)
});