remove events and refactor of push notifications functions

This commit is contained in:
Gabriel Bazán 2016-01-26 14:44:17 -03:00
commit e19ece08c7
4 changed files with 25 additions and 35 deletions

View file

@ -16,7 +16,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
if (self.usePushNotifications) {
storageService.getDeviceToken(function(err, token) {
$timeout(function() {
if (!token) pushNotificationsService.pushNotificationsInit();
if (!token) pushNotificationsService.pushNotificationsInit(profileService.walletClients);
}, 5000);
});
}
@ -1285,24 +1285,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
go.walletHome();
});
$rootScope.$on('Local/SubscribeNotifications', function(event) {
if (!self.usePushNotifications) return;
$rootScope.$on('Local/ProfileCreated', function(event) {
self.updateRemotePreferences({
saveAll: true
}, function() {
$log.debug('Remote preferences saved');
pushNotificationsService.enableNotifications();
});
});
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) {
if (!self.usePushNotifications) return cb();
pushNotificationsService.unsubscribe(walletId, function(err) {
if (err) $log.warn('Subscription error: ' + err.code);
else $log.debug('Unsubscribed from push notifications service');
return cb();
});
});

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesGlobalController',
function($scope, $rootScope, $log, configService, uxLanguage, pushNotificationsService) {
function($scope, $rootScope, $log, configService, uxLanguage, pushNotificationsService, profileService) {
this.init = function() {
var config = configService.getSync();
@ -39,9 +39,9 @@ angular.module('copayApp.controllers').controller('preferencesGlobalController',
};
configService.set(opts, function(err) {
if (opts.pushNotifications.enabled)
pushNotificationsService.enableNotifications();
pushNotificationsService.enableNotifications(profileService.walletClients);
else
pushNotificationsService.disableNotifications();
pushNotificationsService.disableNotifications(profileService.walletClients);
if (err) $log.debug(err);
});
});