mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/17321] Add versioning to push worker to force updates
PHPBB-17321
This commit is contained in:
@@ -1,3 +1,15 @@
|
||||
/**
|
||||
* Event listener for install event
|
||||
*/
|
||||
self.addEventListener('install', () => {
|
||||
// Call to ensure service worker is correctly updated
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
|
||||
/**
|
||||
* Event listener for push event
|
||||
*/
|
||||
@@ -7,17 +19,25 @@ self.addEventListener('push', event => {
|
||||
}
|
||||
|
||||
let itemId = 0;
|
||||
let typeId = 0;
|
||||
let typeId = 0;
|
||||
let notificationVersion = 5;
|
||||
try {
|
||||
const notificationData = event.data.json();
|
||||
itemId = notificationData.item_id;
|
||||
typeId = notificationData.type_id;
|
||||
notificationVersion = parseInt(notificationData.version, 10);
|
||||
} catch {
|
||||
self.registration.showNotification(event.data.text());
|
||||
return;
|
||||
}
|
||||
|
||||
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
|
||||
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
|
||||
|
||||
// Force update if versions differ
|
||||
if (assetsVersion !== notificationVersion) {
|
||||
self.registration.update();
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('item_id', itemId.toString(10));
|
||||
|
Reference in New Issue
Block a user