2020-08-01 13:25:17 +00:00
|
|
|
use activitystreams::unparsed::UnparsedMutExt;
|
2020-07-17 21:11:07 +00:00
|
|
|
use activitystreams_ext::UnparsedExtension;
|
2020-05-05 14:30:13 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-05-05 00:04:48 +00:00
|
|
|
|
2020-10-19 14:29:35 +00:00
|
|
|
/// Activitystreams extension to allow (de)serializing additional Post fields
|
|
|
|
/// `comemnts_enabled` (called 'locked' in Lemmy),
|
|
|
|
/// `sensitive` (called 'nsfw') and `stickied`.
|
2020-05-05 00:04:48 +00:00
|
|
|
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct PageExtension {
|
|
|
|
pub comments_enabled: bool,
|
|
|
|
pub sensitive: bool,
|
2020-07-27 15:42:15 +00:00
|
|
|
pub stickied: bool,
|
2020-05-05 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 21:11:07 +00:00
|
|
|
impl<U> UnparsedExtension<U> for PageExtension
|
|
|
|
where
|
|
|
|
U: UnparsedMutExt,
|
|
|
|
{
|
|
|
|
type Error = serde_json::Error;
|
|
|
|
|
|
|
|
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
|
|
|
Ok(PageExtension {
|
|
|
|
comments_enabled: unparsed_mut.remove("commentsEnabled")?,
|
|
|
|
sensitive: unparsed_mut.remove("sensitive")?,
|
2020-07-27 15:42:15 +00:00
|
|
|
stickied: unparsed_mut.remove("stickied")?,
|
2020-07-17 21:11:07 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
|
|
|
|
unparsed_mut.insert("commentsEnabled", self.comments_enabled)?;
|
|
|
|
unparsed_mut.insert("sensitive", self.sensitive)?;
|
2020-07-27 15:42:15 +00:00
|
|
|
unparsed_mut.insert("stickied", self.stickied)?;
|
2020-07-17 21:11:07 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|