2 extensions::context::lemmy_context,
3 http::{create_apub_response, create_apub_tombstone_response},
9 collection::{CollectionExt, OrderedCollection},
11 use actix_web::{body::Body, web, HttpResponse};
12 use lemmy_api_common::blocking;
13 use lemmy_db_queries::source::person::Person_;
14 use lemmy_db_schema::source::person::Person;
15 use lemmy_utils::LemmyError;
16 use lemmy_websocket::LemmyContext;
17 use serde::Deserialize;
20 #[derive(Deserialize)]
21 pub struct PersonQuery {
25 /// Return the ActivityPub json representation of a local person over HTTP.
26 pub(crate) async fn get_apub_person_http(
27 info: web::Path<PersonQuery>,
28 context: web::Data<LemmyContext>,
29 ) -> Result<HttpResponse<Body>, LemmyError> {
30 let user_name = info.into_inner().user_name;
31 // TODO: this needs to be able to read deleted persons, so that it can send tombstones
32 let person = blocking(context.pool(), move |conn| {
33 Person::find_by_name(conn, &user_name)
38 let apub = person.to_apub(context.pool()).await?;
40 Ok(create_apub_response(&apub))
42 Ok(create_apub_tombstone_response(&person.to_tombstone()?))
46 pub(crate) async fn get_apub_person_outbox(
47 info: web::Path<PersonQuery>,
48 context: web::Data<LemmyContext>,
49 ) -> Result<HttpResponse<Body>, LemmyError> {
50 let person = blocking(context.pool(), move |conn| {
51 Person::find_by_name(&conn, &info.user_name)
54 // TODO: populate the person outbox
55 let mut collection = OrderedCollection::new();
57 .set_many_items(Vec::<Url>::new())
58 .set_many_contexts(lemmy_context()?)
59 .set_id(person.get_outbox_url()?)
60 .set_total_items(0_u64);
61 Ok(create_apub_response(&collection))
64 pub(crate) async fn get_apub_person_inbox(
65 info: web::Path<PersonQuery>,
66 context: web::Data<LemmyContext>,
67 ) -> Result<HttpResponse<Body>, LemmyError> {
68 let person = blocking(context.pool(), move |conn| {
69 Person::find_by_name(&conn, &info.user_name)
73 let mut collection = OrderedCollection::new();
75 .set_id(person.inbox_url.into())
76 .set_many_contexts(lemmy_context()?);
77 Ok(create_apub_response(&collection))