add: ability to generate invite codes in bulk add: better mark as nsfw

ui
This commit is contained in:
trisua 2025-06-23 13:48:16 -04:00
parent 2a77c61bf2
commit 4843688fcf
13 changed files with 126 additions and 90 deletions

View file

@ -689,31 +689,15 @@ impl DataManager {
id: usize,
batch: usize,
page: usize,
user: &Option<User>,
) -> Result<Vec<Post>> {
let conn = match self.0.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 {
hide_nsfw = !ua.settings.show_nsfw;
}
// ...
let res = query_rows!(
&conn,
&format!(
"SELECT * FROM posts WHERE owner = $1 AND replying_to = 0 AND NOT (context::json->>'is_profile_pinned')::boolean AND is_deleted = 0 {} ORDER BY created DESC LIMIT $2 OFFSET $3",
if hide_nsfw {
"AND NOT (context::json->>'is_nsfw')::boolean"
} else {
""
}
),
"SELECT * FROM posts WHERE owner = $1 AND replying_to = 0 AND NOT (context::json->>'is_profile_pinned')::boolean AND is_deleted = 0 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) }
);
@ -1008,31 +992,15 @@ impl DataManager {
tag: &str,
batch: usize,
page: usize,
user: &Option<User>,
) -> Result<Vec<Post>> {
let conn = match self.0.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 {
hide_nsfw = !ua.settings.show_nsfw;
}
// ...
let res = query_rows!(
&conn,
&format!(
"SELECT * FROM posts WHERE owner = $1 AND context::json->>'tags' LIKE $2 AND is_deleted = 0 {} ORDER BY created DESC LIMIT $3 OFFSET $4",
if hide_nsfw {
"AND NOT (context::json->>'is_nsfw')::boolean"
} else {
""
}
),
"SELECT * FROM posts WHERE owner = $1 AND context::json->>'tags' LIKE $2 AND is_deleted = 0 ORDER BY created DESC LIMIT $3 OFFSET $4",
params![
&(id as i64),
&format!("%\"{tag}\"%"),