diff options
Diffstat (limited to 'webapp/utils')
-rw-r--r-- | webapp/utils/utils.jsx | 38 |
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; +} |