Merge pull request #4945 from bitpay/revert-4942-feat/email-toggle

Revert "Add toggle for email notifications"
This commit is contained in:
Jason Dreyzehner 2016-10-28 09:10:14 -07:00 committed by GitHub
commit f4017f5a7f
6 changed files with 49 additions and 100 deletions

View File

@ -1,62 +1,49 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesNotificationsController', function($scope, $log, $window, configService, platformInfo, pushNotificationsService, profileService, emailService) {
var updateConfig = function() {
$scope.appName = $window.appConfig.nameCase;
$scope.PNEnabledByUser = true;
$scope.usePushNotifications = platformInfo.isCordova && !platformInfo.isWP;
$scope.isIOSApp = platformInfo.isIOS && platformInfo.isCordova;
angular.module('copayApp.controllers').controller('preferencesNotificationsController',
function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) {
if ($scope.isIOSApp) {
try {
PushNotification.hasPermission(function(data) {
$scope.PNEnabledByUser = data.isEnabled;
});
} catch (e) {
$log.error(e);
var updateConfig = function() {
var config = configService.getSync();
var isCordova = platformInfo.isCordova;
var isIOS = platformInfo.isIOS;
$scope.appName = $window.appConfig.nameCase;
$scope.PNEnabledByUser = true;
$scope.isIOSApp = isIOS && isCordova;
if ($scope.isIOSApp) {
try {
PushNotification.hasPermission(function(data) {
$scope.PNEnabledByUser = data.isEnabled;
});
} catch(e) {
$log.error(e);
};
}
$scope.pushNotifications = {
value: config.pushNotifications.enabled
};
}
var config = configService.getSync();
$scope.pushNotifications = {
value: config.pushNotifications.enabled
};
$scope.emailNotifications = {
value: config.emailNotifications ? config.emailNotifications.enabled : false
$scope.pushNotificationsChange = function() {
if (!$scope.pushNotifications) return;
var opts = {
pushNotifications: {
enabled: $scope.pushNotifications.value
}
};
configService.set(opts, function(err) {
if (opts.pushNotifications.enabled)
profileService.pushNotificationsInit();
else
pushNotificationsService.disableNotifications(profileService.getWallets());
if (err) $log.debug(err);
});
};
};
$scope.pushNotificationsChange = function() {
if (!$scope.pushNotifications) return;
var opts = {
pushNotifications: {
enabled: $scope.pushNotifications.value
}
};
configService.set(opts, function(err) {
if (opts.pushNotifications.enabled)
profileService.pushNotificationsInit();
else
pushNotificationsService.disableNotifications(profileService.getWallets());
if (err) $log.debug(err);
$scope.$on("$ionicView.enter", function(event, data) {
updateConfig();
});
};
$scope.emailNotificationsChange = function() {
var opts = {
emailNotifications: {
enabled: $scope.emailNotifications.value
}
};
emailService.enableEmailNotifications($scope.emailNotifications.value);
configService.set(opts, function(err) {
if (err) $log.debug(err);
});
};
$scope.$on("$ionicView.enter", function(event, data) {
updateConfig();
});
});

View File

@ -1,11 +1,17 @@
'use strict';
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, profileService, feeService, configService, externalLinkService) {
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService) {
var updateConfig = function() {
$scope.appName = $window.appConfig.nameCase;
var config = configService.getSync();
var isCordova = platformInfo.isCordova;
var isWP = platformInfo.isWP;
$scope.usePushNotifications = isCordova && !isWP;
$scope.appName = $window.appConfig.nameCase;
$scope.unitName = config.wallet.settings.unitName;
$scope.currentLanguageName = uxLanguage.getCurrentLanguageName();
$scope.selectedAlternative = {

View File

@ -85,10 +85,6 @@ angular.module('copayApp.services').factory('configService', function(storageSer
windows: {},
}
},
emailNotifications: {
enabled: true,
},
};
var configCache = null;

View File

@ -1,36 +0,0 @@
'use strict';
angular.module('copayApp.services').factory('emailService', function($log, configService, profileService, lodash, walletService) {
var root = {};
root.enableEmailNotifications = function(val) {
val = val || false;
var config = configService.getSync();
if (!config.emailFor) {
$log.debug('No email configuration available');
return;
}
var keys = lodash.keys(config.emailFor);
var wallets = lodash.map(keys, function(k) {
return profileService.getWallet(k);
});
if (!wallets) {
$log.debug('No wallets found');
return;
}
lodash.each(wallets, function(w) {
walletService.updateRemotePreferences(w, {
email: val ? config.emailFor[w.credentials.walletId] : null
}, function(err) {
if (err) $log.warn(err);
});
});
};
return root;
});

View File

@ -10,13 +10,9 @@
<div ng-show="PNEnabledByUser">
<div class="item item-divider" translate>Notifications</div>
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()" ng-show="usePushNotifications">
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()">
<span class="toggle-label" translate>Enable push notifications</span>
</ion-toggle>
<ion-toggle ng-model="emailNotifications.value" toggle-class="toggle-balanced" ng-change="emailNotificationsChange()">
<span class="toggle-label" translate>Enable email notifications</span>
</ion-toggle>
</div>
<div ng-show="!PNEnabledByUser && isIOSApp">

View File

@ -39,7 +39,7 @@
<div class="item item-divider" translate>Preferences</div>
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications">
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications" ng-show="usePushNotifications">
<i class="icon big-icon-svg">
<img src="img/icon-notifications.svg" class="bg"/>
</i>