Making mark post read fields optional.

mark_unread_post_id_opt
Dessalines 2023-10-17 14:47:09 -04:00
parent a675fecacd
commit 05722f9b79
2 changed files with 17 additions and 5 deletions

View File

@ -11,14 +11,25 @@ pub async fn mark_post_as_read(
context: Data<LemmyContext>, context: Data<LemmyContext>,
local_user_view: LocalUserView, local_user_view: LocalUserView,
) -> Result<Json<SuccessResponse>, LemmyError> { ) -> Result<Json<SuccessResponse>, LemmyError> {
let mut post_ids = data.post_ids.iter().cloned().collect::<HashSet<_>>(); let mut post_ids = HashSet::new();
post_ids.insert(data.post_id); if let Some(post_ids_) = &data.post_ids {
let person_id = local_user_view.person.id; post_ids.extend(&post_ids_.iter().cloned().collect::<HashSet<_>>());
}
if let Some(post_id) = data.post_id {
post_ids.insert(post_id);
}
if post_ids.is_empty() {
Err(LemmyErrorType::CouldntMarkPostAsRead)?;
}
if post_ids.len() > MAX_API_PARAM_ELEMENTS { if post_ids.len() > MAX_API_PARAM_ELEMENTS {
Err(LemmyErrorType::TooManyItems)?; Err(LemmyErrorType::TooManyItems)?;
} }
let person_id = local_user_view.person.id;
// Mark the post as read / unread // Mark the post as read / unread
if data.read { if data.read {
PostRead::mark_as_read(&mut context.pool(), post_ids, person_id) PostRead::mark_as_read(&mut context.pool(), post_ids, person_id)

View File

@ -135,14 +135,15 @@ pub struct RemovePost {
pub reason: Option<String>, pub reason: Option<String>,
} }
#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize, Clone, Default)] #[derive(Debug, Serialize, Deserialize, Clone, Default)]
#[cfg_attr(feature = "full", derive(TS))] #[cfg_attr(feature = "full", derive(TS))]
#[cfg_attr(feature = "full", ts(export))] #[cfg_attr(feature = "full", ts(export))]
/// Mark a post as read. /// Mark a post as read.
pub struct MarkPostAsRead { pub struct MarkPostAsRead {
/// TODO: deprecated, send `post_ids` instead /// TODO: deprecated, send `post_ids` instead
pub post_id: PostId, pub post_id: Option<PostId>,
pub post_ids: Vec<PostId>, pub post_ids: Option<Vec<PostId>>,
pub read: bool, pub read: bool,
} }