]> Untitled Git - lemmy.git/blob - crates/apub/src/http/person.rs
Add some more clippy lints (#2586)
[lemmy.git] / crates / apub / src / http / person.rs
1 use crate::{
2   activity_lists::PersonInboxActivitiesWithAnnouncable,
3   fetcher::user_or_community::UserOrCommunity,
4   generate_outbox_url,
5   http::{create_apub_response, create_apub_tombstone_response, receive_lemmy_activity},
6   objects::person::ApubPerson,
7   protocol::collections::empty_outbox::EmptyOutbox,
8 };
9 use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
10 use actix_web::{web, HttpRequest, HttpResponse};
11 use lemmy_db_schema::{source::person::Person, traits::ApubActor};
12 use lemmy_utils::error::LemmyError;
13 use lemmy_websocket::LemmyContext;
14 use serde::Deserialize;
15
16 #[derive(Deserialize)]
17 pub struct PersonQuery {
18   user_name: String,
19 }
20
21 /// Return the ActivityPub json representation of a local person over HTTP.
22 #[tracing::instrument(skip_all)]
23 pub(crate) async fn get_apub_person_http(
24   info: web::Path<PersonQuery>,
25   context: web::Data<LemmyContext>,
26 ) -> Result<HttpResponse, LemmyError> {
27   let user_name = info.into_inner().user_name;
28   // TODO: this needs to be able to read deleted persons, so that it can send tombstones
29   let person: ApubPerson = Person::read_from_name(context.pool(), &user_name, true)
30     .await?
31     .into();
32
33   if !person.deleted {
34     let apub = person.into_apub(&context).await?;
35
36     Ok(create_apub_response(&apub))
37   } else {
38     Ok(create_apub_tombstone_response(person.actor_id.clone()))
39   }
40 }
41
42 #[tracing::instrument(skip_all)]
43 pub async fn person_inbox(
44   request: HttpRequest,
45   payload: String,
46   context: web::Data<LemmyContext>,
47 ) -> Result<HttpResponse, LemmyError> {
48   receive_lemmy_activity::<WithContext<PersonInboxActivitiesWithAnnouncable>, UserOrCommunity>(
49     request, payload, context,
50   )
51   .await
52 }
53
54 #[tracing::instrument(skip_all)]
55 pub(crate) async fn get_apub_person_outbox(
56   info: web::Path<PersonQuery>,
57   context: web::Data<LemmyContext>,
58 ) -> Result<HttpResponse, LemmyError> {
59   let person = Person::read_from_name(context.pool(), &info.user_name, false).await?;
60   let outbox_id = generate_outbox_url(&person.actor_id)?.into();
61   let outbox = EmptyOutbox::new(outbox_id)?;
62   Ok(create_apub_response(&outbox))
63 }