refactor
This commit is contained in:
parent
2d07cf0e55
commit
171665afe6
4 changed files with 93 additions and 93 deletions
|
|
@ -1,18 +1,84 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('pushNotificationsService', function($http) {
|
||||
var root = {};
|
||||
'use strict';
|
||||
angular.module('copayApp.services')
|
||||
.factory('pushNotificationsService', function($http, $log, profileService, storageService, lodash) {
|
||||
var root = {};
|
||||
|
||||
root.subscribe = function(opts) {
|
||||
return $http.post('http://192.168.1.126:8000/subscribe', opts);
|
||||
}
|
||||
root.pushNotificationsInit = function() {
|
||||
|
||||
root.unsubscribe = function(token) {
|
||||
return $http.post('http://192.168.1.126:8000/unsubscribe', {
|
||||
token: token
|
||||
});
|
||||
}
|
||||
var push = PushNotification.init({
|
||||
android: {
|
||||
senderID: "959259672122"
|
||||
},
|
||||
ios: {
|
||||
alert: "true",
|
||||
badge: true,
|
||||
sound: 'false'
|
||||
},
|
||||
windows: {}
|
||||
});
|
||||
|
||||
return root;
|
||||
push.on('registration', function(data) {
|
||||
storageService.setDeviceToken(data.registrationId, function() {
|
||||
root.enableNotifications();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
push.on('notification', function(data) {
|
||||
$log.debug('Notification event: ', data.message);
|
||||
/* data.message,
|
||||
data.title,
|
||||
data.count,
|
||||
data.sound,
|
||||
data.image,
|
||||
data.additionalData
|
||||
*/
|
||||
});
|
||||
|
||||
push.on('error', function(e) {
|
||||
$log.warn('Error trying to push notifications: ', e);
|
||||
});
|
||||
};
|
||||
|
||||
root.enableNotifications = function() {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
|
||||
lodash.forEach(profileService.getWallets('livenet'), function(wallets) {
|
||||
var opts = {};
|
||||
opts.user = wallets.id;
|
||||
opts.type = (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "ios" : (navigator.userAgent.match(/Android/i)) == "Android" ? "android" : null;
|
||||
opts.token = token;
|
||||
|
||||
root.subscribe(opts).then(function(response) {
|
||||
$log.debug('Suscribed: ' + response.status);
|
||||
},
|
||||
function(err) {
|
||||
$log.warn('Error: ' + err.status);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root.disableNotifications = function() {
|
||||
storageService.getDeviceToken(function(err, token) {
|
||||
root.unsubscribe(token).then(function(response) {
|
||||
$log.debug('Unsubscribed: ' + response.status);
|
||||
},
|
||||
function(err) {
|
||||
$log.warn('Error: ' + err.status);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
root.subscribe = function(opts) {
|
||||
return $http.post('http://192.168.1.128:8000/subscribe', opts);
|
||||
}
|
||||
|
||||
root.unsubscribe = function(token) {
|
||||
return $http.post('http://192.168.1.128:8000/unsubscribe', {
|
||||
token: token
|
||||
});
|
||||
}
|
||||
|
||||
return root;
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue