1 use crate::http::{create_apub_response, create_apub_tombstone_response};
4 collection::{CollectionExt, OrderedCollection},
6 use actix_web::{body::Body, web, HttpResponse};
7 use lemmy_api_common::blocking;
8 use lemmy_apub::{extensions::context::lemmy_context, objects::ToApub, ActorType};
9 use lemmy_db_queries::source::person::Person_;
10 use lemmy_db_schema::source::person::Person;
11 use lemmy_utils::LemmyError;
12 use lemmy_websocket::LemmyContext;
13 use serde::Deserialize;
16 #[derive(Deserialize)]
17 pub struct PersonQuery {
21 /// Return the ActivityPub json representation of a local person over HTTP.
22 pub(crate) async fn get_apub_person_http(
23 info: web::Path<PersonQuery>,
24 context: web::Data<LemmyContext>,
25 ) -> Result<HttpResponse<Body>, 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 = blocking(context.pool(), move |conn| {
29 Person::find_by_name(conn, &user_name)
34 let apub = person.to_apub(context.pool()).await?;
36 Ok(create_apub_response(&apub))
38 Ok(create_apub_tombstone_response(&person.to_tombstone()?))
42 pub(crate) async fn get_apub_person_outbox(
43 info: web::Path<PersonQuery>,
44 context: web::Data<LemmyContext>,
45 ) -> Result<HttpResponse<Body>, LemmyError> {
46 let person = blocking(context.pool(), move |conn| {
47 Person::find_by_name(&conn, &info.user_name)
50 // TODO: populate the person outbox
51 let mut collection = OrderedCollection::new();
53 .set_many_items(Vec::<Url>::new())
54 .set_many_contexts(lemmy_context()?)
55 .set_id(person.get_outbox_url()?)
56 .set_total_items(0_u64);
57 Ok(create_apub_response(&collection))
60 pub(crate) async fn get_apub_person_inbox(
61 info: web::Path<PersonQuery>,
62 context: web::Data<LemmyContext>,
63 ) -> Result<HttpResponse<Body>, LemmyError> {
64 let person = blocking(context.pool(), move |conn| {
65 Person::find_by_name(&conn, &info.user_name)
69 let mut collection = OrderedCollection::new();
71 .set_id(person.inbox_url.into())
72 .set_many_contexts(lemmy_context()?);
73 Ok(create_apub_response(&collection))