Update to activitypub with extensions

This commit is contained in:
asonix
2020-03-18 17:49:56 -05:00
parent f48d404a15
commit 2b36909d2f
5 changed files with 30 additions and 48 deletions
+5 -19
View File
@@ -1,7 +1,9 @@
use activitystreams::{
actor::Actor,
ext::Extension,
object::{Object, ObjectBox},
primitives::XsdAnyUri,
PropRefs,
Base, BaseBox, PropRefs,
};
use std::collections::HashMap;
@@ -13,16 +15,9 @@ pub struct PublicKey {
pub public_key_pem: String,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PublicKeyExtension<T> {
public_key: PublicKey,
impl<T> Extension<T> for PublicKey where T: Actor {}
#[serde(flatten)]
extending: T,
}
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PropRefs)]
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, PropRefs)]
#[serde(rename_all = "camelCase")]
#[prop_refs(Object)]
pub struct AnyExistingObject {
@@ -91,15 +86,6 @@ pub struct Endpoints {
shared_inbox: Option<XsdAnyUri>,
}
impl PublicKey {
pub fn extend<T>(self, extending: T) -> PublicKeyExtension<T> {
PublicKeyExtension {
public_key: self,
extending,
}
}
}
impl ValidObjects {
pub fn id(&self) -> &XsdAnyUri {
match self {
+5 -10
View File
@@ -7,10 +7,11 @@ use crate::{
state::{State, UrlKind},
};
use activitystreams::{
activity::apub::{Accept, Announce, Follow, Undo},
activity::{Accept, Announce, Follow, Undo},
context,
object::properties::ObjectProperties,
primitives::XsdAnyUri,
public, security,
};
use actix_web::{web, HttpResponse};
use futures::join;
@@ -18,12 +19,6 @@ use http_signature_normalization_actix::middleware::SignatureVerified;
use log::error;
use std::convert::TryInto;
fn public() -> XsdAnyUri {
"https://www.w3.org/ns/activitystreams#Public"
.parse()
.unwrap()
}
pub async fn inbox(
db: web::Data<Db>,
state: web::Data<State>,
@@ -203,7 +198,7 @@ fn generate_undo_follow(
undo.undo_props
.set_actor_xsd_any_uri(my_id.clone())?
.set_object_object_box({
.set_object_base_box({
let mut follow = Follow::default();
follow
@@ -272,7 +267,7 @@ fn generate_accept_follow(
accept
.accept_props
.set_actor_xsd_any_uri(my_id.clone())?
.set_object_object_box({
.set_object_base_box({
let mut follow = Follow::default();
follow.object_props.set_id(input_id.clone())?;
@@ -303,7 +298,7 @@ where
t.as_mut()
.set_id(id.try_into()?)?
.set_many_to_xsd_any_uris(vec![to.try_into()?])?
.set_context_xsd_any_uri(context())?;
.set_many_context_xsd_any_uris(vec![context(), security()])?;
Ok(t)
}
+9 -6
View File
@@ -1,4 +1,7 @@
use activitystreams::{actor::apub::Application, context, endpoint::EndpointProperties};
use activitystreams::{
actor::Application, context, endpoint::EndpointProperties, ext::Extensible,
object::properties::ObjectProperties,
};
use actix_web::{middleware::Logger, web, App, HttpResponse, HttpServer, Responder};
use bb8_postgres::tokio_postgres;
use http_signature_normalization_actix::prelude::{VerifyDigest, VerifySignature};
@@ -50,13 +53,13 @@ async fn index() -> impl Responder {
}
async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError> {
let mut application = Application::default();
let mut application = Application::full();
let mut endpoint = EndpointProperties::default();
endpoint.set_shared_inbox(state.generate_url(UrlKind::Inbox))?;
application
.object_props
let props: &mut ObjectProperties = application.as_mut();
props
.set_id(state.generate_url(UrlKind::Actor))?
.set_summary_xsd_string("AodeRelay bot")?
.set_name_xsd_string("AodeRelay")?
@@ -64,7 +67,7 @@ async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError>
.set_context_xsd_any_uri(context())?;
application
.ap_actor_props
.extension
.set_preferred_username("relay")?
.set_followers(state.generate_url(UrlKind::Followers))?
.set_following(state.generate_url(UrlKind::Following))?
@@ -78,7 +81,7 @@ async fn actor_route(state: web::Data<State>) -> Result<impl Responder, MyError>
public_key_pem: state.settings.public_key.to_pem_pkcs8()?,
};
Ok(ok(public_key.extend(application)))
Ok(ok(application.extend(public_key)))
}
#[actix_rt::main]