Unverified Commit 74018c66 authored by Eli Yukelzon's avatar Eli Yukelzon Committed by GitHub

MM-18623 - Handle reply-count in getPostThread code path (#933)

* refactored into two separate components. cleaned up css

* Revert "refactored into two separate components. cleaned up css"

This reverts commit 6784589f

* Handle reply-count in getPostThread code path
parent d3429317
......@@ -573,13 +573,13 @@ export function flagPost(postId) {
};
}
export function getPostThread(rootId) {
export function getPostThread(rootId, fetchThreads = true) {
return async (dispatch, getState) => {
dispatch({type: PostTypes.GET_POST_THREAD_REQUEST}, getState);
let posts;
try {
posts = await Client4.getPostThread(rootId);
posts = await Client4.getPostThread(rootId, fetchThreads);
getProfilesAndStatusesForPosts(posts.posts, dispatch, getState);
} catch (error) {
forceLogoutIfNecessary(error, dispatch, getState);
......@@ -764,7 +764,7 @@ export function getPostsAround(channelId, postId, perPage = Posts.POST_CHUNK_SIZ
// getThreadsForPosts is intended for an array of posts that have been batched
// (see the actions/websocket_actions/handleNewPostEvents function in the webapp)
export function getThreadsForPosts(posts) {
export function getThreadsForPosts(posts, fetchThreads = true) {
return (dispatch, getState) => {
if (!Array.isArray(posts) || !posts.length) {
return {data: true};
......@@ -780,7 +780,7 @@ export function getThreadsForPosts(posts) {
const rootPost = Selectors.getPost(state, post.root_id);
if (!rootPost) {
promises.push(dispatch(getPostThread(post.root_id)));
promises.push(dispatch(getPostThread(post.root_id, fetchThreads)));
}
});
......@@ -1132,7 +1132,7 @@ function completePostReceive(post, websocketMessageProps) {
const rootPost = Selectors.getPost(state, post.root_id);
if (post.root_id && !rootPost) {
dispatch(getPostThread(post.root_id));
dispatch(getPostThread(post.root_id, true));
}
dispatch(lastPostActions(post, websocketMessageProps));
......
......@@ -438,7 +438,7 @@ describe('Actions.Posts', () => {
};
nock(Client4.getPostsRoute()).
get(`/${post.id}/thread`).
get(`/${post.id}/thread?fetchThreads=true`).
reply(200, postList);
await Actions.getPostThread(post.id)(store.dispatch, store.getState);
......@@ -1161,7 +1161,7 @@ describe('Actions.Posts', () => {
postList.posts[post1.id] = post1;
nock(Client4.getPostsRoute()).
get(`/${post1.id}/thread`).
get(`/${post1.id}/thread?fetchThreads=true`).
reply(200, postList);
await Actions.getPostThread(post1.id)(dispatch, getState);
......@@ -1190,7 +1190,7 @@ describe('Actions.Posts', () => {
postList.posts[post1.id] = post1;
nock(Client4.getPostsRoute()).
get(`/${post1.id}/thread`).
get(`/${post1.id}/thread?fetchThreads=true`).
reply(200, postList);
await Actions.getPostThread(post1.id)(dispatch, getState);
......@@ -1625,7 +1625,7 @@ describe('Actions.Posts', () => {
};
nock(Client4.getPostsRoute()).
get(`/${post1.id}/thread`).
get(`/${post1.id}/thread?fetchThreads=true`).
reply(200, threadList);
});
......
......@@ -1575,9 +1575,9 @@ export default class Client4 {
);
};
getPostThread = async (postId) => {
getPostThread = async (postId, fetchThreads = true) => {
return this.doFetch(
`${this.getPostRoute(postId)}/thread`,
`${this.getPostRoute(postId)}/thread${buildQueryString({fetchThreads})}`,
{method: 'get'}
);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment