Blog outbox

This commit is contained in:
Bat
2018-04-29 18:49:56 +01:00
parent 5e6be0cf93
commit 4666cd3ee3
7 changed files with 70 additions and 2 deletions
+10
View File
@@ -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
+3 -1
View File
@@ -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
View 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)
}
}
+1 -1
View File
@@ -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;