summaryrefslogtreecommitdiff
path: root/StoneIsland/platforms/android/assets/www/js/lib/etc/push.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-12-11 05:37:34 -0600
committerJules Laplace <jules@okfoc.us>2015-12-11 05:37:34 -0600
commitaa5a9b7c7cd52a69f8dd1d0cdc15475e113e6da0 (patch)
treececfdb0893eb9e936fe605478b3f8195dc7ef987 /StoneIsland/platforms/android/assets/www/js/lib/etc/push.js
parent4178c44c48aa401f7780bec3f89430c83d50fe30 (diff)
remembered a couple things, push 0.3.4
Diffstat (limited to 'StoneIsland/platforms/android/assets/www/js/lib/etc/push.js')
-rwxr-xr-xStoneIsland/platforms/android/assets/www/js/lib/etc/push.js77
1 files changed, 76 insertions, 1 deletions
diff --git a/StoneIsland/platforms/android/assets/www/js/lib/etc/push.js b/StoneIsland/platforms/android/assets/www/js/lib/etc/push.js
index ab0c0141..4e771b62 100755
--- a/StoneIsland/platforms/android/assets/www/js/lib/etc/push.js
+++ b/StoneIsland/platforms/android/assets/www/js/lib/etc/push.js
@@ -1 +1,76 @@
-// \ No newline at end of file
+var push = (function(){
+ var appId = "GS82ZxpN8Mecpc53rsyu6aLLGK0W4CKi42J25DLB"
+ var clientKey = "hQRtQfsgimYnX5PMivtcdXCG9eZhESeyTr0Rd8Sv"
+ var push = { settings: {} }
+ var parsePlugin
+ push.init = function(){
+ parsePlugin = window.parsePlugin || { initialize: function(){} }
+ parsePlugin.initialize(appId, clientKey, push.did_initialize, push.error)
+ }
+ push.did_initialize = function() {
+ 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"
+
+ if ( ! push.settings.requested ) {
+ localStorage.setItem("yoox.push_" + channel, "true")
+ push.subscribe("hub", function(){
+ push.subscribe("store")
+ })
+ }
+ }
+ push.subscribe = function(channel, cb){
+ parsePlugin.subscribe(channel, function(){
+ push.settings[channel] = true
+ localStorage.setItem("yoox.push_" + channel, "true")
+ console.log("subscribed to", channel)
+ cb && cb()
+ }, push.error)
+ }
+ push.unsubscribe = function(channel, cb){
+ parsePlugin.unsubscribe(channel, function(){
+ push.settings[channel] = false
+ localStorage.setItem("yoox.push_" + channel, "false")
+ console.log("unsubscribed from", channel)
+ cb && cb()
+ }, 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()
+
+ try {
+ var is_hub = JSON.stringify(push_obj || {}).match(/hub/i)
+ if (is_hub) {
+ app.intro.$alert.show().html("[ HUB UPDATED ]")
+ }
+ else {
+ app.intro.$alert.show().html("[ STORE UPDATED ]")
+ }
+ }
+ catch (e) {
+ app.intro.$alert.show().html("[ HUB UPDATED ]")
+ }
+
+ if (push_obj.receivedInForeground === false) {
+ // TODO: route the user to the uri in push_obj
+ }
+ else {
+ app.route("intro")
+ }
+ }
+ push.error = function(e){
+ console.log("push error")
+ }
+ return push
+})() \ No newline at end of file