From 50ffb0af232f04c7a1db6f7a2b23c00b3a28d4e3 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 13 Jan 2016 10:12:10 -0300 Subject: [PATCH] move push notifications config to configService --- src/js/controllers/preferencesGlobal.js | 4 +-- src/js/services/configService.js | 16 ++++++++++-- src/js/services/pushNotificationsService.js | 28 +++++++-------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/js/controllers/preferencesGlobal.js b/src/js/controllers/preferencesGlobal.js index ab468733f..ee24f76a8 100644 --- a/src/js/controllers/preferencesGlobal.js +++ b/src/js/controllers/preferencesGlobal.js @@ -36,12 +36,12 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController', var unwatchNotification = $scope.$watch('notifications', function(newVal, oldVal) { if (newVal == oldVal) return; var opts = { - notifications: { + pushNotifications: { enabled: newVal } }; configService.set(opts, function(err) { - if (opts.notifications.enabled) + if (opts.pushNotifications.enabled) pushNotificationsService.enableNotifications(); else pushNotificationsService.disableNotifications(); diff --git a/src/js/services/configService.js b/src/js/services/configService.js index 3771c5e9b..702cad585 100644 --- a/src/js/services/configService.js +++ b/src/js/services/configService.js @@ -42,8 +42,20 @@ angular.module('copayApp.services').factory('configService', function(storageSer url: 'https://insight.bitpay.com:443/api/rates', }, - notifications: { - enabled: true + pushNotifications: { + enabled: true, + url: 'http://192.168.1.111:8080', + config: { + android: { + senderID: '959259672122', + }, + ios: { + alert: 'true', + badge: 'true', + sound: 'true', + }, + windows: {}, + } }, }; diff --git a/src/js/services/pushNotificationsService.js b/src/js/services/pushNotificationsService.js index c3a84866d..68eac8027 100644 --- a/src/js/services/pushNotificationsService.js +++ b/src/js/services/pushNotificationsService.js @@ -1,31 +1,21 @@ 'use strict'; angular.module('copayApp.services') - .factory('pushNotificationsService', function($http, $log, profileService, storageService, lodash) { + .factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) { var root = {}; + var defaults = configService.getDefaults(); root.pushNotificationsInit = function() { - - var push = PushNotification.init({ - android: { - senderID: "959259672122" - }, - ios: { - alert: "true", - badge: true, - sound: 'false' - }, - windows: {} - }); + var push = PushNotification.init(defaults.pushNotifications.config); push.on('registration', function(data) { - $log.debug('Starting registration'); + $log.debug('Starting push notification registration'); storageService.setDeviceToken(data.registrationId, function() { root.enableNotifications(); }); }); push.on('notification', function(data) { - $log.debug('Notification event: ', data.message); + $log.debug('Push notification event: ', data.message); /* data.message, data.title, data.count, @@ -45,7 +35,7 @@ angular.module('copayApp.services') lodash.forEach(profileService.getWallets('testnet'), function(wallets) { var opts = {}; opts.user = wallets.id + '$' + wallets.copayerId; - opts.type = (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "ios" : (navigator.userAgent.match(/Android/i)) == "Android" ? "android" : null; + opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null; opts.token = token; root.subscribe(opts).then(function(response) { $log.debug('Suscribed: ' + response.status); @@ -69,17 +59,17 @@ angular.module('copayApp.services') } root.subscribe = function(opts) { - return $http.post('http://192.168.1.128:8000/subscribe', opts); + return $http.post(defaults.pushNotifications.url + '/subscribe', opts); } root.unsubscribe = function(user) { - return $http.post('http://192.168.1.128:8000/unsubscribe', { + return $http.post(defaults.pushNotifications.url + '/unsubscribe', { user: user }); } root.unsubscribeAll = function(token) { - return $http.post('http://192.168.1.128:8000/unsubscribe', { + return $http.post(defaults.pushNotifications.url + '/unsubscribe', { token: token }); }