add toggle for email notifications
This commit is contained in:
parent
8c8411914d
commit
410d35495b
6 changed files with 100 additions and 49 deletions
|
|
@ -1,49 +1,62 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesNotificationsController',
|
angular.module('copayApp.controllers').controller('preferencesNotificationsController', function($scope, $log, $window, configService, platformInfo, pushNotificationsService, profileService, emailService) {
|
||||||
function($scope, $rootScope, $log, $window, lodash, configService, uxLanguage, platformInfo, pushNotificationsService, profileService, feeService) {
|
var updateConfig = function() {
|
||||||
|
$scope.appName = $window.appConfig.nameCase;
|
||||||
|
$scope.PNEnabledByUser = true;
|
||||||
|
$scope.usePushNotifications = platformInfo.isCordova && !platformInfo.isWP;
|
||||||
|
$scope.isIOSApp = platformInfo.isIOS && platformInfo.isCordova;
|
||||||
|
|
||||||
var updateConfig = function() {
|
if ($scope.isIOSApp) {
|
||||||
|
try {
|
||||||
|
PushNotification.hasPermission(function(data) {
|
||||||
|
$scope.PNEnabledByUser = data.isEnabled;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
$log.error(e);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
var isCordova = platformInfo.isCordova;
|
|
||||||
var isIOS = platformInfo.isIOS;
|
|
||||||
|
|
||||||
$scope.appName = $window.appConfig.nameCase;
|
$scope.pushNotifications = {
|
||||||
$scope.PNEnabledByUser = true;
|
value: config.pushNotifications.enabled
|
||||||
$scope.isIOSApp = isIOS && isCordova;
|
};
|
||||||
if ($scope.isIOSApp) {
|
|
||||||
try {
|
$scope.emailNotifications = {
|
||||||
PushNotification.hasPermission(function(data) {
|
value: config.emailNotifications ? config.emailNotifications.enabled : false
|
||||||
$scope.PNEnabledByUser = data.isEnabled;
|
};
|
||||||
});
|
};
|
||||||
} catch(e) {
|
|
||||||
$log.error(e);
|
$scope.pushNotificationsChange = function() {
|
||||||
};
|
if (!$scope.pushNotifications) return;
|
||||||
|
var opts = {
|
||||||
|
pushNotifications: {
|
||||||
|
enabled: $scope.pushNotifications.value
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.pushNotifications = {
|
|
||||||
value: config.pushNotifications.enabled
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
configService.set(opts, function(err) {
|
||||||
$scope.pushNotificationsChange = function() {
|
if (opts.pushNotifications.enabled)
|
||||||
if (!$scope.pushNotifications) return;
|
profileService.pushNotificationsInit();
|
||||||
var opts = {
|
else
|
||||||
pushNotifications: {
|
pushNotificationsService.disableNotifications(profileService.getWallets());
|
||||||
enabled: $scope.pushNotifications.value
|
if (err) $log.debug(err);
|
||||||
}
|
|
||||||
};
|
|
||||||
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();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, platformInfo, profileService, feeService, configService, externalLinkService) {
|
angular.module('copayApp.controllers').controller('tabSettingsController', function($scope, $window, uxLanguage, profileService, feeService, configService, externalLinkService) {
|
||||||
|
|
||||||
var updateConfig = function() {
|
var updateConfig = function() {
|
||||||
|
|
||||||
var config = configService.getSync();
|
|
||||||
var isCordova = platformInfo.isCordova;
|
|
||||||
var isWP = platformInfo.isWP;
|
|
||||||
|
|
||||||
$scope.usePushNotifications = isCordova && !isWP;
|
|
||||||
|
|
||||||
$scope.appName = $window.appConfig.nameCase;
|
$scope.appName = $window.appConfig.nameCase;
|
||||||
|
|
||||||
|
var config = configService.getSync();
|
||||||
$scope.unitName = config.wallet.settings.unitName;
|
$scope.unitName = config.wallet.settings.unitName;
|
||||||
$scope.currentLanguageName = uxLanguage.getCurrentLanguageName();
|
$scope.currentLanguageName = uxLanguage.getCurrentLanguageName();
|
||||||
$scope.selectedAlternative = {
|
$scope.selectedAlternative = {
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,10 @@ angular.module('copayApp.services').factory('configService', function(storageSer
|
||||||
windows: {},
|
windows: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emailNotifications: {
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var configCache = null;
|
var configCache = null;
|
||||||
|
|
|
||||||
36
src/js/services/emailService.js
Normal file
36
src/js/services/emailService.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
'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;
|
||||||
|
});
|
||||||
|
|
@ -10,9 +10,13 @@
|
||||||
<div ng-show="PNEnabledByUser">
|
<div ng-show="PNEnabledByUser">
|
||||||
<div class="item item-divider" translate>Notifications</div>
|
<div class="item item-divider" translate>Notifications</div>
|
||||||
|
|
||||||
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()">
|
<ion-toggle ng-model="pushNotifications.value" toggle-class="toggle-balanced" ng-change="pushNotificationsChange()" ng-show="usePushNotifications">
|
||||||
<span class="toggle-label" translate>Enable push notifications</span>
|
<span class="toggle-label" translate>Enable push notifications</span>
|
||||||
</ion-toggle>
|
</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>
|
||||||
|
|
||||||
<div ng-show="!PNEnabledByUser && isIOSApp">
|
<div ng-show="!PNEnabledByUser && isIOSApp">
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@
|
||||||
|
|
||||||
<div class="item item-divider" translate>Preferences</div>
|
<div class="item item-divider" translate>Preferences</div>
|
||||||
|
|
||||||
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications" ng-show="usePushNotifications">
|
<a class="item item-icon-left item-icon-right" ui-sref="tabs.notifications">
|
||||||
<i class="icon big-icon-svg">
|
<i class="icon big-icon-svg">
|
||||||
<img src="img/icon-notifications.svg" class="bg"/>
|
<img src="img/icon-notifications.svg" class="bg"/>
|
||||||
</i>
|
</i>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue