From 20415a038663dae65d68545c3f40901dd8916c16 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 22 Mar 2024 01:52:02 +0100 Subject: [PATCH] feat: barebones following/followers collections --- src/activitypub/user.rs | 28 ++++++++++++++++++++++++++++ src/activitypub/well_known.rs | 2 ++ src/server.rs | 2 ++ 3 files changed, 32 insertions(+) diff --git a/src/activitypub/user.rs b/src/activitypub/user.rs index 464403d4..493cc361 100644 --- a/src/activitypub/user.rs +++ b/src/activitypub/user.rs @@ -22,6 +22,34 @@ pub async fn view(State(ctx) : State, Path(id): Path) -> Result } } +pub async fn followers( + State(ctx): State, + Path(id): Path, +) -> Result, StatusCode> { + Ok(JsonLD( + serde_json::Value::new_object() + .set_id(Some(&format!("{}/users/{}/followers", ctx.base(), id))) + .set_collection_type(Some(CollectionType::OrderedCollection)) + .set_total_items(Some(0)) + .set_first(Node::link(format!("{}/users/{}/followers?page=true", ctx.base(), id))) + .ld_context() + )) +} + +pub async fn following( + State(ctx): State, + Path(id): Path, +) -> Result, StatusCode> { + Ok(JsonLD( + serde_json::Value::new_object() + .set_id(Some(&format!("{}/users/{}/following", ctx.base(), id))) + .set_collection_type(Some(CollectionType::OrderedCollection)) + .set_total_items(Some(0)) + .set_first(Node::link(format!("{}/users/{}/following?page=true", ctx.base(), id))) + .ld_context() + )) +} + pub async fn outbox( State(ctx): State, Path(id): Path, diff --git a/src/activitypub/well_known.rs b/src/activitypub/well_known.rs index 36abcca9..910e73e5 100644 --- a/src/activitypub/well_known.rs +++ b/src/activitypub/well_known.rs @@ -30,6 +30,8 @@ pub async fn nodeinfo_discovery(State(ctx): State) -> Json, Path(version): Path) -> Result, StatusCode> { // TODO it's unsustainable to count these every time, especially comments since it's a complex // filter! keep these numbers caches somewhere, maybe db, so that we can just look them up diff --git a/src/server.rs b/src/server.rs index 3388be5c..1be31c01 100644 --- a/src/server.rs +++ b/src/server.rs @@ -86,6 +86,8 @@ pub async fn serve(db: DatabaseConnection, domain: String) { .route("/users/:id", get(ap::user::view)) .route("/users/:id/inbox", post(ap::user::inbox)) .route("/users/:id/outbox", get(ap::user::outbox)) + .route("/users/:id/followers", get(ap::user::followers)) + .route("/users/:id/following", get(ap::user::following)) // specific object routes .route("/activities/:id", get(ap::activity::view)) .route("/objects/:id", get(ap::object::view))