mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
Merge pull request #6631 from marc1706/ticket/17321
[ticket/17321] Add versioning to push worker to force updates
This commit is contained in:
commit
df0dcae3ce
3 changed files with 26 additions and 1 deletions
|
@ -210,6 +210,7 @@ class webpush extends messenger_base implements extended_method_interface
|
|||
$data = [
|
||||
'item_id' => $notification->item_id,
|
||||
'type_id' => $notification->notification_type_id,
|
||||
'version' => $this->config['assets_version'],
|
||||
];
|
||||
$json_data = json_encode($data);
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ class webpush
|
|||
// @todo: only work for logged in users, no anonymous & bot
|
||||
$content = $this->template->render('push_worker.js.twig', [
|
||||
'U_WEBPUSH_GET_NOTIFICATION' => $this->controller_helper->route('phpbb_ucp_push_get_notification_controller'),
|
||||
'ASSETS_VERSION' => $this->config['assets_version'],
|
||||
]);
|
||||
|
||||
$response = new Response($content);
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
/**
|
||||
* Event listener for install event
|
||||
*/
|
||||
self.addEventListener('install', () => {
|
||||
// Call to ensure service worker is correctly updated
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
/**
|
||||
* Event listener for activate event
|
||||
*/
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
||||
/**
|
||||
* Event listener for push event
|
||||
*/
|
||||
|
@ -8,16 +23,24 @@ self.addEventListener('push', event => {
|
|||
|
||||
let itemId = 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));
|
||||
|
|
Loading…
Add table
Reference in a new issue