add: show nsfw posts to their author
nsfw posts are also always shown if the profile is private
This commit is contained in:
parent
0b3573a513
commit
a62905a8c4
2 changed files with 26 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -254,15 +254,39 @@ impl DataManager {
|
|||
id: usize,
|
||||
batch: usize,
|
||||
page: usize,
|
||||
user: &Option<User>,
|
||||
) -> Result<Vec<Post>> {
|
||||
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) }
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue