Created
August 18, 2016 20:11
-
-
Save flavioso16/fa0bcb969bf432f55cba1b255d441e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener("push",function(a){a.waitUntil(self.registration.pushManager.getSubscription().then(function(a){var b=a&&a.subscriptionId?a.subscriptionId:a.endpoint.match(/([^\/]+)$/)&&RegExp.$1,c="https://apps.argos4.me/api/app/getNextChromeMessage?subscriptionId="+b;return fetch(c).then(function(a){if(200!==a.status)throw console.log("Looks like there was a problem. Status Code: "+a.status),new Error;return a.json().then(function(a){if(a)return console.log("Getting message id: "+a.id),self.registration.showNotification(a.title,{body:a.message,icon:a.iconURI,requireInteraction:!0,tag:a.tag,data:JSON.stringify({idNotification:a.id,subscriptionId:b,url:a.url})});throw console.log("Looks like there was a problem."),new Error})})}))}),self.addEventListener("notificationclick",function(a){console.log("On notification click: ",a.notification.tag),a.notification.close(),a.waitUntil(clients.matchAll({type:"window"}).then(function(b){for(var c=0;c<b.length;c++){var d=b[c];if("/"==d.url&&"focus"in d)return d.focus()}if(clients.openWindow&&(void 0!=a.notification.data||null!=a.notification.data)){var e=JSON.parse(a.notification.data);if(void 0!=e.idNotification||null!=e.idNotification){var f="https://apps.argos4.me/api/app/updateChromeMessage?subscriptionId="+e.subscriptionId+"¬ificationId="+e.idNotification+"&statusChromeMessage=CLICKED";fetch(f,{method:"put"})}if(void 0!=e.url||null!=e.url)return clients.openWindow(decodeURIComponent(e.url))}}))}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How this differs from https://gist.github.com/brandonrozek/0cf038df40a913fda655 ---------> Is this just the full code? And the above is a minification?