Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function isConsecutivePost(state, ownProps) {
const post = ownProps.post;
const previousPost = ownProps.previousPostId && getPost(state, ownProps.previousPostId);
let consecutivePost = false;
if (previousPost) {
const postFromWebhook = Boolean(post.props && post.props.from_webhook);
const prevPostFromWebhook = Boolean(previousPost.props && previousPost.props.from_webhook);
if (previousPost && previousPost.user_id === post.user_id &&
post.create_at - previousPost.create_at <= Posts.POST_COLLAPSE_TIMEOUT &&
!postFromWebhook && !prevPostFromWebhook &&
!isSystemMessage(post) && !isSystemMessage(previousPost) &&
(previousPost.root_id === post.root_id || previousPost.id === post.root_id)) {
// The last post and this post were made by the same user within some time
consecutivePost = true;
}
}
return consecutivePost;
return function mapStateToProps(state, ownProps) {
const post = ownProps.post || getPost(state, ownProps.postId);
const previousPost = getPost(state, ownProps.previousPostId);
const beforePrevPost = getPost(state, ownProps.beforePrevPostId);
const myPreferences = getMyPreferences(state);
const currentUserId = getCurrentUserId(state);
const user = getUser(state, post.user_id);
const isCommentMention = isPostCommentMention(state, post.id);
let isFirstReply = true;
let isLastReply = true;
let commentedOnPost = null;
if (ownProps.renderReplies && post && post.root_id) {
if (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;
return (state, ownProps) => {
const post = ownProps.post || getPost(state, ownProps.postId);
let replyCount = post.reply_count;
if (post.root_id !== '') {
const rootPost = getPost(state, post.root_id);
replyCount = rootPost ? rootPost.reply_count : 0;
}
let previousPost = null;
if (ownProps.previousPostId) {
previousPost = getPost(state, ownProps.previousPostId);
}
let consecutivePostByUser = false;
let previousPostIsComment = false;
if (previousPost) {
consecutivePostByUser = post.user_id === previousPost.user_id && // The post is by the same user
post.create_at - previousPost.create_at <= Posts.POST_COLLAPSE_TIMEOUT && // And was within a short time period
function mapStateToProps(state) {
const rhsState = getRhsState(state);
const channelId = getSelectedChannelId(state);
let channel = null;
if (channelId) {
channel = getChannel(state, channelId);
if (channel == null) {
// the permalink view is not really tied to a particular channel but still needs it
const {focusedPostId} = state.views.channel;
const post = getPost(state, focusedPostId);
// the post take some time before being available on page load
if (post != null) {
channel = getChannel(state, post.channel_id);
}
}
}
return {
isExpanded: getIsRhsExpanded(state),
isOpen: getIsRhsOpen(state),
channel,
currentUserId: getCurrentUserId(state),
postRightVisible: Boolean(getSelectedPostId(state)),
postCardVisible: Boolean(getSelectedPostCardId(state)),
searchVisible: Boolean(rhsState) && rhsState !== RHSStates.PLUGIN,
const myPreferences = getMyPreferences(state);
const currentUserId = getCurrentUserId(state);
const user = getUser(state, post.user_id);
const isCommentMention = isPostCommentMention(state, post.id);
let isFirstReply = true;
let isLastReply = true;
let commentedOnPost = null;
if (ownProps.renderReplies && post && post.root_id) {
if (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 {
channelIsReadOnly: isChannelReadOnlyById(state, post.channel_id),
currentUserId,
post,
chunk = getUnreadPostsChunk(state, ownProps.channelId, ownProps.unreadChunkTimeStamp);
} else {
chunk = getRecentPostsChunkInChannel(state, ownProps.channelId);
}
if (chunk) {
postIds = chunk.order;
atLatestPost = chunk.recent;
atOldestPost = chunk.oldest;
}
if (postIds) {
formattedPostIds = preparePostIdsForPostList(state, {postIds, lastViewedAt, indicateNewMessages: true});
if (postIds.length) {
const latestPostId = memoizedGetLatestPostId(postIds);
const latestPost = getPost(state, latestPostId);
latestPostTimeStamp = latestPost.create_at;
latestAriaLabelFunc = createAriaLabelForPost(state, latestPost);
}
}
return {
lastViewedAt,
isFirstLoad: isFirstLoad(state, ownProps.channelId),
formattedPostIds,
atLatestPost,
atOldestPost,
focusedPostId: ownProps.match.params.postid,
latestPostTimeStamp,
postListIds: postIds,
latestAriaLabelFunc,
};
return function mapStateToProps(state) {
const {currentFocusedPostId} = state.entities.posts;
const post = getPost(state, currentFocusedPostId);
let channel;
let postIds;
if (post) {
channel = getChannel(state, {id: post.channel_id});
postIds = getPostIdsAroundPost(state, currentFocusedPostId, post.channel_id, {
postsBeforeCount: 10,
postsAfterCount: 10,
});
}
return {
channelId: channel ? channel.id : '',
channelIsArchived: channel ? channel.delete_at !== 0 : false,
channelName: channel ? channel.display_name : '',
function addPostToSearchResults(postId, state, dispatch) {
const results = state.entities.search.results;
const index = results.indexOf(postId);
if (index === -1) {
const newPost = PostSelectors.getPost(state, postId);
const posts = getPostsForIds(state, results).reduce((acc, post) => {
acc[post.id] = post;
return acc;
}, {});
posts[newPost.id] = newPost;
const newResults = [...results, postId];
newResults.sort((a, b) => comparePosts(posts[a], posts[b]));
dispatch({
type: SearchTypes.RECEIVED_SEARCH_POSTS,
data: {posts, order: newResults},
});
}
}
return async (dispatch, getState) => {
const state = getState();
const rootPost = PostSelectors.getPost(state, post.root_id);
if (post.root_id && !rootPost) {
const {data: posts} = await dispatch(PostActions.getPostThread(post.root_id));
if (posts) {
dispatch(lastPostActions(post, websocketMessageProps));
}
return;
}
dispatch(lastPostActions(post, websocketMessageProps));
};
}
function mapStateToProps(state, ownProps) {
const post = getPost(state, ownProps.postId) || {};
let channelType = '';
if (post && post.channel_id) {
const channel = getChannel(state, post.channel_id);
if (channel && channel.type) {
channelType = channel.type;
}
}
return {
channelType,
currentUser: getCurrentUser(state),
post,
};
}