add: nsfw marker for posts/communities

This commit is contained in:
trisua 2025-04-07 16:32:09 -04:00
parent f83cfa3756
commit 51534fbd52
8 changed files with 49 additions and 7 deletions

View file

@ -133,7 +133,7 @@ impl DataManager {
let res = query_rows!(
&conn,
"SELECT * FROM communities ORDER BY member_count DESC LIMIT 12",
"SELECT * FROM communities WHERE NOT context LIKE '%\"is_nsfw\":true%' ORDER BY member_count DESC LIMIT 12",
empty,
|x| { Self::get_community_from_row(x) }
);

View file

@ -144,7 +144,7 @@ impl DataManager {
let res = query_rows!(
&conn,
"SELECT * FROM posts WHERE owner = $1 AND NOT context LIKE '%\"is_profile_pinned\":true%' ORDER BY created DESC LIMIT $2 OFFSET $3",
"SELECT * FROM posts WHERE owner = $1 AND NOT context LIKE '%\"is_profile_pinned\":true%' AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY created DESC LIMIT $2 OFFSET $3",
&[&(id as i64), &(batch as i64), &((page * batch) as i64)],
|x| { Self::get_post_from_row(x) }
);
@ -248,7 +248,7 @@ impl DataManager {
let res = query_rows!(
&conn,
"SELECT * FROM posts WHERE replying_to = 0 ORDER BY likes DESC, created ASC LIMIT $1 OFFSET $2",
"SELECT * FROM posts WHERE replying_to = 0 AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY likes DESC, created ASC LIMIT $1 OFFSET $2",
&[&(batch as i64), &((page * batch) as i64)],
|x| { Self::get_post_from_row(x) }
);
@ -358,6 +358,9 @@ impl DataManager {
return Err(Error::NotAllowed);
}
// mirror nsfw state
data.context.is_nsfw = community.context.is_nsfw;
// check if we're blocked
if let Some(replying_to) = data.replying_to {
if let Ok(_) = self

View file

@ -72,8 +72,12 @@ impl Community {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct CommunityContext {
#[serde(default)]
pub display_name: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub is_nsfw: bool,
}
impl Default for CommunityContext {
@ -81,6 +85,7 @@ impl Default for CommunityContext {
Self {
display_name: String::new(),
description: String::new(),
is_nsfw: false,
}
}
}
@ -171,6 +176,8 @@ pub struct PostContext {
pub is_profile_pinned: bool,
#[serde(default)]
pub edited: usize,
#[serde(default)]
pub is_nsfw: bool,
}
fn default_comments_enabled() -> bool {
@ -184,6 +191,7 @@ impl Default for PostContext {
is_pinned: false,
is_profile_pinned: false,
edited: 0,
is_nsfw: false,
}
}
}