From 94a26a0c7dcd51f47b9427c0df178f231becdd83 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 15 May 2024 18:51:34 +0200 Subject: [PATCH] feat: parse and serve shared_inbox endpoint --- src/model/user.rs | 13 ++++++++----- src/routes/activitypub/user/mod.rs | 8 ++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/model/user.rs b/src/model/user.rs index 58e9cc0f..9aaf3410 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -1,6 +1,6 @@ use sea_orm::entity::prelude::*; -use apb::{Actor, ActorMut, ActorType, BaseMut, DocumentMut, Object, ObjectMut, PublicKey, PublicKeyMut}; +use apb::{Actor, ActorMut, ActorType, BaseMut, DocumentMut, Endpoints, EndpointsMut, Object, ObjectMut, PublicKey, PublicKeyMut}; use crate::routes::activitypub::jsonld::LD; @@ -50,11 +50,11 @@ impl Model { actor_type: object.actor_type().ok_or(super::FieldError("type"))?, name: object.name().map(|x| x.to_string()), summary: object.summary().map(|x| x.to_string()), - icon: object.icon().get().map(|x| x.url().id().unwrap_or_default()), - image: object.image().get().map(|x| x.url().id().unwrap_or_default()), + icon: object.icon().get().and_then(|x| x.url().id()), + image: object.image().get().and_then(|x| x.url().id()), inbox: object.inbox().id(), outbox: object.outbox().id(), - shared_inbox: None, // TODO!!! parse endpoints + shared_inbox: object.endpoints().get().and_then(|x| Some(x.shared_inbox()?.to_string())), followers: object.followers().id(), following: object.following().id(), created: object.published().unwrap_or(chrono::Utc::now()), @@ -98,8 +98,11 @@ impl Model { .set_owner(Some(&self.id)) .set_public_key_pem(&self.public_key) )) + .set_endpoints(apb::Node::object( + serde_json::Value::new_object() + .set_shared_inbox(self.shared_inbox.as_deref()) + )) .set_discoverable(Some(true)) - .set_endpoints(apb::Node::Empty) } } diff --git a/src/routes/activitypub/user/mod.rs b/src/routes/activitypub/user/mod.rs index 2b378194..05508347 100644 --- a/src/routes/activitypub/user/mod.rs +++ b/src/routes/activitypub/user/mod.rs @@ -7,7 +7,7 @@ pub mod following; use axum::extract::{Path, Query, State}; use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect, SelectColumns}; -use apb::{ActorMut, Node}; +use apb::{ActorMut, EndpointsMut, Node}; use crate::{errors::UpubError, model::{self, user}, server::{auth::AuthIdentity, fetcher::Fetcher, Context}, url}; use super::{jsonld::LD, JsonLD, TryFetch}; @@ -73,7 +73,11 @@ pub async fn view( .set_following(Node::link(url!(ctx, "/users/{id}/following"))) .set_followers(Node::link(url!(ctx, "/users/{id}/followers"))) .set_following_me(following_me) - .set_followed_by_me(followed_by_me); + .set_followed_by_me(followed_by_me) + .set_endpoints(Node::object( + serde_json::Value::new_object() + .set_shared_inbox(Some(&url!(ctx, "/inbox"))) + )); if !auth.is(&uid) && !cfg.show_followers_count { user = user.set_followers_count(None);