From 236c7e24fd27bd49169fbd4072dbb92cfc078498 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 19 Oct 2023 20:16:23 -0400 Subject: [PATCH] Making mark post read fields optional. (#4055) * Making mark post read fields optional. * Remove unecessary & * Fix clippy. * Addressing PR comments. * serde(default) * Revert "serde(default)" This reverts commit d56afd3075a3baccb2b0eda1cc739406b83963aa. --------- Co-authored-by: Felix Ableitner --- crates/api/src/post/mark_read.rs | 13 ++++++++++--- crates/api_common/src/post.rs | 5 +++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/crates/api/src/post/mark_read.rs b/crates/api/src/post/mark_read.rs index a377b3c6c..a46e949fa 100644 --- a/crates/api/src/post/mark_read.rs +++ b/crates/api/src/post/mark_read.rs @@ -11,14 +11,21 @@ pub async fn mark_post_as_read( context: Data, local_user_view: LocalUserView, ) -> Result, LemmyError> { - let mut post_ids = data.post_ids.iter().cloned().collect::>(); - post_ids.insert(data.post_id); - let person_id = local_user_view.person.id; + let mut post_ids = HashSet::new(); + if let Some(post_ids_) = &data.post_ids { + post_ids.extend(post_ids_.iter().cloned()); + } + + if let Some(post_id) = data.post_id { + post_ids.insert(post_id); + } if post_ids.len() > MAX_API_PARAM_ELEMENTS { Err(LemmyErrorType::TooManyItems)?; } + let person_id = local_user_view.person.id; + // Mark the post as read / unread if data.read { PostRead::mark_as_read(&mut context.pool(), post_ids, person_id) diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index fbb6f1d38..b93742bea 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -135,14 +135,15 @@ pub struct RemovePost { pub reason: Option, } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize, Clone, Default)] #[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", ts(export))] /// Mark a post as read. pub struct MarkPostAsRead { /// TODO: deprecated, send `post_ids` instead - pub post_id: PostId, - pub post_ids: Vec, + pub post_id: Option, + pub post_ids: Option>, pub read: bool, }