1 use activitystreams::unparsed::UnparsedMutExt;
2 use activitystreams_ext::UnparsedExtension;
3 use lemmy_utils::LemmyError;
4 use serde::{Deserialize, Serialize};
6 /// Activitystreams extension to allow (de)serializing additional Community field
7 /// `sensitive` (called 'nsfw' in Lemmy).
8 #[derive(Clone, Debug, Default, Deserialize, Serialize)]
9 #[serde(rename_all = "camelCase")]
10 pub struct GroupExtension {
11 pub sensitive: Option<bool>,
15 pub fn new(sensitive: bool) -> Result<GroupExtension, LemmyError> {
17 sensitive: Some(sensitive),
22 impl<U> UnparsedExtension<U> for GroupExtension
26 type Error = serde_json::Error;
28 fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
30 sensitive: unparsed_mut.remove("sensitive")?,
34 fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> {
35 unparsed_mut.insert("sensitive", self.sensitive)?;