Adding list_post request option to auto-mark as read.

This commit is contained in:
Dessalines 2024-11-04 15:23:27 -05:00
parent bd0e68fb00
commit 3dbc33e68c
2 changed files with 7 additions and 2 deletions

View file

@ -85,6 +85,8 @@ pub struct GetPosts {
pub show_read: Option<bool>, pub show_read: Option<bool>,
/// If true, then show the nsfw posts (even if your user setting is to hide them) /// If true, then show the nsfw posts (even if your user setting is to hide them)
pub show_nsfw: Option<bool>, pub show_nsfw: Option<bool>,
/// Whether to automatically mark fetched posts as read.
pub auto_mark_fetched_posts_as_read: Option<bool>,
pub page_cursor: Option<PaginationCursor>, pub page_cursor: Option<PaginationCursor>,
} }

View file

@ -91,9 +91,12 @@ pub async fn list_posts(
.await .await
.with_lemmy_type(LemmyErrorType::CouldntGetPosts)?; .with_lemmy_type(LemmyErrorType::CouldntGetPosts)?;
// If in their user settings, auto-mark fetched posts as read // If in their user settings (or as part of the API request), auto-mark fetched posts as read
if let Some(local_user) = local_user { if let Some(local_user) = local_user {
if local_user.auto_mark_fetched_posts_as_read { if data
.auto_mark_fetched_posts_as_read
.unwrap_or(local_user.auto_mark_fetched_posts_as_read)
{
let post_ids = posts.iter().map(|p| p.post.id).collect::<Vec<PostId>>(); let post_ids = posts.iter().map(|p| p.post.id).collect::<Vec<PostId>>();
PostRead::mark_as_read(&mut context.pool(), &post_ids, local_user.person_id).await?; PostRead::mark_as_read(&mut context.pool(), &post_ids, local_user.person_id).await?;
} }