diff --git a/src/main.rs b/src/main.rs index c0217808..107437f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,6 +69,7 @@ fn main() { routes::user::activity_details, routes::user::outbox, routes::user::inbox, + routes::user::followers, routes::user::new, routes::user::create, diff --git a/src/routes/user.rs b/src/routes/user.rs index 13b5f9f4..62d29033 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -4,8 +4,7 @@ use rocket_contrib::Template; use serde_json; use std::collections::HashMap; -use activity_pub::ActivityPub; -use activity_pub::activity; +use activity_pub::{activity, activity_pub, ActivityPub, context}; use activity_pub::actor::Actor; use activity_pub::inbox::Inbox; use activity_pub::outbox::Outbox; @@ -90,3 +89,18 @@ fn inbox(name: String, conn: DbConn, data: String) -> String { user.received(&*conn, act); String::from("") } + +#[get("/@//followers")] +fn followers(name: String, conn: DbConn) -> ActivityPub { + let user = User::find_local(&*conn, name).unwrap(); + let followers = user.get_followers(&*conn).into_iter().map(|f| f.compute_id(&*conn)).collect::>(); + + let json = json!({ + "@context": context(), + "id": user.compute_box(&*conn, "followers"), + "type": "OrderedCollection", + "totalItems": followers.len(), + "orderedItems": followers + }); + activity_pub(json) +}