Hide private posts from home timeline, show replies

This commit is contained in:
silverpill 2021-11-19 18:22:24 +00:00
parent 5547403200
commit 294e2f201b

View file

@ -35,7 +35,7 @@ pub async fn get_home_timeline(
current_user_id: &Uuid, current_user_id: &Uuid,
) -> Result<Vec<Post>, DatabaseError> { ) -> Result<Vec<Post>, DatabaseError> {
// Select posts from follows + own posts. // Select posts from follows + own posts.
// Do not select replies // Exclude direct messages where current user is not mentioned.
let statement = format!( let statement = format!(
" "
SELECT SELECT
@ -45,18 +45,25 @@ pub async fn get_home_timeline(
FROM post FROM post
JOIN actor_profile ON post.author_id = actor_profile.id JOIN actor_profile ON post.author_id = actor_profile.id
WHERE WHERE
post.in_reply_to_id IS NULL (
AND (
post.author_id = $1 post.author_id = $1
OR EXISTS ( OR EXISTS (
SELECT 1 FROM relationship SELECT 1 FROM relationship
WHERE source_id = $1 AND target_id = post.author_id WHERE source_id = $1 AND target_id = post.author_id
) )
) )
AND (
post.visibility = {visibility_public}
OR EXISTS (
SELECT 1 FROM mention
WHERE post_id = post.id AND profile_id = $1
)
)
ORDER BY post.created_at DESC ORDER BY post.created_at DESC
", ",
related_attachments=RELATED_ATTACHMENTS, related_attachments=RELATED_ATTACHMENTS,
related_mentions=RELATED_MENTIONS, related_mentions=RELATED_MENTIONS,
visibility_public=i16::from(&Visibility::Public),
); );
let rows = db_client.query( let rows = db_client.query(
statement.as_str(), statement.as_str(),