2 activity_lists::PersonInboxActivities,
6 create_apub_tombstone_response,
10 objects::person::ApubPerson,
11 protocol::collections::person_outbox::UserOutbox,
13 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
14 use lemmy_api_common::blocking;
15 use lemmy_apub_lib::traits::ApubObject;
16 use lemmy_db_schema::source::person::Person;
17 use lemmy_utils::LemmyError;
18 use lemmy_websocket::LemmyContext;
20 use serde::Deserialize;
22 #[derive(Deserialize)]
23 pub struct PersonQuery {
27 /// Return the ActivityPub json representation of a local person over HTTP.
28 pub(crate) async fn get_apub_person_http(
29 info: web::Path<PersonQuery>,
30 context: web::Data<LemmyContext>,
31 ) -> Result<HttpResponse<Body>, LemmyError> {
32 let user_name = info.into_inner().user_name;
33 // TODO: this needs to be able to read deleted persons, so that it can send tombstones
34 let person: ApubPerson = blocking(context.pool(), move |conn| {
35 Person::find_by_name(conn, &user_name)
41 let apub = person.to_apub(&context).await?;
43 Ok(create_apub_response(&apub))
45 Ok(create_apub_tombstone_response(&person.to_tombstone()?))
49 pub async fn person_inbox(
52 _path: web::Path<String>,
53 context: web::Data<LemmyContext>,
54 ) -> Result<HttpResponse, LemmyError> {
55 let unparsed = payload_to_string(payload).await?;
56 info!("Received person inbox activity {}", unparsed);
57 let activity = serde_json::from_str::<WithContext<PersonInboxActivities>>(&unparsed)?;
58 receive_person_inbox(activity.inner(), request, &context).await
61 pub(in crate::http) async fn receive_person_inbox(
62 activity: PersonInboxActivities,
64 context: &LemmyContext,
65 ) -> Result<HttpResponse, LemmyError> {
66 receive_activity(request, activity, context).await
69 pub(crate) async fn get_apub_person_outbox(
70 info: web::Path<PersonQuery>,
71 context: web::Data<LemmyContext>,
72 ) -> Result<HttpResponse<Body>, LemmyError> {
73 let person = blocking(context.pool(), move |conn| {
74 Person::find_by_name(conn, &info.user_name)
77 let outbox = UserOutbox::new(person).await?;
78 Ok(create_apub_response(&outbox))