From a62905a8c41812d4e2a8e9a5a74d14db43434246 Mon Sep 17 00:00:00 2001 From: trisua Date: Tue, 6 May 2025 16:28:07 -0400 Subject: [PATCH] add: show nsfw posts to their author nsfw posts are also always shown if the profile is private --- crates/app/src/routes/pages/profile.rs | 2 +- crates/core/src/database/posts.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/app/src/routes/pages/profile.rs b/crates/app/src/routes/pages/profile.rs index bacd4c8..5f10b3e 100644 --- a/crates/app/src/routes/pages/profile.rs +++ b/crates/app/src/routes/pages/profile.rs @@ -200,7 +200,7 @@ pub async fn posts_request( let posts = match data .0 - .get_posts_by_user(other_user.id, 12, props.page) + .get_posts_by_user(other_user.id, 12, props.page, &user) .await { Ok(p) => match data diff --git a/crates/core/src/database/posts.rs b/crates/core/src/database/posts.rs index 41e4828..012ce16 100644 --- a/crates/core/src/database/posts.rs +++ b/crates/core/src/database/posts.rs @@ -254,15 +254,39 @@ impl DataManager { id: usize, batch: usize, page: usize, + user: &Option, ) -> Result> { + let other_user = self.get_user_by_id(id).await?; + let conn = match self.connect().await { Ok(c) => c, Err(e) => return Err(Error::DatabaseConnection(e.to_string())), }; + // check if we should hide nsfw posts + let mut hide_nsfw: bool = true; + + if let Some(ua) = user { + if ua.id == other_user.id { + hide_nsfw = false + } + } + + if other_user.settings.private_profile { + hide_nsfw = false; + } + + // ... let res = query_rows!( &conn, - "SELECT * FROM posts WHERE owner = $1 AND replying_to = 0 AND NOT context LIKE '%\"is_profile_pinned\":true%' AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY created DESC LIMIT $2 OFFSET $3", + &format!( + "SELECT * FROM posts WHERE owner = $1 AND replying_to = 0 AND NOT context LIKE '%\"is_profile_pinned\":true%' {} ORDER BY created DESC LIMIT $2 OFFSET $3", + if hide_nsfw { + "AND NOT context LIKE '%\"is_nsfw\":true%'" + } else { + "" + } + ), &[&(id as i64), &(batch as i64), &((page * batch) as i64)], |x| { Self::get_post_from_row(x) } );