unsubscribe when wallet is deleted

This commit is contained in:
Gabriel Bazán 2016-01-04 16:35:34 -03:00
commit 2d64e61654
3 changed files with 19 additions and 7 deletions

View file

@ -1273,10 +1273,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
go.walletHome(); go.walletHome();
}); });
$rootScope.$on('Local/EnableNotifications', function(event) { $rootScope.$on('Local/SubscribeNotifications', function(event) {
pushNotificationsService.enableNotifications(); pushNotificationsService.enableNotifications();
}); });
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId) {
pushNotificationsService.unsubscribe(walletId);
});
self.debouncedUpdate = lodash.throttle(function() { self.debouncedUpdate = lodash.throttle(function() {
self.updateAll({ self.updateAll({
quiet: true quiet: true

View file

@ -326,6 +326,8 @@ angular.module('copayApp.services')
if (err) $log.warn(err); if (err) $log.warn(err);
}); });
$rootScope.$emit('Local/UnsubscribeNotifications', walletId);
$timeout(function() { $timeout(function() {
root.setWalletClients(); root.setWalletClients();
root.setAndStoreFocus(null, function() { root.setAndStoreFocus(null, function() {
@ -397,7 +399,7 @@ angular.module('copayApp.services')
handleImport(function() { handleImport(function() {
root.setAndStoreFocus(walletId, function() { root.setAndStoreFocus(walletId, function() {
storageService.storeProfile(root.profile, function(err) { storageService.storeProfile(root.profile, function(err) {
$rootScope.$emit('Local/EnableNotifications'); $rootScope.$emit('Local/SubscribeNotifications');
return cb(err, walletId); return cb(err, walletId);
}); });
}); });

View file

@ -42,7 +42,7 @@ angular.module('copayApp.services')
root.enableNotifications = function() { root.enableNotifications = function() {
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
lodash.forEach(profileService.getWallets('livenet'), function(wallets) { lodash.forEach(profileService.getWallets('testnet'), function(wallets) {
var opts = {}; var opts = {};
opts.user = wallets.id; opts.user = wallets.id;
opts.type = (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "ios" : (navigator.userAgent.match(/Android/i)) == "Android" ? "android" : null; opts.type = (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "ios" : (navigator.userAgent.match(/Android/i)) == "Android" ? "android" : null;
@ -60,7 +60,7 @@ angular.module('copayApp.services')
root.disableNotifications = function() { root.disableNotifications = function() {
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
root.unsubscribe(token).then(function(response) { root.unsubscribeAll(token).then(function(response) {
$log.debug('Unsubscribed: ' + response.status); $log.debug('Unsubscribed: ' + response.status);
}, },
function(err) { function(err) {
@ -70,11 +70,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('http://192.168.1.121:8000/subscribe', opts);
} }
root.unsubscribe = function(token) { root.unsubscribe = function(user) {
return $http.post('http://192.168.1.128:8000/unsubscribe', { return $http.post('http://192.168.1.121:8000/unsubscribe', {
user: user
});
}
root.unsubscribeAll = function(token) {
return $http.post('http://192.168.1.121:8000/unsubscribe', {
token: token token: token
}); });
} }