unsubscribe method refactor
This commit is contained in:
parent
d8cfb9dd5c
commit
58b573ac4e
3 changed files with 42 additions and 35 deletions
|
|
@ -1288,10 +1288,13 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
pushNotificationsService.enableNotifications();
|
pushNotificationsService.enableNotifications();
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/UnsubscribeNotifications', function(event) {
|
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) {
|
||||||
pushNotificationsService.unsubscribe(null, function(err, response) {
|
storageService.getDeviceToken(function(err, token) {
|
||||||
|
pushNotificationsService.unsubscribe(token, walletId, function(err, response) {
|
||||||
if (err) $log.warn('Error: ' + err.code);
|
if (err) $log.warn('Error: ' + err.code);
|
||||||
$log.debug('Unsubscribed: ' + response);
|
$log.debug('Unsubscribed: ' + response);
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -305,7 +305,8 @@ angular.module('copayApp.services')
|
||||||
var fc = root.focusedClient;
|
var fc = root.focusedClient;
|
||||||
var walletId = fc.credentials.walletId;
|
var walletId = fc.credentials.walletId;
|
||||||
|
|
||||||
$rootScope.$emit('Local/UnsubscribeNotifications');
|
$rootScope.$emit('Local/UnsubscribeNotifications', walletId, function() {
|
||||||
|
|
||||||
$log.debug('Deleting Wallet:', fc.credentials.walletName);
|
$log.debug('Deleting Wallet:', fc.credentials.walletName);
|
||||||
|
|
||||||
fc.removeAllListeners();
|
fc.removeAllListeners();
|
||||||
|
|
@ -337,6 +338,7 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setMetaData = function(walletClient, addressBook, historyCache, cb) {
|
root.setMetaData = function(walletClient, addressBook, historyCache, cb) {
|
||||||
|
|
|
||||||
|
|
@ -32,11 +32,11 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.enableNotifications = function() {
|
root.enableNotifications = function() {
|
||||||
storageService.getDeviceToken(function(err, token) {
|
storageService.getDeviceToken(function(err, token) {
|
||||||
lodash.forEach(profileService.getWallets('testnet'), function(wallets) {
|
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||||
var opts = {};
|
var opts = {};
|
||||||
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
opts.type = isMobile.iOS() ? "ios" : isMobile.Android() ? "android" : null;
|
||||||
opts.token = token;
|
opts.token = token;
|
||||||
root.subscribe(opts, wallets.id, function(err, response) {
|
root.subscribe(opts, wallet.id, function(err, response) {
|
||||||
if (err) $log.warn('Error: ' + err.code);
|
if (err) $log.warn('Error: ' + err.code);
|
||||||
$log.debug('Suscribed: ' + JSON.stringify(response));
|
$log.debug('Suscribed: ' + JSON.stringify(response));
|
||||||
});
|
});
|
||||||
|
|
@ -46,11 +46,13 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root.disableNotifications = function() {
|
root.disableNotifications = function() {
|
||||||
storageService.getDeviceToken(function(err, token) {
|
storageService.getDeviceToken(function(err, token) {
|
||||||
root.unsubscribe(token, function(err, response) {
|
lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
|
||||||
|
root.unsubscribe(token, wallet.id, function(err, response) {
|
||||||
if (err) $log.warn('Error: ' + err.code);
|
if (err) $log.warn('Error: ' + err.code);
|
||||||
$log.debug('Unsubscribed: ' + response);
|
$log.debug('Unsubscribed: ' + response);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
root.subscribe = function(opts, walletId, cb) {
|
root.subscribe = function(opts, walletId, cb) {
|
||||||
|
|
@ -61,9 +63,9 @@ angular.module('copayApp.services')
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
root.unsubscribe = function(opts, cb) {
|
root.unsubscribe = function(token, walletId, cb) {
|
||||||
var walletClient = profileService.focusedClient;
|
var walletClient = profileService.getClient(walletId);
|
||||||
walletClient.pushNotificationsUnsubscribe(opts, function(err, resp) {
|
walletClient.pushNotificationsUnsubscribe(token, function(err, resp) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
return cb(null, resp);
|
return cb(null, resp);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue