summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-09-05 23:13:39 +0800
committerGitHub <noreply@github.com>2017-09-05 23:13:39 +0800
commitdaed8ffbf6151f01866b9299574fdf6764c8b7bd (patch)
tree75bf94c67db772a5344169a671d83dfc21c1efaa /webapp/utils
parentd6383643cb9f60e0429d09c1d363b7781da15e47 (diff)
downloadchat-daed8ffbf6151f01866b9299574fdf6764c8b7bd.tar.gz
chat-daed8ffbf6151f01866b9299574fdf6764c8b7bd.tar.bz2
chat-daed8ffbf6151f01866b9299574fdf6764c8b7bd.zip
fix email notifications settings appearing save despite cancel (#7359)
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/utils.jsx38
1 files changed, 38 insertions, 0 deletions
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index aa98a9872..9bfd22e07 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -1401,3 +1401,41 @@ export function removePrefixFromLocalStorage(prefix) {
localStorage.removeItem(keys[i]);
}
}
+
+export function getEmailInterval(isEmailEnabled) {
+ const {
+ INTERVAL_NEVER,
+ INTERVAL_IMMEDIATE,
+ INTERVAL_FIFTEEN_MINUTES,
+ INTERVAL_HOUR,
+ CATEGORY_NOTIFICATIONS,
+ EMAIL_INTERVAL
+ } = Constants.Preferences;
+
+ if (!isEmailEnabled) {
+ return INTERVAL_NEVER;
+ }
+
+ const validValuesWithEmailBatching = [INTERVAL_IMMEDIATE, INTERVAL_FIFTEEN_MINUTES, INTERVAL_HOUR];
+ const validValuesWithoutEmailBatching = [INTERVAL_IMMEDIATE];
+
+ let emailInterval;
+
+ if (global.mm_config.EnableEmailBatching === 'true') {
+ // when email batching is enabled, the default interval is 15 minutes
+ emailInterval = PreferenceStore.getInt(CATEGORY_NOTIFICATIONS, EMAIL_INTERVAL, INTERVAL_FIFTEEN_MINUTES);
+
+ if (validValuesWithEmailBatching.indexOf(emailInterval) === -1) {
+ emailInterval = INTERVAL_FIFTEEN_MINUTES;
+ }
+ } else {
+ // otherwise, the default interval is immediately
+ emailInterval = PreferenceStore.getInt(CATEGORY_NOTIFICATIONS, EMAIL_INTERVAL, INTERVAL_IMMEDIATE);
+
+ if (validValuesWithoutEmailBatching.indexOf(emailInterval) === -1) {
+ emailInterval = INTERVAL_IMMEDIATE;
+ }
+ }
+
+ return emailInterval;
+}