Refactor ActivityPub
This commit is contained in:
parent
270786ad3d
commit
0b00849a62
@ -1,6 +1,6 @@
|
|||||||
use diesel::PgConnection;
|
use diesel::PgConnection;
|
||||||
use serde_json::Value;
|
|
||||||
|
|
||||||
|
use activity_pub::{activity, Activity, context};
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
|
|
||||||
pub enum ActorType {
|
pub enum ActorType {
|
||||||
@ -26,29 +26,9 @@ pub trait Actor {
|
|||||||
|
|
||||||
fn get_actor_type() -> ActorType;
|
fn get_actor_type() -> ActorType;
|
||||||
|
|
||||||
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
fn as_activity_pub (&self, conn: &PgConnection) -> Activity {
|
||||||
json!({
|
activity(json!({
|
||||||
"@context": [
|
"@context": context(),
|
||||||
"https://www.w3.org/ns/activitystreams",
|
|
||||||
"https://w3id.org/security/v1",
|
|
||||||
{
|
|
||||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
|
||||||
"sensitive": "as:sensitive",
|
|
||||||
"movedTo": "as:movedTo",
|
|
||||||
"Hashtag": "as:Hashtag",
|
|
||||||
"ostatus":"http://ostatus.org#",
|
|
||||||
"atomUri":"ostatus:atomUri",
|
|
||||||
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
|
||||||
"conversation":"ostatus:conversation",
|
|
||||||
"toot":"http://joinmastodon.org/ns#",
|
|
||||||
"Emoji":"toot:Emoji",
|
|
||||||
"focalPoint": {
|
|
||||||
"@container":"@list",
|
|
||||||
"@id":"toot:focalPoint"
|
|
||||||
},
|
|
||||||
"featured":"toot:featured"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"id": self.compute_id(conn),
|
"id": self.compute_id(conn),
|
||||||
"type": Self::get_actor_type().to_string(),
|
"type": Self::get_actor_type().to_string(),
|
||||||
"inbox": self.compute_inbox(conn),
|
"inbox": self.compute_inbox(conn),
|
||||||
@ -60,7 +40,7 @@ pub trait Actor {
|
|||||||
"endpoints": {
|
"endpoints": {
|
||||||
"sharedInbox": "https://plu.me/inbox"
|
"sharedInbox": "https://plu.me/inbox"
|
||||||
}
|
}
|
||||||
})
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
fn compute_outbox(&self, conn: &PgConnection) -> String {
|
||||||
|
@ -1,2 +1,37 @@
|
|||||||
|
use rocket::http::ContentType;
|
||||||
|
use rocket::response::Content;
|
||||||
|
use rocket_contrib::Json;
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
pub mod actor;
|
pub mod actor;
|
||||||
pub mod webfinger;
|
pub mod webfinger;
|
||||||
|
|
||||||
|
pub type Activity = Content<Json>;
|
||||||
|
|
||||||
|
pub fn context() -> serde_json::Value {
|
||||||
|
json!([
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"ostatus":"http://ostatus.org#",
|
||||||
|
"atomUri":"ostatus:atomUri",
|
||||||
|
"inReplyToAtomUri":"ostatus:inReplyToAtomUri",
|
||||||
|
"conversation":"ostatus:conversation",
|
||||||
|
"toot":"http://joinmastodon.org/ns#",
|
||||||
|
"Emoji":"toot:Emoji",
|
||||||
|
"focalPoint": {
|
||||||
|
"@container":"@list",
|
||||||
|
"@id":"toot:focalPoint"
|
||||||
|
},
|
||||||
|
"featured":"toot:featured"
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn activity(json: serde_json::Value) -> Activity {
|
||||||
|
Content(ContentType::new("application", "activity+json"), Json(json))
|
||||||
|
}
|
||||||
|
@ -61,7 +61,7 @@ fn main() {
|
|||||||
|
|
||||||
routes::user::me,
|
routes::user::me,
|
||||||
routes::user::details,
|
routes::user::details,
|
||||||
routes::user::activity,
|
routes::user::activity_details,
|
||||||
routes::user::new,
|
routes::user::new,
|
||||||
routes::user::create,
|
routes::user::create,
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ fn main() {
|
|||||||
routes::session::delete,
|
routes::session::delete,
|
||||||
|
|
||||||
routes::blogs::details,
|
routes::blogs::details,
|
||||||
routes::blogs::activity,
|
routes::blogs::activity_details,
|
||||||
routes::blogs::new,
|
routes::blogs::new,
|
||||||
routes::blogs::create,
|
routes::blogs::create,
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket_contrib::{Json, Template};
|
use rocket_contrib::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use activity_pub::Activity;
|
||||||
use activity_pub::actor::Actor;
|
use activity_pub::actor::Actor;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::blog_authors::*;
|
use models::blog_authors::*;
|
||||||
@ -17,9 +18,9 @@ fn details(name: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
|
#[get("/~/<name>", format = "application/activity+json", rank = 1)]
|
||||||
fn activity(name: String, conn: DbConn) -> Json {
|
fn activity_details(name: String, conn: DbConn) -> Activity {
|
||||||
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
|
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
|
||||||
Json(blog.as_activity_pub(&*conn))
|
blog.as_activity_pub(&*conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/blogs/new")]
|
#[get("/blogs/new")]
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
use rocket::request::Form;
|
use rocket::request::Form;
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket_contrib::{Json, Template};
|
use rocket_contrib::Template;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use activity_pub::Activity;
|
||||||
use activity_pub::actor::Actor;
|
use activity_pub::actor::Actor;
|
||||||
use db_conn::DbConn;
|
use db_conn::DbConn;
|
||||||
use models::instance::Instance;
|
use models::instance::Instance;
|
||||||
@ -19,9 +20,9 @@ fn details(name: String) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[get("/@/<name>", format = "application/activity+json", rank = 1)]
|
#[get("/@/<name>", format = "application/activity+json", rank = 1)]
|
||||||
fn activity(name: String, conn: DbConn) -> Json {
|
fn activity_details(name: String, conn: DbConn) -> Activity {
|
||||||
let user = User::find_by_name(&*conn, name).unwrap();
|
let user = User::find_by_name(&*conn, name).unwrap();
|
||||||
Json(user.as_activity_pub(&*conn))
|
user.as_activity_pub(&*conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/users/new")]
|
#[get("/users/new")]
|
||||||
|
Loading…
Reference in New Issue
Block a user