1
0
Fork 0
forked from alemi/upub

feat: parse and serve shared_inbox endpoint

This commit is contained in:
əlemi 2024-05-15 18:51:34 +02:00
parent 461526df12
commit 94a26a0c7d
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 14 additions and 7 deletions

View file

@ -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)
}
}

View file

@ -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);