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