Prevent notify props from causing a crash (#1127)
This commit is contained in:
parent
2dcf7a01d0
commit
c42e2276a2
9 changed files with 45 additions and 15 deletions
|
|
@ -11,9 +11,8 @@ import {handleUpdateUserNotifyProps} from 'app/actions/views/account_notificatio
|
||||||
|
|
||||||
import NotificationSettings from './notification_settings';
|
import NotificationSettings from './notification_settings';
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
...ownProps,
|
|
||||||
config: state.entities.general.config,
|
config: state.entities.general.config,
|
||||||
currentUser: getCurrentUser(state),
|
currentUser: getCurrentUser(state),
|
||||||
myPreferences: getMyPreferences(state),
|
myPreferences: getMyPreferences(state),
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import {RadioButton, RadioButtonGroup} from 'app/components/radio_button';
|
||||||
import StatusBar from 'app/components/status_bar';
|
import StatusBar from 'app/components/status_bar';
|
||||||
import NotificationPreferences from 'app/notification_preferences';
|
import NotificationPreferences from 'app/notification_preferences';
|
||||||
import SettingsItem from 'app/screens/settings/settings_item';
|
import SettingsItem from 'app/screens/settings/settings_item';
|
||||||
|
import {getNotificationProps} from 'app/utils/notify_props';
|
||||||
import {preventDoubleTap} from 'app/utils/tap';
|
import {preventDoubleTap} from 'app/utils/tap';
|
||||||
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
|
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
|
||||||
|
|
||||||
|
|
@ -154,7 +155,7 @@ class NotificationSettings extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.saveNotificationProps({
|
this.saveNotificationProps({
|
||||||
...currentUser.notify_props,
|
...getNotificationProps(currentUser),
|
||||||
email,
|
email,
|
||||||
interval
|
interval
|
||||||
});
|
});
|
||||||
|
|
@ -165,7 +166,7 @@ class NotificationSettings extends PureComponent {
|
||||||
const {currentUser} = this.props;
|
const {currentUser} = this.props;
|
||||||
const {user_id} = notifyProps;
|
const {user_id} = notifyProps;
|
||||||
const previousProps = {
|
const previousProps = {
|
||||||
...currentUser.notify_props,
|
...getNotificationProps(currentUser),
|
||||||
user_id
|
user_id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -184,7 +185,7 @@ class NotificationSettings extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
const {config, currentUser, intl, myPreferences} = this.props;
|
const {config, currentUser, intl, myPreferences} = this.props;
|
||||||
const notifyProps = currentUser.notify_props || {};
|
const notifyProps = getNotificationProps(currentUser);
|
||||||
const sendEmailNotifications = config.SendEmailNotifications === 'true';
|
const sendEmailNotifications = config.SendEmailNotifications === 'true';
|
||||||
const emailBatchingEnabled = sendEmailNotifications && config.EnableEmailBatching === 'true';
|
const emailBatchingEnabled = sendEmailNotifications && config.EnableEmailBatching === 'true';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,8 @@ import {getMyPreferences, getTheme} from 'mattermost-redux/selectors/entities/pr
|
||||||
|
|
||||||
import NotificationSettingsEmail from './notification_settings_email';
|
import NotificationSettingsEmail from './notification_settings_email';
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
...ownProps,
|
|
||||||
config: getConfig(state),
|
config: getConfig(state),
|
||||||
myPreferences: getMyPreferences(state),
|
myPreferences: getMyPreferences(state),
|
||||||
theme: getTheme(state)
|
theme: getTheme(state)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {getPreferencesByCategory} from 'mattermost-redux/utils/preference_utils'
|
||||||
|
|
||||||
import FormattedText from 'app/components/formatted_text';
|
import FormattedText from 'app/components/formatted_text';
|
||||||
import StatusBar from 'app/components/status_bar';
|
import StatusBar from 'app/components/status_bar';
|
||||||
|
import {getNotificationProps} from 'app/utils/notify_props';
|
||||||
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
|
import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme';
|
||||||
|
|
||||||
import Section from 'app/screens/settings/section';
|
import Section from 'app/screens/settings/section';
|
||||||
|
|
@ -33,7 +34,7 @@ export default class NotificationSettingsEmail extends PureComponent {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const {currentUser} = props;
|
const {currentUser} = props;
|
||||||
const notifyProps = currentUser.notify_props || {};
|
const notifyProps = getNotificationProps(currentUser);
|
||||||
|
|
||||||
props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
|
props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
|
||||||
this.state = this.setStateFromNotifyProps(notifyProps);
|
this.state = this.setStateFromNotifyProps(notifyProps);
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
|
||||||
|
|
||||||
import NotificationSettingsMentions from './notification_settings_mentions';
|
import NotificationSettingsMentions from './notification_settings_mentions';
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
...ownProps,
|
|
||||||
theme: getTheme(state)
|
theme: getTheme(state)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import {PureComponent} from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {intlShape} from 'react-intl';
|
import {intlShape} from 'react-intl';
|
||||||
|
|
||||||
|
import {getNotificationProps} from 'app/utils/notify_props';
|
||||||
|
|
||||||
export default class NotificationSettingsMentionsBase extends PureComponent {
|
export default class NotificationSettingsMentionsBase extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
currentUser: PropTypes.object.isRequired,
|
currentUser: PropTypes.object.isRequired,
|
||||||
|
|
@ -18,7 +20,7 @@ export default class NotificationSettingsMentionsBase extends PureComponent {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const {currentUser} = props;
|
const {currentUser} = props;
|
||||||
const notifyProps = currentUser.notify_props || {};
|
const notifyProps = getNotificationProps(currentUser);
|
||||||
|
|
||||||
props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
|
props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
|
||||||
|
|
||||||
|
|
@ -43,7 +45,7 @@ export default class NotificationSettingsMentionsBase extends PureComponent {
|
||||||
mentionKeys.splice(usernameMentionIndex, 1);
|
mentionKeys.splice(usernameMentionIndex, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const comments = notifyProps.comments || 'never';
|
const comments = notifyProps.comments || 'any';
|
||||||
|
|
||||||
const newState = {
|
const newState = {
|
||||||
...notifyProps,
|
...notifyProps,
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,8 @@ import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
|
||||||
|
|
||||||
import NotificationSettingsMentionsKeywords from './notification_settings_mentions_keywords';
|
import NotificationSettingsMentionsKeywords from './notification_settings_mentions_keywords';
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
...ownProps,
|
|
||||||
theme: getTheme(state)
|
theme: getTheme(state)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ import {Platform} from 'react-native';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import {intlShape} from 'react-intl';
|
import {intlShape} from 'react-intl';
|
||||||
|
|
||||||
|
import {getNotificationProps} from 'app/utils/notify_props';
|
||||||
|
|
||||||
export default class NotificationSettingsMobileBase extends PureComponent {
|
export default class NotificationSettingsMobileBase extends PureComponent {
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
config: PropTypes.object.isRequired,
|
config: PropTypes.object.isRequired,
|
||||||
|
|
@ -21,7 +23,7 @@ export default class NotificationSettingsMobileBase extends PureComponent {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const {currentUser} = props;
|
const {currentUser} = props;
|
||||||
const notifyProps = currentUser.notify_props || {};
|
const notifyProps = getNotificationProps(currentUser);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
...notifyProps,
|
...notifyProps,
|
||||||
|
|
|
||||||
28
app/utils/notify_props.js
Normal file
28
app/utils/notify_props.js
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
export function getNotificationProps(user) {
|
||||||
|
if (user && user.notify_props) {
|
||||||
|
return user.notify_props;
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = {
|
||||||
|
channel: 'true',
|
||||||
|
comments: 'any',
|
||||||
|
desktop: 'all',
|
||||||
|
desktop_sound: 'true',
|
||||||
|
email: 'true',
|
||||||
|
mention_keys: user ? `${user.username},@${user.username}` : '',
|
||||||
|
push: 'mention',
|
||||||
|
push_status: 'online'
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!user || !user.first_name) {
|
||||||
|
props.first_name = 'false';
|
||||||
|
} else {
|
||||||
|
props.first_name = 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue