2 extensions::context::lemmy_context,
5 create_apub_tombstone_response,
6 inbox_enums::PersonInboxActivities,
13 use activitystreams::{
15 collection::{CollectionExt, OrderedCollection},
17 use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
18 use lemmy_api_common::blocking;
19 use lemmy_db_queries::source::person::Person_;
20 use lemmy_db_schema::source::person::Person;
21 use lemmy_utils::LemmyError;
22 use lemmy_websocket::LemmyContext;
23 use serde::Deserialize;
26 #[derive(Deserialize)]
27 pub struct PersonQuery {
31 /// Return the ActivityPub json representation of a local person over HTTP.
32 pub(crate) async fn get_apub_person_http(
33 info: web::Path<PersonQuery>,
34 context: web::Data<LemmyContext>,
35 ) -> Result<HttpResponse<Body>, LemmyError> {
36 let user_name = info.into_inner().user_name;
37 // TODO: this needs to be able to read deleted persons, so that it can send tombstones
38 let person = blocking(context.pool(), move |conn| {
39 Person::find_by_name(conn, &user_name)
44 let apub = person.to_apub(context.pool()).await?;
46 Ok(create_apub_response(&apub))
48 Ok(create_apub_tombstone_response(&person.to_tombstone()?))
52 pub async fn person_inbox(
55 _path: web::Path<String>,
56 context: web::Data<LemmyContext>,
57 ) -> Result<HttpResponse, LemmyError> {
58 let unparsed = payload_to_string(payload).await?;
59 receive_activity::<PersonInboxActivities>(request, &unparsed, context).await
62 pub(crate) async fn get_apub_person_outbox(
63 info: web::Path<PersonQuery>,
64 context: web::Data<LemmyContext>,
65 ) -> Result<HttpResponse<Body>, LemmyError> {
66 let person = blocking(context.pool(), move |conn| {
67 Person::find_by_name(conn, &info.user_name)
70 // TODO: populate the person outbox
71 let mut collection = OrderedCollection::new();
73 .set_many_items(Vec::<Url>::new())
74 .set_many_contexts(lemmy_context()?)
75 .set_id(person.get_outbox_url()?)
76 .set_total_items(0_u64);
77 Ok(create_apub_response(&collection))
80 pub(crate) async fn get_apub_person_inbox(
81 info: web::Path<PersonQuery>,
82 context: web::Data<LemmyContext>,
83 ) -> Result<HttpResponse<Body>, LemmyError> {
84 let person = blocking(context.pool(), move |conn| {
85 Person::find_by_name(conn, &info.user_name)
89 let mut collection = OrderedCollection::new();
91 .set_id(person.inbox_url.into())
92 .set_many_contexts(lemmy_context()?);
93 Ok(create_apub_response(&collection))