self.addEventListener("install",function(a){a.waitUntil(self.skipWaiting());console.log("The ServiceWorker was installed.")});self.addEventListener("activate",function(a){console.log("The ServiceWorker was activated.")});self.addEventListener("push",function(b){console.log("Received a new push message",b);var c;var a;b.waitUntil(self.registration.pushManager.getSubscription().then(function(d){c="Web";a=d.endpoint;if(b.data){return b.data.json()}else{return fetch("pnfw/notifications/?"+toQueryString({os:c,token:a}))}}).then(function(d){if(d instanceof Response){if(d.ok){return d.json()}else{return{title:"",message:"A new post has been published.",id:0}}}else{return d}}).then(function(d){return self.registration.showNotification(d.title,{body:d.message,icon:d.icon||"pnfw/icon/",tag:self.registration.scope,requireInteraction:true,data:{id:d.id,token:a,os:c}})}))});self.addEventListener("notificationclick",function(a){console.log("On notification click: ",a.notification.tag);a.notification.close();var b={os:a.notification.data.os,token:a.notification.data.token,post:a.notification.data.id};if(clients.openWindow){return clients.openWindow("pnfw/goto/?"+toQueryString(b))}});function toQueryString(c){var b=[];for(var a in c){if(c.hasOwnProperty(a)){b.push(encodeURIComponent(a)+"="+encodeURIComponent(c[a]))}}return b.join("&")};