From 8f2b8f3cc31f58503541e73d17ce09d28e654a46 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Tue, 14 Apr 2020 18:59:43 +0200 Subject: [PATCH] Automated cherry pick of #4150 (#4152) * Ensure postProps is not null/undefined * Disable camelcase check Co-authored-by: Miguel Alatzar Co-authored-by: Miguel Alatzar --- app/components/post_body/index.js | 4 ++-- app/components/post_body/post_body.js | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/app/components/post_body/index.js b/app/components/post_body/index.js index a5594e77a..77e7d0c07 100644 --- a/app/components/post_body/index.js +++ b/app/components/post_body/index.js @@ -80,8 +80,8 @@ export function makeMapStateToProps() { const customEmojis = getCustomEmojisByName(state); const {isEmojiOnly, shouldRenderJumboEmoji} = memoizeHasEmojisOnly(post.message, customEmojis); const systemMessage = isSystemMessage(post); - const postProps = post.props; - if (systemMessage && !post.props?.username) { + const postProps = post.props || {}; + if (systemMessage && !postProps.username) { const owner = getUser(state, post.user_id); postProps.username = owner?.username || ''; } diff --git a/app/components/post_body/post_body.js b/app/components/post_body/post_body.js index 7ed1c901f..3dc7b00c2 100644 --- a/app/components/post_body/post_body.js +++ b/app/components/post_body/post_body.js @@ -1,6 +1,8 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +/* eslint-disable camelcase */ + import React, {PureComponent} from 'react'; import PropTypes from 'prop-types'; import { @@ -62,7 +64,7 @@ export default class PostBody extends PureComponent { onPermalinkPress: PropTypes.func, onPress: PropTypes.func, post: PropTypes.object.isRequired, - postProps: PropTypes.object, + postProps: PropTypes.object.isRequired, postType: PropTypes.string, replyBarStyle: PropTypes.array, showAddReaction: PropTypes.bool, @@ -79,6 +81,7 @@ export default class PostBody extends PureComponent { onPress: emptyFunction, replyBarStyle: [], message: '', + postProps: {}, }; static contextTypes = { @@ -193,21 +196,23 @@ export default class PostBody extends PureComponent { }); }; - renderAddChannelMember = (style, messageStyle, textStyles) => { + renderAddChannelMember = (messageStyle, textStyles) => { const {onPress, postProps} = this.props; if (!PostAddChannelMember) { PostAddChannelMember = require('app/components/post_add_channel_member').default; } - let userIds = postProps.add_channel_member.not_in_channel_user_ids; - let usernames = postProps.add_channel_member.not_in_channel_usernames; + const postId = postProps.add_channel_member.post_id; + const noGroupsUsernames = postProps.add_channel_member?.not_in_groups_usernames; + let userIds = postProps.add_channel_member?.not_in_channel_user_ids; + let usernames = postProps.add_channel_member?.not_in_channel_usernames; if (!userIds) { - userIds = postProps.add_channel_member.user_ids; + userIds = postProps.add_channel_member?.user_ids; } if (!usernames) { - usernames = postProps.add_channel_member.usernames; + usernames = postProps.add_channel_member?.usernames; } return ( @@ -215,10 +220,10 @@ export default class PostBody extends PureComponent { baseTextStyle={messageStyle} onPostPress={onPress} textStyles={textStyles} - postId={postProps.add_channel_member.post_id} + postId={postId} userIds={userIds} usernames={usernames} - noGroupsUsernames={postProps.add_channel_member.not_in_groups_usernames} + noGroupsUsernames={noGroupsUsernames} /> ); }; @@ -368,7 +373,7 @@ export default class PostBody extends PureComponent { /> ); } else if (isPostAddChannelMember) { - messageComponent = this.renderAddChannelMember(style, messageStyle, textStyles); + messageComponent = this.renderAddChannelMember(messageStyle, textStyles); } else if (postType === Posts.POST_TYPES.COMBINED_USER_ACTIVITY) { const {allUserIds, allUsernames, messageData} = postProps.user_activity; messageComponent = (