Actually start playing with ActivityPub
And Rust
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::object::Object;
|
||||
|
||||
pub struct Create<'a, T, U> where T: Actor + 'static, U: Object {
|
||||
by: &'a T,
|
||||
object: U
|
||||
}
|
||||
|
||||
impl<'a, T: Actor, U: Object> Create<'a, T, U> {
|
||||
pub fn new(by: &T, obj: U) -> Create<T, U> {
|
||||
Create {
|
||||
by: by,
|
||||
object: obj
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
use diesel::PgConnection;
|
||||
|
||||
use activity_pub::{activity, Activity, context};
|
||||
use activity_pub::{activity_pub, ActivityPub, context};
|
||||
use activity_pub::activity::Create;
|
||||
use activity_pub::object::{Attribuable, Object};
|
||||
use models::instance::Instance;
|
||||
|
||||
pub enum ActorType {
|
||||
@@ -26,8 +28,8 @@ pub trait Actor {
|
||||
|
||||
fn get_actor_type() -> ActorType;
|
||||
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> Activity {
|
||||
activity(json!({
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> ActivityPub {
|
||||
activity_pub(json!({
|
||||
"@context": context(),
|
||||
"id": self.compute_id(conn),
|
||||
"type": Self::get_actor_type().to_string(),
|
||||
@@ -63,4 +65,9 @@ pub trait Actor {
|
||||
user = self.get_actor_id()
|
||||
)
|
||||
}
|
||||
|
||||
fn create<T>(&self, obj: T) -> Create<Self, T> where T: Object + Attribuable, Self: Actor + Sized {
|
||||
obj.set_attribution::<Self>(self);
|
||||
Create::<Self, T>::new(self, obj)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,14 @@ use rocket::response::Content;
|
||||
use rocket_contrib::Json;
|
||||
use serde_json;
|
||||
|
||||
pub mod activity;
|
||||
pub mod actor;
|
||||
pub mod object;
|
||||
pub mod webfinger;
|
||||
|
||||
pub type Activity = Content<Json>;
|
||||
pub type ActivityPub = Content<Json>;
|
||||
|
||||
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
|
||||
|
||||
pub fn context() -> serde_json::Value {
|
||||
json!([
|
||||
@@ -32,6 +36,6 @@ pub fn context() -> serde_json::Value {
|
||||
])
|
||||
}
|
||||
|
||||
pub fn activity(json: serde_json::Value) -> Activity {
|
||||
pub fn activity_pub(json: serde_json::Value) -> ActivityPub {
|
||||
Content(ContentType::new("application", "activity+json"), Json(json))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
use activity_pub::actor::Actor;
|
||||
|
||||
pub trait Object {}
|
||||
|
||||
pub trait Attribuable {
|
||||
fn set_attribution<T>(&self, by: &T) where T: Actor;
|
||||
}
|
||||
Reference in New Issue
Block a user