add: option to hide posts answering questions from "All" timeline

This commit is contained in:
trisua 2025-06-22 00:45:05 -04:00
parent 5961999ce4
commit 612fbf5eb4
6 changed files with 36 additions and 5 deletions

View file

@ -1364,6 +1364,11 @@
\"{{ profile.settings.auto_unlist }}\", \"{{ profile.settings.auto_unlist }}\",
\"checkbox\", \"checkbox\",
], ],
[
[\"all_timeline_hide_answers\", 'Hide posts answering questions from the \"All\" timeline'],
\"{{ profile.settings.all_timeline_hide_answers }}\",
\"checkbox\",
],
[[], \"Questions\", \"title\"], [[], \"Questions\", \"title\"],
[ [
[ [

View file

@ -792,7 +792,10 @@ pub async fn all_request(
None => return Json(Error::NotAllowed.into()), None => return Json(Error::NotAllowed.into()),
}; };
match data.get_latest_posts(12, props.page).await { match data
.get_latest_posts(12, props.page, &Some(user.clone()))
.await
{
Ok(posts) => { Ok(posts) => {
let ignore_users = crate::ignore_users_gen!(user!, #data); let ignore_users = crate::ignore_users_gen!(user!, #data);
Json(ApiReturn { Json(ApiReturn {

View file

@ -636,7 +636,9 @@ pub async fn swiss_army_timeline_request(
} else { } else {
// everything else // everything else
match req.tl { match req.tl {
DefaultTimelineChoice::AllPosts => data.0.get_latest_posts(12, req.page).await, DefaultTimelineChoice::AllPosts => {
data.0.get_latest_posts(12, req.page, &user).await
}
DefaultTimelineChoice::PopularPosts => { DefaultTimelineChoice::PopularPosts => {
data.0.get_popular_posts(12, req.page, 604_800_000).await data.0.get_popular_posts(12, req.page, 604_800_000).await
} }

View file

@ -1319,7 +1319,18 @@ impl DataManager {
/// # Arguments /// # Arguments
/// * `batch` - the limit of posts in each page /// * `batch` - the limit of posts in each page
/// * `page` - the page number /// * `page` - the page number
pub async fn get_latest_posts(&self, batch: usize, page: usize) -> Result<Vec<Post>> { pub async fn get_latest_posts(
&self,
batch: usize,
page: usize,
as_user: &Option<User>,
) -> Result<Vec<Post>> {
let hide_answers: bool = if let Some(user) = as_user {
user.settings.all_timeline_hide_answers
} else {
false
};
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())),
@ -1327,7 +1338,14 @@ impl DataManager {
let res = query_rows!( let res = query_rows!(
&conn, &conn,
"SELECT * FROM posts WHERE replying_to = 0 AND NOT context LIKE '%\"is_nsfw\":true%' ORDER BY created DESC LIMIT $1 OFFSET $2", &format!(
"SELECT * FROM posts WHERE replying_to = 0 AND NOT context LIKE '%\"is_nsfw\":true%'{} ORDER BY created DESC LIMIT $1 OFFSET $2",
if hide_answers {
" AND context::jsonb->>'answering' = '0'"
} 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) }
); );

View file

@ -59,7 +59,7 @@ impl DataManager {
match stack.sort { match stack.sort {
StackSort::Created => { StackSort::Created => {
self.fill_posts_with_community( self.fill_posts_with_community(
self.get_latest_posts(batch, page).await?, self.get_latest_posts(batch, page, &user).await?,
as_user_id, as_user_id,
&ignore_users, &ignore_users,
user, user,

View file

@ -240,6 +240,9 @@ pub struct UserSettings {
/// Automatically unlist posts from timelines. /// Automatically unlist posts from timelines.
#[serde(default)] #[serde(default)]
pub auto_unlist: bool, pub auto_unlist: bool,
/// Hide posts that are answering a question on the "All" timeline.
#[serde(default)]
pub all_timeline_hide_answers: bool,
} }
fn mime_avif() -> String { fn mime_avif() -> String {