2 activity_lists::PersonInboxActivitiesWithAnnouncable,
3 fetcher::user_or_community::UserOrCommunity,
4 http::{create_apub_response, create_apub_tombstone_response, receive_lemmy_activity},
5 objects::person::ApubPerson,
6 protocol::collections::empty_outbox::EmptyOutbox,
8 use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
9 use actix_web::{web, HttpRequest, HttpResponse};
10 use lemmy_api_common::{context::LemmyContext, utils::generate_outbox_url};
11 use lemmy_db_schema::{source::person::Person, traits::ApubActor};
12 use lemmy_utils::error::LemmyError;
13 use serde::Deserialize;
15 #[derive(Deserialize)]
16 pub struct PersonQuery {
20 /// Return the ActivityPub json representation of a local person over HTTP.
21 #[tracing::instrument(skip_all)]
22 pub(crate) async fn get_apub_person_http(
23 info: web::Path<PersonQuery>,
24 context: web::Data<LemmyContext>,
25 ) -> Result<HttpResponse, LemmyError> {
26 let user_name = info.into_inner().user_name;
27 // TODO: this needs to be able to read deleted persons, so that it can send tombstones
28 let person: ApubPerson = Person::read_from_name(context.pool(), &user_name, true)
33 let apub = person.into_apub(&context).await?;
35 Ok(create_apub_response(&apub))
37 Ok(create_apub_tombstone_response(person.actor_id.clone()))
41 #[tracing::instrument(skip_all)]
42 pub async fn person_inbox(
45 context: web::Data<LemmyContext>,
46 ) -> Result<HttpResponse, LemmyError> {
47 receive_lemmy_activity::<WithContext<PersonInboxActivitiesWithAnnouncable>, UserOrCommunity>(
48 request, payload, context,
53 #[tracing::instrument(skip_all)]
54 pub(crate) async fn get_apub_person_outbox(
55 info: web::Path<PersonQuery>,
56 context: web::Data<LemmyContext>,
57 ) -> Result<HttpResponse, LemmyError> {
58 let person = Person::read_from_name(context.pool(), &info.user_name, false).await?;
59 let outbox_id = generate_outbox_url(&person.actor_id)?.into();
60 let outbox = EmptyOutbox::new(outbox_id)?;
61 Ok(create_apub_response(&outbox))