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
|
let posts = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_by_user(other_user.id, 12, props.page)
|
.get_posts_by_user(other_user.id, 12, props.page, &user)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(p) => match data
|
Ok(p) => match data
|
||||||
|
|
|
@ -254,15 +254,39 @@ impl DataManager {
|
||||||
id: usize,
|
id: usize,
|
||||||
batch: usize,
|
batch: usize,
|
||||||
page: usize,
|
page: usize,
|
||||||
|
user: &Option<User>,
|
||||||
) -> Result<Vec<Post>> {
|
) -> Result<Vec<Post>> {
|
||||||
|
let other_user = self.get_user_by_id(id).await?;
|
||||||
|
|
||||||
let conn = match self.connect().await {
|
let conn = match self.connect().await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
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!(
|
let res = query_rows!(
|
||||||
&conn,
|
&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)],
|
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|
||||||
|x| { Self::get_post_from_row(x) }
|
|x| { Self::get_post_from_row(x) }
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue