add ability to unsubscribe from a single event using a dedicated link

This commit is contained in:
Matteo Pagliazzi
2015-02-23 21:25:01 +01:00
parent b010a53bed
commit 4151b0733f
3 changed files with 23 additions and 2 deletions

View File

@@ -15,6 +15,27 @@ habitrpg.controller('SettingsCtrl',
// });
// }
// A simple object to map the key stored in the db (user.preferences.emailNotification[key])
// to its string but ONLY when the preferences' key and the string key don't match
var mapPrefToEmailString = {
'importantAnnouncements': 'inactivityEmails'
};
// If ?unsubFrom param is passed with valid email type,
// automatically unsubscribe users from that email and
// show an alert
$timeout(function(){
var unsubFrom = $location.search().unsubFrom;
if(unsubFrom){
var emailPrefKey = 'preferences.emailNotifications.' + qs.unsubFrom;
var emailTypeString = env.t(mapPrefToEmailString[qs.unsubFrom] || qs.unsubFrom);
User.set({emailPrefKey: false});
User.user.preferences.emailNotifications[qs.unsubFrom] = false;
Notification.text(env.t('correctlyUnsubscribedEmailType', {emailType: emailTypeString}));
$location.search({});
}
}, 500);
$scope.hideHeader = function(){
User.set({"preferences.hideHeader":!User.user.preferences.hideHeader})
if (User.user.preferences.hideHeader && User.user.preferences.stickyHeader){