Update notification counter of all clients on push
This commit is contained in:
parent
0a51b37378
commit
2b62d22f9f
@ -17,9 +17,6 @@ export async function testNotification(arn: AnimeNotifier) {
|
||||
await fetch("/api/test/notification", {
|
||||
credentials: "same-origin"
|
||||
})
|
||||
|
||||
// Update notification counter
|
||||
arn.notificationManager.update()
|
||||
}
|
||||
|
||||
// Mark notifications as seen
|
||||
|
@ -73,6 +73,10 @@ export class ServiceWorkerManager {
|
||||
let message = JSON.parse(evt.data)
|
||||
|
||||
switch(message.type) {
|
||||
case "new notification":
|
||||
this.arn.notificationManager.update()
|
||||
break
|
||||
|
||||
case "new content":
|
||||
if(message.url.includes("/_/")) {
|
||||
// Content reload
|
||||
|
@ -197,6 +197,16 @@ class MyServiceWorker {
|
||||
onPush(evt: PushEvent) {
|
||||
var payload = evt.data ? evt.data.json() : {}
|
||||
|
||||
// Notify all clients about the new notification so they can update their notification counter
|
||||
self.clients.matchAll().then(function(clientList) {
|
||||
for(let client of clientList) {
|
||||
client.postMessage(JSON.stringify({
|
||||
type: "new notification"
|
||||
}))
|
||||
}
|
||||
})
|
||||
|
||||
// Display the notification
|
||||
return self.registration.showNotification(payload.title, {
|
||||
body: payload.message,
|
||||
icon: payload.icon,
|
||||
|
Loading…
Reference in New Issue
Block a user