1 use activitystreams::unparsed::UnparsedMutExt;
2 use activitystreams_ext::UnparsedExtension;
3 use serde::{Deserialize, Serialize};
5 /// Activitystreams extension to allow (de)serializing additional Post fields
6 /// `comemnts_enabled` (called 'locked' in Lemmy),
7 /// `sensitive` (called 'nsfw') and `stickied`.
8 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
9 #[serde(rename_all = "camelCase")]
10 pub struct PageExtension {
11 pub comments_enabled: Option<bool>,
12 pub sensitive: Option<bool>,
13 pub stickied: Option<bool>,
16 impl<U> UnparsedExtension<U> for PageExtension
20 type Error = serde_json::Error;
22 fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
24 comments_enabled: unparsed_mut.remove("commentsEnabled")?,
25 sensitive: unparsed_mut.remove("sensitive")?,
26 stickied: unparsed_mut.remove("stickied")?,
30 fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
31 unparsed_mut.insert("commentsEnabled", self.comments_enabled)?;
32 unparsed_mut.insert("sensitive", self.sensitive)?;
33 unparsed_mut.insert("stickied", self.stickied)?;