From 2986c384690951b2e87c016efaa6f447d844e6b2 Mon Sep 17 00:00:00 2001 From: atp Date: Mon, 21 Aug 2017 19:30:40 +0530 Subject: PLT-7256: Fix email rate selection when batching is disabled (#7202) --- .../user_settings/email_notification_setting.jsx | 53 +++++++++++++++------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'webapp/components') diff --git a/webapp/components/user_settings/email_notification_setting.jsx b/webapp/components/user_settings/email_notification_setting.jsx index 5abdc3384..bbde40fa1 100644 --- a/webapp/components/user_settings/email_notification_setting.jsx +++ b/webapp/components/user_settings/email_notification_setting.jsx @@ -31,17 +31,9 @@ export default class EmailNotificationSetting extends React.Component { this.expand = this.expand.bind(this); this.collapse = this.collapse.bind(this); - if (global.mm_config.EnableEmailBatching === 'true') { - // when email batching is enabled, the default interval is 15 minutes - this.state = { - emailInterval: PreferenceStore.getInt(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, Preferences.INTERVAL_FIFTEEN_MINUTES) - }; - } else { - // otherwise, the default interval is immediately - this.state = { - emailInterval: PreferenceStore.getInt(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, Preferences.INTERVAL_IMMEDIATE) - }; - } + this.state = { + emailInterval: EmailNotificationSetting.getEmailInterval(props) + }; } handleChange(enableEmail, emailInterval) { @@ -156,7 +148,7 @@ export default class EmailNotificationSetting extends React.Component { id='emailNotificationMinutes' type='radio' name='emailNotifications' - checked={this.props.enableEmail && this.state.emailInterval === Preferences.INTERVAL_FIFTEEN_MINUTES} + checked={this.state.emailInterval === Preferences.INTERVAL_FIFTEEN_MINUTES} onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_FIFTEEN_MINUTES)} /> ); } + + static getEmailInterval(props) { + const validValuesWithEmailBatching = [Preferences.INTERVAL_IMMEDIATE, Preferences.INTERVAL_FIFTEEN_MINUTES, Preferences.INTERVAL_HOUR]; + const validValuesWithoutEmailBatching = [Preferences.INTERVAL_IMMEDIATE]; + + let emailInterval; + + if (global.mm_config.EnableEmailBatching === 'true') { + // when email batching is enabled, the default interval is 15 minutes + emailInterval = PreferenceStore.getInt(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, Preferences.INTERVAL_FIFTEEN_MINUTES); + + if (validValuesWithEmailBatching.indexOf(emailInterval) === -1) { + emailInterval = Preferences.INTERVAL_FIFTEEN_MINUTES; + } + } else { + // otherwise, the default interval is immediately + emailInterval = PreferenceStore.getInt(Preferences.CATEGORY_NOTIFICATIONS, Preferences.EMAIL_INTERVAL, Preferences.INTERVAL_IMMEDIATE); + + if (validValuesWithoutEmailBatching.indexOf(emailInterval) === -1) { + emailInterval = Preferences.INTERVAL_IMMEDIATE; + } + } + + if (!props.enableEmail) { + emailInterval = Preferences.INTERVAL_NEVER; + } + + return emailInterval; + } } -- cgit v1.2.3-1-g7c22