Merge pull request #3789 from gabrielbazan7/fix/registrationPushControl

adding control for non ios and android device in pushnotifications registration
This commit is contained in:
Matias Alejo Garcia 2016-01-20 17:22:32 -03:00
commit 189db76999
3 changed files with 34 additions and 24 deletions

View file

@ -103,13 +103,10 @@ if [ ! -d $PROJECT ]; then
cordova plugin add cordova-plugin-statusbar cordova plugin add cordova-plugin-statusbar
checkOK checkOK
cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin
checkOK
cordova plugin add phonegap-plugin-push@1.2.3 cordova plugin add phonegap-plugin-push@1.2.3
checkOK checkOK
cordova plugin add https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin.git --variable URL_SCHEME=bitcoin cordova plugin add cordova-plugin-customurlscheme --variable URL_SCHEME=bitcoin
checkOK checkOK
cordova plugin add cordova-plugin-inappbrowser cordova plugin add cordova-plugin-inappbrowser

View file

@ -5,6 +5,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
var SOFT_CONFIRMATION_LIMIT = 12; var SOFT_CONFIRMATION_LIMIT = 12;
self.isCordova = isCordova; self.isCordova = isCordova;
self.isChromeApp = isChromeApp; self.isChromeApp = isChromeApp;
self.usePushNotifications = isMobile.iOS() || isMobile.Android();
self.isSafari = isMobile.Safari(); self.isSafari = isMobile.Safari();
self.onGoingProcess = {}; self.onGoingProcess = {};
self.historyShowLimit = 10; self.historyShowLimit = 10;
@ -12,13 +13,11 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.prevState = 'walletHome'; self.prevState = 'walletHome';
document.addEventListener('deviceready', function() { document.addEventListener('deviceready', function() {
if (isMobile.Android() || isMobile.iOS()) { storageService.getDeviceToken(function(err, token) {
storageService.getDeviceToken(function(err, token) { $timeout(function() {
$timeout(function() { if (!token) pushNotificationsService.pushNotificationsInit();
if (!token) pushNotificationsService.pushNotificationsInit(); }, 5000);
}, 5000); });
});
}
}); });
function strip(number) { function strip(number) {
@ -1075,11 +1074,12 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
}; };
self.setUxLanguage = function() { self.setUxLanguage = function(cb) {
uxLanguage.update(function(lang) { uxLanguage.update(function(lang) {
var userLang = lang; var userLang = lang;
self.defaultLanguageIsoCode = userLang; self.defaultLanguageIsoCode = userLang;
self.defaultLanguageName = uxLanguage.getName(userLang); self.defaultLanguageName = uxLanguage.getName(userLang);
if (cb) return cb();
}); });
}; };
@ -1285,13 +1285,17 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
$rootScope.$on('Local/SubscribeNotifications', function(event) { $rootScope.$on('Local/SubscribeNotifications', function(event) {
pushNotificationsService.enableNotifications(); pushNotificationsService.enableNotifications();
}); });
$rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) { $rootScope.$on('Local/UnsubscribeNotifications', function(event, walletId, cb) {
pushNotificationsService.unsubscribe(walletId, function(err, response) { if (!self.usePushNotifications) return cb();
if (err) $log.warn('Error: ' + err.code);
$log.debug('Unsubscribed: ' + response); pushNotificationsService.unsubscribe(walletId, function(err) {
if (err) $log.warn('Subscription error: ' + err.code);
else $log.debug('Unsubscribed from push notifications service');
return cb(); return cb();
}); });
}); });
@ -1430,7 +1434,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.noFocusedWallet = true; self.noFocusedWallet = true;
self.isComplete = null; self.isComplete = null;
self.walletName = null; self.walletName = null;
self.setUxLanguage(function() {}); self.setUxLanguage();
profileService.isDisclaimerAccepted(function(v) { profileService.isDisclaimerAccepted(function(v) {
if (v) { if (v) {
go.path('import'); go.path('import');
@ -1440,7 +1444,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}); });
$rootScope.$on('Local/NewFocusedWallet', function() { $rootScope.$on('Local/NewFocusedWallet', function() {
self.setUxLanguage(function() {}); self.setUxLanguage();
self.setFocusedWallet(); self.setFocusedWallet();
self.debounceUpdateHistory(); self.debounceUpdateHistory();
self.isDisclaimerAccepted(); self.isDisclaimerAccepted();

View file

@ -3,8 +3,11 @@ angular.module('copayApp.services')
.factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) { .factory('pushNotificationsService', function($http, $log, isMobile, profileService, storageService, configService, lodash) {
var root = {}; var root = {};
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
var usePushNotifications = isMobile.iOS() || isMobile.Android();
root.pushNotificationsInit = function() { root.pushNotificationsInit = function() {
if (!usePushNotifications) return;
var push = PushNotification.init(defaults.pushNotifications.config); var push = PushNotification.init(defaults.pushNotifications.config);
push.on('registration', function(data) { push.on('registration', function(data) {
@ -31,29 +34,34 @@ angular.module('copayApp.services')
}; };
root.enableNotifications = function() { root.enableNotifications = function() {
if (!usePushNotifications) return;
storageService.getDeviceToken(function(err, token) { storageService.getDeviceToken(function(err, token) {
lodash.forEach(profileService.getWallets('testnet'), function(wallet) { 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, wallet.id, function(err, response) { root.subscribe(opts, wallet.id, function(err, response) {
if (err) $log.warn('Error: ' + err.code); if (err) $log.warn('Subscription error: ' + err.code);
$log.debug('Suscribed to push notifications service: ' + JSON.stringify(response)); else $log.debug('Subscribed to push notifications service: ' + JSON.stringify(response));
}); });
}); });
}); });
} }
root.disableNotifications = function() { root.disableNotifications = function() {
if (!usePushNotifications) return;
lodash.forEach(profileService.getWallets('testnet'), function(wallet) { lodash.forEach(profileService.getWallets('testnet'), function(wallet) {
root.unsubscribe(wallet.id, function(err, response) { root.unsubscribe(wallet.id, function(err) {
if (err) $log.warn('Error: ' + err.code); if (err) $log.warn('Subscription error: ' + err.code);
$log.debug('Unsubscribed from push notifications service'); else $log.debug('Unsubscribed from push notifications service');
}); });
}); });
} }
root.subscribe = function(opts, walletId, cb) { root.subscribe = function(opts, walletId, cb) {
var walletClient = profileService.getClient(walletId); var walletClient = profileService.getClient(walletId);
walletClient.pushNotificationsSubscribe(opts, function(err, resp) { walletClient.pushNotificationsSubscribe(opts, function(err, resp) {
if (err) return cb(err); if (err) return cb(err);
@ -62,10 +70,11 @@ angular.module('copayApp.services')
} }
root.unsubscribe = function(walletId, cb) { root.unsubscribe = function(walletId, cb) {
var walletClient = profileService.getClient(walletId); var walletClient = profileService.getClient(walletId);
walletClient.pushNotificationsUnsubscribe(function(err, resp) { walletClient.pushNotificationsUnsubscribe(function(err) {
if (err) return cb(err); if (err) return cb(err);
return cb(null, resp); return cb(null);
}); });
} }