From 994a4dbb2d43d48dc1d9aee4484b4151c0a4c06d Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 24 Feb 2022 01:58:05 +0900 Subject: [PATCH] Add source property to CustomGroup --- plume-common/src/activity_pub/mod.rs | 50 ++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 2a8e91a6..4ff4705f 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -8,7 +8,7 @@ use activitystreams::{ primitives::{AnyString, OneOrMany}, unparsed::UnparsedMutExt, }; -use activitystreams_ext::{Ext1, UnparsedExtension}; +use activitystreams_ext::{Ext1, Ext2, UnparsedExtension}; use array_tool::vec::Uniq; use reqwest::{header::HeaderValue, r#async::ClientBuilder, Url}; use rocket::{ @@ -344,8 +344,32 @@ where } } +#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] +#[serde(rename_all = "camelCase")] +pub struct ActorSource { + pub source: Source, +} + +impl UnparsedExtension for ActorSource +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(ActorSource { + source: unparsed_mut.remove("source")?, + }) + } + + fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { + unparsed_mut.insert("source", self.source)?; + Ok(()) + } +} + pub type CustomPerson = Ext1, ApSignature07>; -pub type CustomGroup = Ext1, ApSignature07>; +pub type CustomGroup = Ext2, ApSignature07, ActorSource>; #[derive(Clone, Debug, Default, UnitString)] #[activitystreams(Hashtag)] @@ -364,7 +388,7 @@ pub struct Hashtag { pub name: Option, } -#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct Source { pub media_type: String, @@ -374,6 +398,26 @@ pub struct Source { impl Object for Source {} +impl UnparsedExtension for Source +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(Source { + content: unparsed_mut.remove("content")?, + media_type: unparsed_mut.remove("mediaType")?, + }) + } + + fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { + unparsed_mut.insert("content", self.content)?; + unparsed_mut.insert("mediaType", self.media_type)?; + Ok(()) + } +} + #[derive(Clone, Debug, Default, Deserialize, Serialize, Properties)] #[serde(rename_all = "camelCase")] pub struct Licensed {