same condition apply repost visibility
MATCH (me:User {publicId: '9995055351656468'})
Call {
WITH me
MATCH (me)-[:POSTED]->(post:Post)
MATCH (user:User)-[:POSTED]->(post)
WHERE user = me OR user.publicId = post.userId
RETURN user, post
UNION
WITH me
MATCH (user:User)-[:POSTED]->(post:Post {visibility: 'public'})
RETURN user, post
UNION
WITH me
MATCH (me)-[:FOLLOWS]->(follower:User)-[:POSTED]->(post:Post)
RETURN follower as user, post
}
MATCH (user:User)-[:SHARE]->(p:Post)-[r:REPOSTED]->(p1:Post)
WHERE r.userId = user.publicId AND p.postId = p1.postId
RETURN user AS rePostUser, null AS rePost
WITH rePostUser, rePost
with DISTINCT me, user, post
WITH user, post, CASE
WHEN post.visibility = 'onlyme' AND post.userId = me.publicId THEN true
WHEN post.visibility = 'specific' AND (post.userId = me.publicId OR (post)<-[:SHOULD_SEE]-(me)) THEN true
WHEN post.visibility = 'followers' OR post.visibility = 'public' THEN true
ELSE false
END AS canSeePost
WHERE canSeePost
WITH user, post
ORDER BY post.createdAt DESC
SKIP 0
LIMIT 1
RETURN COLLECT({
post: post,
content: [(post)-[:HAS_CONTENT]->(content:PostContent)|content],
user: user,
rePostInfo: CASE WHEN user IS NOT NULL THEN { post: properties(post), rePostUser: properties(user) } ELSE {} END,
taggedUsers: [(post)-[:TAG_IN]->(tags:User)|tags],
specificUser: [(post)<-[:SHOULD_SEE]-(specificUser:User) | specificUser]
}) AS posts