mattermost-mobile/app/components/post/index.js
Harrison Healey 0e4f9d5825 Changed to pass IDs to PostList instead of posts (#1036)
* Moved PostList to take a list of postIds instead of posts

* Removed usage of selectors that return posts from ChannelPostList and Thread

* Fixed search and switched to use getPostIdsAroundPost selector

* Removed use of selectors that returned posts from emoji reactions

* Updated makePreparePostIdsForPostList to be better memoized

* Fixed filter of join/leave messages

* Added unit tests for makePrepaprePostIdsForPostList

* Check if post edit/delete should be enabled more often

* Updated mattermost-redux version in yarn.lock
2017-10-20 18:58:44 -03:00

70 lines
2.2 KiB
JavaScript

// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import {connect} from 'react-redux';
import {bindActionCreators} from 'redux';
import {addReaction, createPost, deletePost, removePost} from 'mattermost-redux/actions/posts';
import {getPost} from 'mattermost-redux/selectors/entities/posts';
import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import Post from './post';
function mapStateToProps(state, ownProps) {
const post = getPost(state, ownProps.postId);
const {config, license} = state.entities.general;
const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : '';
let isFirstReply = true;
let isLastReply = true;
let commentedOnPost = null;
if (ownProps.renderReplies && post && post.root_id) {
if (ownProps.previousPostId) {
const previousPost = getPost(state, ownProps.previousPostId);
if (previousPost && (previousPost.id === post.root_id || previousPost.root_id === post.root_id)) {
// Previous post is root post or previous post is in same thread
isFirstReply = false;
} else {
// Last post is not a comment on the same message
commentedOnPost = getPost(state, post.root_id);
}
}
if (ownProps.nextPostId) {
const nextPost = getPost(state, ownProps.nextPostId);
if (nextPost && nextPost.root_id === post.root_id) {
isLastReply = false;
}
}
}
return {
config,
currentUserId: getCurrentUserId(state),
post,
isFirstReply,
isLastReply,
commentedOnPost,
license,
roles,
theme: getTheme(state)
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
addReaction,
createPost,
deletePost,
removePost
}, dispatch)
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Post);