Skip to content

Commit

Permalink
Merge pull request #408 from dappforce/fix-shared-posts
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel authored Apr 21, 2024
2 parents 2264589 + 6c1907c commit 4a63204
Showing 1 changed file with 50 additions and 11 deletions.
61 changes: 50 additions & 11 deletions src/rtk/features/posts/postsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,10 @@ export const fetchProfilePosts = createAsyncThunk<
ThunkApiConfig
>(
'posts/fetchManyByAddress',
async ({
id,
spaceId,
client,
additionalData,
withHidden,
dispatch,
api,
limit,
offset,
}): Promise<PostStruct[]> => {
async (
{ id, spaceId, client, additionalData, withHidden, dispatch, api, limit, offset },
{ getState },
): Promise<PostStruct[]> => {
const address = id as AccountId

if (!client) return []
Expand All @@ -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<any>[] = [
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<PostId>()

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: {
Expand Down

0 comments on commit 4a63204

Please sign in to comment.