fix: nsfw posts in all/communities timelines
This commit is contained in:
parent
69067145ce
commit
7960f1ed41
3 changed files with 28 additions and 6 deletions
|
@ -723,7 +723,7 @@ pub async fn from_communities_request(
|
||||||
};
|
};
|
||||||
|
|
||||||
match data
|
match data
|
||||||
.get_posts_from_user_communities(user.id, 12, props.page)
|
.get_posts_from_user_communities(user.id, 12, props.page, &user)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(posts) => {
|
Ok(posts) => {
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub async fn index_request(
|
||||||
|
|
||||||
let list = match data
|
let list = match data
|
||||||
.0
|
.0
|
||||||
.get_posts_from_user_communities(user.id, 12, req.page)
|
.get_posts_from_user_communities(user.id, 12, req.page, &user)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(l) => match data
|
Ok(l) => match data
|
||||||
|
@ -725,7 +725,7 @@ pub async fn swiss_army_timeline_request(
|
||||||
DefaultTimelineChoice::MyCommunities => {
|
DefaultTimelineChoice::MyCommunities => {
|
||||||
if let Some(ref ua) = user {
|
if let Some(ref ua) = user {
|
||||||
data.0
|
data.0
|
||||||
.get_posts_from_user_communities(ua.id, 12, req.page)
|
.get_posts_from_user_communities(ua.id, 12, req.page, ua)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
return Err(Html(
|
return Err(Html(
|
||||||
|
|
|
@ -1452,6 +1452,14 @@ impl DataManager {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// check if we should hide nsfw posts
|
||||||
|
let mut hide_nsfw: bool = true;
|
||||||
|
|
||||||
|
if let Some(ua) = as_user {
|
||||||
|
hide_nsfw = !ua.settings.show_nsfw;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ...
|
||||||
let conn = match self.0.connect().await {
|
let conn = match self.0.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())),
|
||||||
|
@ -1460,12 +1468,17 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
&format!(
|
&format!(
|
||||||
"SELECT * FROM posts WHERE replying_to = 0{} AND NOT context LIKE '%\"is_nsfw\":true%'{} ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM posts WHERE replying_to = 0{}{}{} ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
if before_time > 0 {
|
if before_time > 0 {
|
||||||
format!(" AND created < {before_time}")
|
format!(" AND created < {before_time}")
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
},
|
},
|
||||||
|
if hide_nsfw {
|
||||||
|
" AND NOT context LIKE '%\"is_nsfw\":true%'"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
if hide_answers {
|
if hide_answers {
|
||||||
" AND context::jsonb->>'answering' = '0'"
|
" AND context::jsonb->>'answering' = '0'"
|
||||||
} else {
|
} else {
|
||||||
|
@ -1494,6 +1507,7 @@ impl DataManager {
|
||||||
id: usize,
|
id: usize,
|
||||||
batch: usize,
|
batch: usize,
|
||||||
page: usize,
|
page: usize,
|
||||||
|
user: &User,
|
||||||
) -> Result<Vec<Post>> {
|
) -> Result<Vec<Post>> {
|
||||||
let memberships = self.get_memberships_by_owner(id).await?;
|
let memberships = self.get_memberships_by_owner(id).await?;
|
||||||
let mut memberships = memberships.iter();
|
let mut memberships = memberships.iter();
|
||||||
|
@ -1508,6 +1522,9 @@ impl DataManager {
|
||||||
query_string.push_str(&format!(" OR community = {}", membership.community));
|
query_string.push_str(&format!(" OR community = {}", membership.community));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if we should hide nsfw posts
|
||||||
|
let hide_nsfw: bool = !user.settings.show_nsfw;
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
let conn = match self.0.connect().await {
|
let conn = match self.0.connect().await {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
|
@ -1517,8 +1534,13 @@ impl DataManager {
|
||||||
let res = query_rows!(
|
let res = query_rows!(
|
||||||
&conn,
|
&conn,
|
||||||
&format!(
|
&format!(
|
||||||
"SELECT * FROM posts WHERE (community = {} {query_string}) AND NOT context LIKE '%\"is_nsfw\":true%' AND replying_to = 0 AND is_deleted = 0 ORDER BY created DESC LIMIT $1 OFFSET $2",
|
"SELECT * FROM posts WHERE (community = {} {query_string}){} AND replying_to = 0 AND is_deleted = 0 ORDER BY created DESC LIMIT $1 OFFSET $2",
|
||||||
first.community
|
first.community,
|
||||||
|
if hide_nsfw {
|
||||||
|
" AND NOT context LIKE '%\"is_nsfw\":true%'"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
},
|
||||||
),
|
),
|
||||||
&[&(batch as i64), &((page * batch) 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