mirror of
https://git.joinplu.me/Plume/Plume.git
synced 2024-11-25 13:01:08 +00:00
Refactor ActivityPub
This commit is contained in:
parent
270786ad3d
commit
0b00849a62
5 changed files with 50 additions and 33 deletions
|
@ -1,6 +1,6 @@
|
|||
use diesel::PgConnection;
|
||||
use serde_json::Value;
|
||||
|
||||
use activity_pub::{activity, Activity, context};
|
||||
use models::instance::Instance;
|
||||
|
||||
pub enum ActorType {
|
||||
|
@ -26,29 +26,9 @@ pub trait Actor {
|
|||
|
||||
fn get_actor_type() -> ActorType;
|
||||
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> Value {
|
||||
json!({
|
||||
"@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"
|
||||
}
|
||||
],
|
||||
fn as_activity_pub (&self, conn: &PgConnection) -> Activity {
|
||||
activity(json!({
|
||||
"@context": context(),
|
||||
"id": self.compute_id(conn),
|
||||
"type": Self::get_actor_type().to_string(),
|
||||
"inbox": self.compute_inbox(conn),
|
||||
|
@ -60,7 +40,7 @@ pub trait Actor {
|
|||
"endpoints": {
|
||||
"sharedInbox": "https://plu.me/inbox"
|
||||
}
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
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 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::details,
|
||||
routes::user::activity,
|
||||
routes::user::activity_details,
|
||||
routes::user::new,
|
||||
routes::user::create,
|
||||
|
||||
|
@ -70,7 +70,7 @@ fn main() {
|
|||
routes::session::delete,
|
||||
|
||||
routes::blogs::details,
|
||||
routes::blogs::activity,
|
||||
routes::blogs::activity_details,
|
||||
routes::blogs::new,
|
||||
routes::blogs::create,
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use rocket::request::Form;
|
||||
use rocket::response::Redirect;
|
||||
use rocket_contrib::{Json, Template};
|
||||
use rocket_contrib::Template;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use activity_pub::Activity;
|
||||
use activity_pub::actor::Actor;
|
||||
use db_conn::DbConn;
|
||||
use models::blog_authors::*;
|
||||
|
@ -17,9 +18,9 @@ fn details(name: String) -> String {
|
|||
}
|
||||
|
||||
#[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();
|
||||
Json(blog.as_activity_pub(&*conn))
|
||||
blog.as_activity_pub(&*conn)
|
||||
}
|
||||
|
||||
#[get("/blogs/new")]
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use rocket::request::Form;
|
||||
use rocket::response::Redirect;
|
||||
use rocket_contrib::{Json, Template};
|
||||
use rocket_contrib::Template;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use activity_pub::Activity;
|
||||
use activity_pub::actor::Actor;
|
||||
use db_conn::DbConn;
|
||||
use models::instance::Instance;
|
||||
|
@ -19,9 +20,9 @@ fn details(name: String) -> String {
|
|||
}
|
||||
|
||||
#[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();
|
||||
Json(user.as_activity_pub(&*conn))
|
||||
user.as_activity_pub(&*conn)
|
||||
}
|
||||
|
||||
#[get("/users/new")]
|
||||
|
|
Loading…
Reference in a new issue