From 294e2f201b317d66931598c89e8931610932a50b Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 19 Nov 2021 18:22:24 +0000 Subject: [PATCH] Hide private posts from home timeline, show replies --- src/models/posts/queries.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index d5f8545..701e26c 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -35,7 +35,7 @@ pub async fn get_home_timeline( current_user_id: &Uuid, ) -> Result, DatabaseError> { // Select posts from follows + own posts. - // Do not select replies + // Exclude direct messages where current user is not mentioned. let statement = format!( " SELECT @@ -45,18 +45,25 @@ pub async fn get_home_timeline( FROM post JOIN actor_profile ON post.author_id = actor_profile.id WHERE - post.in_reply_to_id IS NULL - AND ( + ( post.author_id = $1 OR EXISTS ( SELECT 1 FROM relationship 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 ", related_attachments=RELATED_ATTACHMENTS, related_mentions=RELATED_MENTIONS, + visibility_public=i16::from(&Visibility::Public), ); let rows = db_client.query( statement.as_str(),