From 92af83565ed0dcf7278e4c159d3daa053d89bac9 Mon Sep 17 00:00:00 2001 From: Bat Date: Fri, 4 May 2018 14:13:55 +0100 Subject: [PATCH] Add an AP followers endpoint for users --- src/main.rs | 1 + src/routes/user.rs | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) 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) +}