PLT-7256: Fix email rate selection when batching is disabled (#7202)

Этот коммит содержится в:
atp
2017-08-21 19:30:40 +05:30
коммит произвёл Harrison Healey
родитель 22efdbe6fb
Коммит 2986c38469
2 изменённых файлов: 39 добавлений и 17 удалений

Просмотреть файл

@@ -31,17 +31,9 @@ export default class EmailNotificationSetting extends React.Component {
this.expand = this.expand.bind(this); this.expand = this.expand.bind(this);
this.collapse = this.collapse.bind(this); this.collapse = this.collapse.bind(this);
if (global.mm_config.EnableEmailBatching === 'true') { this.state = {
// when email batching is enabled, the default interval is 15 minutes emailInterval: EmailNotificationSetting.getEmailInterval(props)
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)
};
}
} }
handleChange(enableEmail, emailInterval) { handleChange(enableEmail, emailInterval) {
@@ -156,7 +148,7 @@ export default class EmailNotificationSetting extends React.Component {
id='emailNotificationMinutes' id='emailNotificationMinutes'
type='radio' type='radio'
name='emailNotifications' 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)} onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_FIFTEEN_MINUTES)}
/> />
<FormattedMessage <FormattedMessage
@@ -172,7 +164,7 @@ export default class EmailNotificationSetting extends React.Component {
id='emailNotificationHour' id='emailNotificationHour'
type='radio' type='radio'
name='emailNotifications' name='emailNotifications'
checked={this.props.enableEmail && this.state.emailInterval === Preferences.INTERVAL_HOUR} checked={this.state.emailInterval === Preferences.INTERVAL_HOUR}
onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_HOUR)} onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_HOUR)}
/> />
<FormattedMessage <FormattedMessage
@@ -209,7 +201,7 @@ export default class EmailNotificationSetting extends React.Component {
id='emailNotificationImmediately' id='emailNotificationImmediately'
type='radio' type='radio'
name='emailNotifications' name='emailNotifications'
checked={this.props.enableEmail && this.state.emailInterval === Preferences.INTERVAL_IMMEDIATE} checked={this.state.emailInterval === Preferences.INTERVAL_IMMEDIATE}
onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_IMMEDIATE)} onChange={this.handleChange.bind(this, 'true', Preferences.INTERVAL_IMMEDIATE)}
/> />
<FormattedMessage <FormattedMessage
@@ -225,8 +217,8 @@ export default class EmailNotificationSetting extends React.Component {
id='emailNotificationNever' id='emailNotificationNever'
type='radio' type='radio'
name='emailNotifications' name='emailNotifications'
checked={!this.props.enableEmail} checked={this.state.emailInterval === Preferences.INTERVAL_NEVER}
onChange={this.handleChange.bind(this, 'false', Preferences.INTERVAL_IMMEDIATE)} onChange={this.handleChange.bind(this, 'false', Preferences.INTERVAL_NEVER)}
/> />
<FormattedMessage <FormattedMessage
id='user.settings.notifications.email.never' id='user.settings.notifications.email.never'
@@ -254,4 +246,33 @@ export default class EmailNotificationSetting extends React.Component {
/> />
); );
} }
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;
}
} }

Просмотреть файл

@@ -59,7 +59,8 @@ export const Preferences = {
EMAIL_INTERVAL: 'email_interval', EMAIL_INTERVAL: 'email_interval',
INTERVAL_IMMEDIATE: 30, // "immediate" is a 30 second interval INTERVAL_IMMEDIATE: 30, // "immediate" is a 30 second interval
INTERVAL_FIFTEEN_MINUTES: 15 * 60, INTERVAL_FIFTEEN_MINUTES: 15 * 60,
INTERVAL_HOUR: 60 * 60 INTERVAL_HOUR: 60 * 60,
INTERVAL_NEVER: 0
}; };
export const ActionTypes = keyMirror({ export const ActionTypes = keyMirror({