mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge 6b6b5ffc28
into 2fce8aeb3e
This commit is contained in:
commit
990425b00f
1 changed files with 33 additions and 26 deletions
|
@ -34,41 +34,48 @@ self.addEventListener('push', event => {
|
||||||
notificationVersion = parseInt(notificationData.version, 10);
|
notificationVersion = parseInt(notificationData.version, 10);
|
||||||
pushToken = notificationData.token;
|
pushToken = notificationData.token;
|
||||||
} catch {
|
} catch {
|
||||||
self.registration.showNotification(event.data.text());
|
event.waitUntil(self.registration.showNotification(event.data.text()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
|
event.waitUntil((async() => {
|
||||||
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
|
const getNotificationUrl = '{{ U_WEBPUSH_GET_NOTIFICATION }}';
|
||||||
|
const assetsVersion = parseInt('{{ ASSETS_VERSION }}', 10);
|
||||||
|
|
||||||
// Force update if versions differ
|
// Force update if versions differ
|
||||||
if (assetsVersion !== notificationVersion) {
|
if (assetsVersion !== notificationVersion) {
|
||||||
self.registration.update();
|
await self.registration.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('item_id', itemId.toString(10));
|
formData.append('item_id', itemId.toString(10));
|
||||||
formData.append('type_id', typeId.toString(10));
|
formData.append('type_id', typeId.toString(10));
|
||||||
formData.append('user_id', userId.toString(10));
|
formData.append('user_id', userId.toString(10));
|
||||||
formData.append('token', pushToken);
|
formData.append('token', pushToken);
|
||||||
|
|
||||||
fetch(getNotificationUrl, {
|
try {
|
||||||
method: 'POST',
|
const response = await fetch(getNotificationUrl, {
|
||||||
headers: {
|
method: 'POST',
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
headers: {
|
||||||
},
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
body: formData,
|
},
|
||||||
})
|
body: formData,
|
||||||
.then(response => response.json())
|
});
|
||||||
.then(response => {
|
|
||||||
const responseBody = response.title + '\n' + response.text;
|
const responseData = await response.json();
|
||||||
|
|
||||||
|
const responseBody = responseData.title + '\n' + responseData.text;
|
||||||
const options = {
|
const options = {
|
||||||
body: responseBody,
|
body: responseBody,
|
||||||
data: response,
|
data: responseData,
|
||||||
icon: response.avatar.src,
|
icon: responseData.avatar.src,
|
||||||
};
|
};
|
||||||
self.registration.showNotification(response.heading, options);
|
|
||||||
});
|
await self.registration.showNotification(responseData.heading, options);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Push error:', e);
|
||||||
|
}
|
||||||
|
})());
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue