diff options
Diffstat (limited to 'StoneIsland/www/js/lib/etc')
| -rwxr-xr-x | StoneIsland/www/js/lib/etc/push.js | 46 |
1 files changed, 15 insertions, 31 deletions
diff --git a/StoneIsland/www/js/lib/etc/push.js b/StoneIsland/www/js/lib/etc/push.js index ccdc39f5..bf7185e6 100755 --- a/StoneIsland/www/js/lib/etc/push.js +++ b/StoneIsland/www/js/lib/etc/push.js @@ -13,41 +13,30 @@ var push = (function(){ clearBadge: true, }, }) + + push.settings.requested = localStorage.getItem("yoox.push_requested") == "true" + push.settings.hub = localStorage.getItem("yoox.push_hub") == "true" + push.settings.store = localStorage.getItem("yoox.push_store") == "true" - PushNotification.hasPermission(push.did_initialize) - + pushPlugin.hasPermission(push.did_initialize) pushPlugin.on('registration', push.got_registration) - pushPlugin.on('notification', push.got_push_notification) } - - push.got_registration = function(data){ - var registrationId = data.registrationId - var oldRegistrationId = localStorage.getItem("yoox.registrationId") - console.log(registrationId, oldRegistrationId) - - if (registrationId !== oldRegistrationId) { - localStorage.setItem("yoox.registrationId", registrationId) - push.subscribe("hub", function(){ - push.subscribe("store") - }) - } - } push.did_initialize = function(data) { if (! data.isEnabled) { return } - - parsePlugin.registerCallback('onNotification', function(){ - window.onNotification = push.got_push_notification - }, push.error) - push.settings.requested = localStorage.getItem("yoox.push_requested") == "true" push.settings.hub = localStorage.getItem("yoox.push_hub") == "true" push.settings.store = localStorage.getItem("yoox.push_store") == "true" + } + push.got_registration = function(data){ + var registrationId = data.registrationId + var oldRegistrationId = localStorage.getItem("yoox.registrationId") + console.log(registrationId, oldRegistrationId) - if ( ! push.settings.requested ) { - localStorage.setItem("yoox.push_requested", "true") + if (registrationId !== oldRegistrationId || ! push.settings.requested) { + localStorage.setItem("yoox.registrationId", registrationId) push.subscribe("hub", function(){ push.subscribe("store") }) @@ -84,7 +73,7 @@ var push = (function(){ $.ajax({ method: "POST", url: "https://stone.sup.land/_services/push/remove", - data: JSON.stringify(), + data: data, contentType: 'application/x-www-form-urlencoded; charset=UTF-8', success: function(){ console.log("unsubscribed from", channel) @@ -93,12 +82,6 @@ var push = (function(){ error: push.error, }) } - // parsePlugin.getInstallationId(function(id) { - // var install_data = { - // installation_id: id, - // channels: ['SampleChannel'] - // } - // }, push.error) push.got_push_notification = function(push_obj) { // alert('We received this push notification: ' + JSON.stringify(push_obj)); app.blog.refresh() @@ -117,8 +100,9 @@ var push = (function(){ app.intro.$alert.show().html("[ HUB UPDATED ]") } - if (push_obj.receivedInForeground === false) { + if (push_obj.additionalData.foreground === false) { // TODO: route the user to the uri in push_obj + pushPlugin.finish(function(){}, function(){}) } else { app.route("intro") |
