diff --git a/src/mastodon_api/accounts/views.rs b/src/mastodon_api/accounts/views.rs index c5dc766..405ea29 100644 --- a/src/mastodon_api/accounts/views.rs +++ b/src/mastodon_api/accounts/views.rs @@ -187,7 +187,7 @@ async fn get_account_statuses( Some(auth) => Some(get_current_user(db_client, auth.token()).await?), None => None, }; - let mut posts = get_posts_by_author(db_client, &account_id).await?; + let mut posts = get_posts_by_author(db_client, &account_id, false).await?; if let Some(user) = maybe_current_user { get_actions_for_posts( db_client, diff --git a/src/models/posts/queries.rs b/src/models/posts/queries.rs index 7b4caa4..c5bf262 100644 --- a/src/models/posts/queries.rs +++ b/src/models/posts/queries.rs @@ -53,8 +53,14 @@ pub async fn get_posts( pub async fn get_posts_by_author( db_client: &impl GenericClient, account_id: &Uuid, + include_replies: bool, ) -> Result, DatabaseError> { - let rows = db_client.query( + let condition = if include_replies { + "post.author_id = $1" + } else { + "post.author_id = $1 AND post.in_reply_to_id IS NULL" + }; + let statement = format!( " SELECT post, actor_profile, @@ -64,10 +70,13 @@ pub async fn get_posts_by_author( ) AS attachments FROM post JOIN actor_profile ON post.author_id = actor_profile.id - WHERE - post.author_id = $1 + WHERE {condition} ORDER BY post.created_at DESC ", + condition=condition, + ); + let rows = db_client.query( + statement.as_str(), &[&account_id], ).await?; let posts: Vec = rows.iter()