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