From 3b63defba9f5dacfd16c82427fffd65b7b62157b Mon Sep 17 00:00:00 2001
From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com>
Date: Wed, 28 Jan 2026 14:05:01 -0500
Subject: [PATCH] up
---
conversations.php | 21 ++++++++++++++-------
service-worker.js | 38 +++++++++++++++++++++++++++++++++++---
2 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/conversations.php b/conversations.php
index c4927d4..2c10bfa 100644
--- a/conversations.php
+++ b/conversations.php
@@ -24,6 +24,9 @@ if (!isset($_SESSION['user_id'])) {
+
+
+
š¬ Conversaciones - WhatsApp Bot
@@ -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) {
diff --git a/service-worker.js b/service-worker.js
index 0e26397..0dd1a59 100644
--- a/service-worker.js
+++ b/service-worker.js
@@ -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)
});