From ee15776a06746d6b4eca1c6d961d8811cff4cf06 Mon Sep 17 00:00:00 2001 From: CJ <38697367+imisshtml@users.noreply.github.com> Date: Mon, 13 Jan 2020 10:23:10 -0500 Subject: [PATCH] MM-21230 Added check for first post (#3786) * MM-21230 Added check for first post Added a check to see if there was an original postId to validate the moreMessages check. * Added comment --- app/components/post_list/post_list.js | 49 +++++++++++++++++++-------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/app/components/post_list/post_list.js b/app/components/post_list/post_list.js index cff2da529..7cc13f5be 100644 --- a/app/components/post_list/post_list.js +++ b/app/components/post_list/post_list.js @@ -248,16 +248,35 @@ export default class PostList extends PureComponent { }; renderItem = ({item, index}) => { + const { + highlightPinnedOrFlagged, + highlightPostId, + isSearchResult, + lastPostIndex, + location, + onHashtagPress, + onPostPress, + postIds, + renderReplies, + shouldRenderReplyButton, + theme, + } = this.props; + if (PostListUtils.isStartOfNewMessages(item)) { // postIds includes a date item after the new message indicator so 2 // needs to be added to the index for the length check to be correct. - const moreNewMessages = this.props.postIds.length === index + 2; + const moreNewMessages = postIds.length === index + 2; + + // The date line and new message line each count for a line. So the + // goal of this is to check for the 3rd previous, which for the start + // of a thread would be null as it doesn't exist. + const checkForPostId = index < postIds.length - 3; return ( ); } else if (PostListUtils.isDateLine(item)) { @@ -271,22 +290,22 @@ export default class PostList extends PureComponent { // Remember that the list is rendered with item 0 at the bottom so the "previous" post // comes after this one in the list - const previousPostId = index < this.props.postIds.length - 1 ? this.props.postIds[index + 1] : null; - const beforePrevPostId = index < this.props.postIds.length - 2 ? this.props.postIds[index + 2] : null; - const nextPostId = index > 0 ? this.props.postIds[index - 1] : null; + const previousPostId = index < postIds.length - 1 ? postIds[index + 1] : null; + const beforePrevPostId = index < postIds.length - 2 ? postIds[index + 2] : null; + const nextPostId = index > 0 ? postIds[index - 1] : null; const postProps = { previousPostId, nextPostId, - highlightPinnedOrFlagged: this.props.highlightPinnedOrFlagged, - isSearchResult: this.props.isSearchResult, - location: this.props.location, + highlightPinnedOrFlagged, + isSearchResult, + location, managedConfig: mattermostManaged.getCachedConfig(), - onHashtagPress: this.props.onHashtagPress, + onHashtagPress, onPermalinkPress: this.handlePermalinkPress, - onPress: this.props.onPostPress, - renderReplies: this.props.renderReplies, - shouldRenderReplyButton: this.props.shouldRenderReplyButton, + onPress: onPostPress, + renderReplies, + shouldRenderReplyButton, beforePrevPostId, }; @@ -304,8 +323,8 @@ export default class PostList extends PureComponent { return ( );