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