Blog outbox
This commit is contained in:
parent
5e6be0cf93
commit
4666cd3ee3
@ -1,6 +1,16 @@
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::object::Object;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Activity {}
|
||||
impl Activity {
|
||||
pub fn serialize(&self) -> serde_json::Value {
|
||||
json!({})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Create<'a, T, U> where T: Actor + 'static, U: Object {
|
||||
by: &'a T,
|
||||
object: U
|
||||
|
@ -6,6 +6,8 @@ use serde_json;
|
||||
pub mod activity;
|
||||
pub mod actor;
|
||||
pub mod object;
|
||||
pub mod outbox;
|
||||
pub mod sign;
|
||||
pub mod webfinger;
|
||||
|
||||
pub type ActivityPub = Content<Json>;
|
||||
@ -14,7 +16,7 @@ pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
|
||||
|
||||
pub fn context() -> serde_json::Value {
|
||||
json!([
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
CONTEXT_URL,
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
|
38
src/activity_pub/outbox.rs
Normal file
38
src/activity_pub/outbox.rs
Normal file
@ -0,0 +1,38 @@
|
||||
use rocket::http::Status;
|
||||
use rocket::response::{Response, Responder};
|
||||
use rocket::request::Request;
|
||||
use serde_json;
|
||||
|
||||
use activity_pub::{activity_pub, ActivityPub, context};
|
||||
use activity_pub::activity::Activity;
|
||||
|
||||
pub struct Outbox {
|
||||
id: String,
|
||||
items: Vec<Activity>
|
||||
}
|
||||
|
||||
impl Outbox {
|
||||
pub fn new(id: String, items: Vec<Activity>) -> Outbox {
|
||||
Outbox {
|
||||
id: id,
|
||||
items: items
|
||||
}
|
||||
}
|
||||
|
||||
fn serialize(&self) -> ActivityPub {
|
||||
let items = self.items.clone();
|
||||
activity_pub(json!({
|
||||
"@context": context(),
|
||||
"type": "OrderedCollection",
|
||||
"id": self.id,
|
||||
"totalItems": items.len(),
|
||||
"orderedItems": items.into_iter().map(|i| i.serialize()).collect::<Vec<serde_json::Value>>()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'r> Responder<'r> for Outbox {
|
||||
fn respond_to(self, request: &Request) -> Result<Response<'r>, Status> {
|
||||
self.serialize().respond_to(request)
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ use chrono::Utc;
|
||||
use openssl::sha::{sha256, sha512};
|
||||
use serde_json;
|
||||
|
||||
// Comments are from the Mastodon source code, to knremow what to do.
|
||||
// (Comments are from the Mastodon source code, to remember what to do.)
|
||||
|
||||
pub trait Signer {
|
||||
fn get_key_id(&self) -> String;
|
||||
|
@ -79,6 +79,7 @@ fn main() {
|
||||
|
||||
routes::blogs::details,
|
||||
routes::blogs::activity_details,
|
||||
routes::blogs::outbox,
|
||||
routes::blogs::new,
|
||||
routes::blogs::create,
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
|
||||
|
||||
use activity_pub::activity::Activity;
|
||||
use activity_pub::actor::{Actor, ActorType};
|
||||
use activity_pub::outbox::Outbox;
|
||||
use activity_pub::webfinger::*;
|
||||
use models::instance::Instance;
|
||||
use schema::blogs;
|
||||
@ -65,6 +67,14 @@ impl Blog {
|
||||
.get_result::<Blog>(conn).expect("Couldn't update inbox URL");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn outbox(&self, conn: &PgConnection) -> Outbox {
|
||||
Outbox::new(self.compute_outbox(conn), self.get_activities(conn))
|
||||
}
|
||||
|
||||
fn get_activities(&self, conn: &PgConnection) -> Vec<Activity> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
impl Actor for Blog {
|
||||
|
@ -5,6 +5,7 @@ use std::collections::HashMap;
|
||||
|
||||
use activity_pub::ActivityPub;
|
||||
use activity_pub::actor::Actor;
|
||||
use activity_pub::outbox::Outbox;
|
||||
use db_conn::DbConn;
|
||||
use models::blog_authors::*;
|
||||
use models::blogs::*;
|
||||
@ -55,3 +56,9 @@ fn create(conn: DbConn, data: Form<NewBlogForm>, user: User) -> Redirect {
|
||||
|
||||
Redirect::to(format!("/~/{}", slug).as_str())
|
||||
}
|
||||
|
||||
#[get("/~/<name>/outbox")]
|
||||
fn outbox(name: String, conn: DbConn) -> Outbox {
|
||||
let blog = Blog::find_by_actor_id(&*conn, name).unwrap();
|
||||
blog.outbox(&*conn)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user