3 create_apub_tombstone_response,
4 inbox_enums::PersonInboxActivities,
10 collection::{CollectionExt, OrderedCollection},
12 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
13 use lemmy_api_common::blocking;
14 use lemmy_apub::{extensions::context::lemmy_context, objects::ToApub, ActorType};
15 use lemmy_db_queries::source::person::Person_;
16 use lemmy_db_schema::source::person::Person;
17 use lemmy_utils::LemmyError;
18 use lemmy_websocket::LemmyContext;
19 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 = blocking(context.pool(), move |conn| {
35 Person::find_by_name(conn, &user_name)
40 let apub = person.to_apub(context.pool()).await?;
42 Ok(create_apub_response(&apub))
44 Ok(create_apub_tombstone_response(&person.to_tombstone()?))
48 pub async fn person_inbox(
51 _path: web::Path<String>,
52 context: web::Data<LemmyContext>,
53 ) -> Result<HttpResponse, LemmyError> {
54 let unparsed = payload_to_string(payload).await?;
55 receive_activity::<PersonInboxActivities>(request, &unparsed, context).await
58 pub(crate) async fn get_apub_person_outbox(
59 info: web::Path<PersonQuery>,
60 context: web::Data<LemmyContext>,
61 ) -> Result<HttpResponse<Body>, LemmyError> {
62 let person = blocking(context.pool(), move |conn| {
63 Person::find_by_name(conn, &info.user_name)
66 // TODO: populate the person outbox
67 let mut collection = OrderedCollection::new();
69 .set_many_items(Vec::<Url>::new())
70 .set_many_contexts(lemmy_context()?)
71 .set_id(person.get_outbox_url()?)
72 .set_total_items(0_u64);
73 Ok(create_apub_response(&collection))
76 pub(crate) async fn get_apub_person_inbox(
77 info: web::Path<PersonQuery>,
78 context: web::Data<LemmyContext>,
79 ) -> Result<HttpResponse<Body>, LemmyError> {
80 let person = blocking(context.pool(), move |conn| {
81 Person::find_by_name(conn, &info.user_name)
85 let mut collection = OrderedCollection::new();
87 .set_id(person.inbox_url.into())
88 .set_many_contexts(lemmy_context()?);
89 Ok(create_apub_response(&collection))