diff --git a/src/rtk/features/posts/postsSlice.ts b/src/rtk/features/posts/postsSlice.ts index 8d47fc1ad..5ec2822fd 100644 --- a/src/rtk/features/posts/postsSlice.ts +++ b/src/rtk/features/posts/postsSlice.ts @@ -459,17 +459,10 @@ export const fetchProfilePosts = createAsyncThunk< ThunkApiConfig >( 'posts/fetchManyByAddress', - async ({ - id, - spaceId, - client, - additionalData, - withHidden, - dispatch, - api, - limit, - offset, - }): Promise => { + async ( + { id, spaceId, client, additionalData, withHidden, dispatch, api, limit, offset }, + { getState }, + ): Promise => { const address = id as AccountId if (!client) return [] @@ -495,6 +488,52 @@ export const fetchProfilePosts = createAsyncThunk< const entities = await changePostsContentId(posts) + const newIds = entities.map(x => x.id) + + if (isClientSide()) { + dispatch(fetchPostRewards({ postIds: newIds as string[] })) + dispatch(fetchPostsViewCount({ postIds: newIds as string[] })) + } + const fetches: Promise[] = [ + dispatch(fetchSuperLikeCounts({ postIds: newIds as string[] })), + dispatch(fetchCanPostsSuperLiked({ postIds: newIds as string[] })), + // need to wait for this to be fetched before any post is rendered + dispatch(fetchBlockedResources({ appId })), + ] + + const alreadyLoadedIds = new Set(newIds) + const extPostIds = new Set() + + const addToExtPostIds = (id: PostId) => { + if (id && !alreadyLoadedIds.has(id)) { + extPostIds.add(id) + } + } + + entities.forEach(x => { + if (x.isComment) { + addToExtPostIds(asCommentStruct(x).rootPostId) + } else if (x.isSharedPost) { + addToExtPostIds(asSharedPostStruct(x).originalPostId) + } + }) + + const newExtIds = selectUnknownPostIds(getState(), Array.from(extPostIds), true) + + fetches.push( + dispatch( + fetchPosts({ + api, + ids: newExtIds, + withRootPost: false, + withContent, + reload: true, + }), + ), + ) + + await Promise.all(fetches) + await handleAfterDataFetch({ entities, args: {