]> Untitled Git - lemmy.git/blobdiff - crates/apub/src/http/person.rs
Implement instance actor (#1798)
[lemmy.git] / crates / apub / src / http / person.rs
index 3a3a340387f0e3c7fd16f628082e685742d1e8fa..9081d5a554dc7d27250442112379c8810acde490 100644 (file)
@@ -1,6 +1,7 @@
 use crate::{
   activity_lists::PersonInboxActivities,
   context::WithContext,
+  generate_outbox_url,
   http::{
     create_apub_response,
     create_apub_tombstone_response,
@@ -9,16 +10,16 @@ use crate::{
     ActivityCommonFields,
   },
   objects::person::ApubPerson,
-  protocol::collections::person_outbox::PersonOutbox,
+  protocol::collections::empty_outbox::EmptyOutbox,
 };
-use actix_web::{body::Body, web, web::Payload, HttpRequest, HttpResponse};
+use actix_web::{web, web::Payload, HttpRequest, HttpResponse};
 use lemmy_api_common::blocking;
 use lemmy_apub_lib::traits::ApubObject;
-use lemmy_db_schema::source::person::Person;
+use lemmy_db_schema::{source::person::Person, traits::ApubActor};
 use lemmy_utils::LemmyError;
 use lemmy_websocket::LemmyContext;
-use log::info;
 use serde::Deserialize;
+use tracing::info;
 
 #[derive(Deserialize)]
 pub struct PersonQuery {
@@ -26,14 +27,15 @@ pub struct PersonQuery {
 }
 
 /// Return the ActivityPub json representation of a local person over HTTP.
+#[tracing::instrument(skip_all)]
 pub(crate) async fn get_apub_person_http(
   info: web::Path<PersonQuery>,
   context: web::Data<LemmyContext>,
-) -> Result<HttpResponse<Body>, LemmyError> {
+) -> Result<HttpResponse, LemmyError> {
   let user_name = info.into_inner().user_name;
   // TODO: this needs to be able to read deleted persons, so that it can send tombstones
   let person: ApubPerson = blocking(context.pool(), move |conn| {
-    Person::find_by_name(conn, &user_name)
+    Person::read_from_name(conn, &user_name)
   })
   .await??
   .into();
@@ -47,6 +49,7 @@ pub(crate) async fn get_apub_person_http(
   }
 }
 
+#[tracing::instrument(skip_all)]
 pub async fn person_inbox(
   request: HttpRequest,
   payload: Payload,
@@ -69,14 +72,16 @@ pub(in crate::http) async fn receive_person_inbox(
   receive_activity(request, activity, activity_data, context).await
 }
 
+#[tracing::instrument(skip_all)]
 pub(crate) async fn get_apub_person_outbox(
   info: web::Path<PersonQuery>,
   context: web::Data<LemmyContext>,
-) -> Result<HttpResponse<Body>, LemmyError> {
+) -> Result<HttpResponse, LemmyError> {
   let person = blocking(context.pool(), move |conn| {
-    Person::find_by_name(conn, &info.user_name)
+    Person::read_from_name(conn, &info.user_name)
   })
   .await??;
-  let outbox = PersonOutbox::new(person).await?;
+  let outbox_id = generate_outbox_url(&person.actor_id)?.into();
+  let outbox = EmptyOutbox::new(outbox_id).await?;
   Ok(create_apub_response(&outbox))
 }