Add an AP followers endpoint for users

This commit is contained in:
Bat 2018-05-04 14:13:55 +01:00
parent 0ef12ff0f5
commit 92af83565e
2 changed files with 17 additions and 2 deletions

View File

@ -69,6 +69,7 @@ fn main() {
routes::user::activity_details, routes::user::activity_details,
routes::user::outbox, routes::user::outbox,
routes::user::inbox, routes::user::inbox,
routes::user::followers,
routes::user::new, routes::user::new,
routes::user::create, routes::user::create,

View File

@ -4,8 +4,7 @@ use rocket_contrib::Template;
use serde_json; use serde_json;
use std::collections::HashMap; use std::collections::HashMap;
use activity_pub::ActivityPub; use activity_pub::{activity, activity_pub, ActivityPub, context};
use activity_pub::activity;
use activity_pub::actor::Actor; use activity_pub::actor::Actor;
use activity_pub::inbox::Inbox; use activity_pub::inbox::Inbox;
use activity_pub::outbox::Outbox; use activity_pub::outbox::Outbox;
@ -90,3 +89,18 @@ fn inbox(name: String, conn: DbConn, data: String) -> String {
user.received(&*conn, act); user.received(&*conn, act);
String::from("") String::from("")
} }
#[get("/@/<name>/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::<Vec<String>>();
let json = json!({
"@context": context(),
"id": user.compute_box(&*conn, "followers"),
"type": "OrderedCollection",
"totalItems": followers.len(),
"orderedItems": followers
});
activity_pub(json)
}