add: option to hide posts answering questions from "All" timeline
This commit is contained in:
parent
5961999ce4
commit
612fbf5eb4
6 changed files with 36 additions and 5 deletions
|
@ -1319,7 +1319,18 @@ impl DataManager {
|
|||
/// # Arguments
|
||||
/// * `batch` - the limit of posts in each page
|
||||
/// * `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 {
|
||||
Ok(c) => c,
|
||||
Err(e) => return Err(Error::DatabaseConnection(e.to_string())),
|
||||
|
@ -1327,7 +1338,14 @@ impl DataManager {
|
|||
|
||||
let res = query_rows!(
|
||||
&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)],
|
||||
|x| { Self::get_post_from_row(x) }
|
||||
);
|
||||
|
|
|
@ -59,7 +59,7 @@ impl DataManager {
|
|||
match stack.sort {
|
||||
StackSort::Created => {
|
||||
self.fill_posts_with_community(
|
||||
self.get_latest_posts(batch, page).await?,
|
||||
self.get_latest_posts(batch, page, &user).await?,
|
||||
as_user_id,
|
||||
&ignore_users,
|
||||
user,
|
||||
|
|
|
@ -240,6 +240,9 @@ pub struct UserSettings {
|
|||
/// Automatically unlist posts from timelines.
|
||||
#[serde(default)]
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue