move push notifications config to configService
This commit is contained in:
parent
a97befc20a
commit
50ffb0af23
3 changed files with 25 additions and 23 deletions
|
|
@ -36,12 +36,12 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
|
||||||
var unwatchNotification = $scope.$watch('notifications', function(newVal, oldVal) {
|
var unwatchNotification = $scope.$watch('notifications', function(newVal, oldVal) {
|
||||||
if (newVal == oldVal) return;
|
if (newVal == oldVal) return;
|
||||||
var opts = {
|
var opts = {
|
||||||
notifications: {
|
pushNotifications: {
|
||||||
enabled: newVal
|
enabled: newVal
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
configService.set(opts, function(err) {
|
configService.set(opts, function(err) {
|
||||||
if (opts.notifications.enabled)
|
if (opts.pushNotifications.enabled)
|
||||||
pushNotificationsService.enableNotifications();
|
pushNotificationsService.enableNotifications();
|
||||||
else
|
else
|
||||||
pushNotificationsService.disableNotifications();
|
pushNotificationsService.disableNotifications();
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,20 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
url: 'https://insight.bitpay.com:443/api/rates',
|
url: 'https://insight.bitpay.com:443/api/rates',
|
||||||
},
|
},
|
||||||
|
|
||||||
notifications: {
|
pushNotifications: {
|
||||||
enabled: true
|
enabled: true,
|
||||||
|
url: 'http://192.168.1.111:8080',
|
||||||
|
config: {
|
||||||
|
android: {
|
||||||
|
senderID: '959259672122',
|
||||||
|
},
|
||||||
|
ios: {
|
||||||
|
alert: 'true',
|
||||||
|
badge: 'true',
|
||||||
|
sound: 'true',
|
||||||
|
},
|
||||||
|
windows: {},
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,21 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
angular.module('copayApp.services')
|
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 root = {};
|
||||||
|
var defaults = configService.getDefaults();
|
||||||
|
|
||||||
root.pushNotificationsInit = function() {
|
root.pushNotificationsInit = function() {
|
||||||
|
var push = PushNotification.init(defaults.pushNotifications.config);
|
||||||
var push = PushNotification.init({
|
|
||||||
android: {
|
|
||||||
senderID: "959259672122"
|
|
||||||
},
|
|
||||||
ios: {
|
|
||||||
alert: "true",
|
|
||||||
badge: true,
|
|
||||||
sound: 'false'
|
|
||||||
},
|
|
||||||
windows: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
push.on('registration', function(data) {
|
push.on('registration', function(data) {
|
||||||
$log.debug('Starting registration');
|
$log.debug('Starting push notification registration');
|
||||||
storageService.setDeviceToken(data.registrationId, function() {
|
storageService.setDeviceToken(data.registrationId, function() {
|
||||||
root.enableNotifications();
|
root.enableNotifications();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
push.on('notification', function(data) {
|
push.on('notification', function(data) {
|
||||||
$log.debug('Notification event: ', data.message);
|
$log.debug('Push notification event: ', data.message);
|
||||||
/* data.message,
|
/* data.message,
|
||||||
data.title,
|
data.title,
|
||||||
data.count,
|
data.count,
|
||||||
|
|
@ -45,7 +35,7 @@ angular.module('copayApp.services')
|
||||||
lodash.forEach(profileService.getWallets('testnet'), function(wallets) {
|
lodash.forEach(profileService.getWallets('testnet'), function(wallets) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
opts.user = wallets.id + '$' + wallets.copayerId;
|
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;
|
opts.token = token;
|
||||||
root.subscribe(opts).then(function(response) {
|
root.subscribe(opts).then(function(response) {
|
||||||
$log.debug('Suscribed: ' + response.status);
|
$log.debug('Suscribed: ' + response.status);
|
||||||
|
|
@ -69,17 +59,17 @@ angular.module('copayApp.services')
|
||||||
}
|
}
|
||||||
|
|
||||||
root.subscribe = function(opts) {
|
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) {
|
root.unsubscribe = function(user) {
|
||||||
return $http.post('http://192.168.1.128:8000/unsubscribe', {
|
return $http.post(defaults.pushNotifications.url + '/unsubscribe', {
|
||||||
user: user
|
user: user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
root.unsubscribeAll = function(token) {
|
root.unsubscribeAll = function(token) {
|
||||||
return $http.post('http://192.168.1.128:8000/unsubscribe', {
|
return $http.post(defaults.pushNotifications.url + '/unsubscribe', {
|
||||||
token: token
|
token: token
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue