diff --git a/server/src/apub/extensions/group_extensions.rs b/server/src/apub/extensions/group_extensions.rs index 2120f6f14..7dc42c4a0 100644 --- a/server/src/apub/extensions/group_extensions.rs +++ b/server/src/apub/extensions/group_extensions.rs @@ -1,5 +1,6 @@ use crate::LemmyError; -use activitystreams::{ext::Extension, Actor}; +use activitystreams_ext::UnparsedExtension; +use activitystreams_new::unparsed::UnparsedMutExt; use diesel::PgConnection; use lemmy_db::{category::Category, Crud}; use serde::{Deserialize, Serialize}; @@ -37,4 +38,22 @@ impl GroupExtension { } } -impl Extension for GroupExtension where T: Actor {} +impl UnparsedExtension for GroupExtension +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(GroupExtension { + category: unparsed_mut.remove("category")?, + sensitive: unparsed_mut.remove("sensitive")?, + }) + } + + fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { + unparsed_mut.insert("category", self.category)?; + unparsed_mut.insert("sensitive", self.sensitive)?; + Ok(()) + } +} diff --git a/server/src/apub/extensions/page_extension.rs b/server/src/apub/extensions/page_extension.rs index 484807e3e..9851a0137 100644 --- a/server/src/apub/extensions/page_extension.rs +++ b/server/src/apub/extensions/page_extension.rs @@ -1,4 +1,5 @@ -use activitystreams::{ext::Extension, Base}; +use activitystreams_ext::UnparsedExtension; +use activitystreams_new::unparsed::UnparsedMutExt; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Default, Deserialize, Serialize)] @@ -8,4 +9,22 @@ pub struct PageExtension { pub sensitive: bool, } -impl Extension for PageExtension where T: Base {} +impl UnparsedExtension for PageExtension +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(PageExtension { + comments_enabled: unparsed_mut.remove("commentsEnabled")?, + sensitive: unparsed_mut.remove("sensitive")?, + }) + } + + 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)?; + Ok(()) + } +} diff --git a/server/src/apub/extensions/signatures.rs b/server/src/apub/extensions/signatures.rs index 1c930a958..468e820ec 100644 --- a/server/src/apub/extensions/signatures.rs +++ b/server/src/apub/extensions/signatures.rs @@ -1,5 +1,6 @@ use crate::{apub::ActorType, LemmyError}; -use activitystreams::ext::Extension; +use activitystreams_ext::UnparsedExtension; +use activitystreams_new::unparsed::UnparsedMutExt; use actix_web::{client::ClientRequest, HttpRequest}; use http_signature_normalization_actix::{ digest::{DigestClient, SignExt}, @@ -98,4 +99,20 @@ impl PublicKey { } } -impl Extension for PublicKeyExtension where T: activitystreams::Actor {} +impl UnparsedExtension for PublicKeyExtension +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(PublicKeyExtension { + public_key: unparsed_mut.remove("publicKey")?, + }) + } + + fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { + unparsed_mut.insert("publicKey", self.public_key)?; + Ok(()) + } +}