Migrate extensions to new activitystreams library
This commit is contained in:
parent
2a206e1b4d
commit
7c55a84184
3 changed files with 61 additions and 6 deletions
|
@ -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<T> Extension<T> for GroupExtension where T: Actor {}
|
||||
impl<U> UnparsedExtension<U> for GroupExtension
|
||||
where
|
||||
U: UnparsedMutExt,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> Extension<T> for PageExtension where T: Base {}
|
||||
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")?,
|
||||
})
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<T> Extension<T> for PublicKeyExtension where T: activitystreams::Actor {}
|
||||
impl<U> UnparsedExtension<U> for PublicKeyExtension
|
||||
where
|
||||
U: UnparsedMutExt,
|
||||
{
|
||||
type Error = serde_json::Error;
|
||||
|
||||
fn try_from_unparsed(unparsed_mut: &mut U) -> Result<Self, Self::Error> {
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue