diff --git a/common/locales/en/settings.json b/common/locales/en/settings.json index 16720de7e1..f53105d6fe 100644 --- a/common/locales/en/settings.json +++ b/common/locales/en/settings.json @@ -99,6 +99,7 @@ "remindersToLogin": "Reminders to check in to HabitRPG", "unsubscribeAllEmails": "Check to Unsubscribe from Emails", "unsubscribeAllEmailsText": "By checking this box, I certify that I understand that by unsubscribing from all emails, HabitRPG will never be able to notify me via email about important changes to the site or my account.", + "correctlyUnsubscribedEmailType": "Correctly unsubscribed from \"<%= emailType %>\" emails.", "subscriptionRateText": "Recurring $<%= price %> every <%= months %> months", "benefits": "Benefits", "coupon": "Coupon", diff --git a/website/public/js/controllers/settingsCtrl.js b/website/public/js/controllers/settingsCtrl.js index 9789c90078..8c66e2dc1b 100644 --- a/website/public/js/controllers/settingsCtrl.js +++ b/website/public/js/controllers/settingsCtrl.js @@ -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){ diff --git a/website/src/utils.js b/website/src/utils.js index 55c47466b1..7dd110998d 100644 --- a/website/src/utils.js +++ b/website/src/utils.js @@ -56,8 +56,7 @@ module.exports.getUserInfo = getUserInfo; module.exports.txnEmail = function(mailingInfoArray, emailType, variables){ var mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray]; var variables = [ - {name: 'BASE_URL', content: baseUrl}, - {name: 'EMAIL_SETTINGS_URL', content: baseUrl + '/#/options/settings/notifications'} + {name: 'BASE_URL', content: baseUrl} ].concat(variables || []); // It's important to pass at least a user with its `preferences` as we need to check if he unsubscribed