163 lines
4.4 KiB
Rust
163 lines
4.4 KiB
Rust
|
use crate::{
|
||
|
object::Object,
|
||
|
primitives::{OneOrMany, Unparsed, XsdAnyUri, XsdString},
|
||
|
traits::{self, Extends, WithUnparsed, WithUnparsedExt},
|
||
|
};
|
||
|
|
||
|
pub mod kind {
|
||
|
pub use activitystreams::actor::kind::*;
|
||
|
}
|
||
|
|
||
|
use self::kind::*;
|
||
|
|
||
|
pub type Application = Object<ApplicationType>;
|
||
|
pub type Group = Object<GroupType>;
|
||
|
pub type Organization = Object<OrganizationType>;
|
||
|
pub type Person = Object<PersonType>;
|
||
|
pub type Service = Object<ServiceType>;
|
||
|
|
||
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
|
||
|
#[serde(rename_all = "camelCase")]
|
||
|
pub struct ApActor<Inner> {
|
||
|
pub inbox: XsdAnyUri,
|
||
|
pub outbox: XsdAnyUri,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub following: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub followers: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub liked: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub streams: Option<OneOrMany<XsdAnyUri>>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub preferred_username: Option<XsdString>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub endpoints: Option<Endpoints>,
|
||
|
|
||
|
#[serde(flatten)]
|
||
|
pub inner: Inner,
|
||
|
}
|
||
|
|
||
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
|
||
|
#[serde(rename_all = "camelCase")]
|
||
|
pub struct Endpoints {
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub proxy_url: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub oauth_authorization_endpoint: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub oauth_token_endpoint: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub provide_client_key: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub sign_client_key: Option<XsdAnyUri>,
|
||
|
|
||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||
|
pub shared_inbox: Option<XsdAnyUri>,
|
||
|
}
|
||
|
|
||
|
impl<Inner> ApActor<Inner> {
|
||
|
fn extending(mut inner: Inner) -> Result<Self, serde_json::Error>
|
||
|
where
|
||
|
Inner: WithUnparsed + traits::Actor,
|
||
|
{
|
||
|
let inbox = inner.remove("inbox")?;
|
||
|
let outbox = inner.remove("outbox")?;
|
||
|
let following = inner.remove("following")?;
|
||
|
let followers = inner.remove("followers")?;
|
||
|
let liked = inner.remove("liked")?;
|
||
|
let streams = inner.remove("streams")?;
|
||
|
let preferred_username = inner.remove("preferredUsername")?;
|
||
|
let endpoints = inner.remove("endpoints")?;
|
||
|
|
||
|
Ok(ApActor {
|
||
|
inbox,
|
||
|
outbox,
|
||
|
following,
|
||
|
followers,
|
||
|
liked,
|
||
|
streams,
|
||
|
preferred_username,
|
||
|
endpoints,
|
||
|
inner,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
fn retracting(self) -> Result<Inner, serde_json::Error>
|
||
|
where
|
||
|
Inner: WithUnparsed + traits::Actor,
|
||
|
{
|
||
|
let ApActor {
|
||
|
inbox,
|
||
|
outbox,
|
||
|
following,
|
||
|
followers,
|
||
|
liked,
|
||
|
streams,
|
||
|
preferred_username,
|
||
|
endpoints,
|
||
|
mut inner,
|
||
|
} = self;
|
||
|
|
||
|
inner
|
||
|
.insert("endpoints", endpoints)?
|
||
|
.insert("preferredUsername", preferred_username)?
|
||
|
.insert("streams", streams)?
|
||
|
.insert("liked", liked)?
|
||
|
.insert("followers", followers)?
|
||
|
.insert("following", following)?
|
||
|
.insert("outbox", outbox)?
|
||
|
.insert("inbox", inbox)?;
|
||
|
|
||
|
Ok(inner)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl traits::Actor for Application {}
|
||
|
impl traits::Actor for Group {}
|
||
|
impl traits::Actor for Organization {}
|
||
|
impl traits::Actor for Person {}
|
||
|
impl traits::Actor for Service {}
|
||
|
|
||
|
impl<Inner> traits::Base for ApActor<Inner> where Inner: traits::Base {}
|
||
|
impl<Inner> traits::Object for ApActor<Inner> where Inner: traits::Object {}
|
||
|
impl<Inner> traits::Actor for ApActor<Inner> where Inner: traits::Actor {}
|
||
|
|
||
|
impl<Inner> Extends<Inner> for ApActor<Inner>
|
||
|
where
|
||
|
Inner: WithUnparsed + traits::Actor,
|
||
|
{
|
||
|
type Error = serde_json::Error;
|
||
|
|
||
|
fn extends(inner: Inner) -> Result<Self, Self::Error> {
|
||
|
Self::extending(inner)
|
||
|
}
|
||
|
|
||
|
fn retracts(self) -> Result<Inner, Self::Error> {
|
||
|
self.retracting()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl<Inner> WithUnparsed for ApActor<Inner>
|
||
|
where
|
||
|
Inner: WithUnparsed,
|
||
|
{
|
||
|
fn unparsed(&self) -> &Unparsed {
|
||
|
self.inner.unparsed()
|
||
|
}
|
||
|
|
||
|
fn unparsed_mut(&mut self) -> &mut Unparsed {
|
||
|
self.inner.unparsed_mut()
|
||
|
}
|
||
|
}
|