2020-12-08 17:38:48 +00:00
|
|
|
use crate::{
|
|
|
|
extensions::context::lemmy_context,
|
2021-01-12 16:12:41 +00:00
|
|
|
http::{create_apub_response, create_apub_tombstone_response},
|
2020-12-08 17:38:48 +00:00
|
|
|
objects::ToApub,
|
|
|
|
ActorType,
|
|
|
|
};
|
2020-11-18 16:04:35 +00:00
|
|
|
use activitystreams::{
|
|
|
|
base::BaseExt,
|
|
|
|
collection::{CollectionExt, OrderedCollection},
|
|
|
|
};
|
2020-10-12 14:10:09 +00:00
|
|
|
use actix_web::{body::Body, web, HttpResponse};
|
2021-03-25 19:19:40 +00:00
|
|
|
use lemmy_api_common::blocking;
|
2021-03-10 22:33:55 +00:00
|
|
|
use lemmy_db_queries::source::person::Person_;
|
|
|
|
use lemmy_db_schema::source::person::Person;
|
2020-10-12 14:10:09 +00:00
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use serde::Deserialize;
|
2020-11-18 16:04:35 +00:00
|
|
|
use url::Url;
|
2020-10-12 14:10:09 +00:00
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
2021-03-10 22:33:55 +00:00
|
|
|
pub struct PersonQuery {
|
2020-10-12 14:10:09 +00:00
|
|
|
user_name: String,
|
|
|
|
}
|
|
|
|
|
2021-03-10 22:33:55 +00:00
|
|
|
/// Return the ActivityPub json representation of a local person over HTTP.
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_http(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-10-12 14:10:09 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
|
|
|
let user_name = info.into_inner().user_name;
|
2021-03-10 22:33:55 +00:00
|
|
|
// TODO: this needs to be able to read deleted persons, so that it can send tombstones
|
|
|
|
let person = blocking(context.pool(), move |conn| {
|
|
|
|
Person::find_by_name(conn, &user_name)
|
2020-10-12 14:10:09 +00:00
|
|
|
})
|
|
|
|
.await??;
|
2021-01-12 16:12:41 +00:00
|
|
|
|
2021-03-10 22:33:55 +00:00
|
|
|
if !person.deleted {
|
|
|
|
let apub = person.to_apub(context.pool()).await?;
|
2021-01-12 16:12:41 +00:00
|
|
|
|
|
|
|
Ok(create_apub_response(&apub))
|
|
|
|
} else {
|
2021-03-10 22:33:55 +00:00
|
|
|
Ok(create_apub_tombstone_response(&person.to_tombstone()?))
|
2021-01-12 16:12:41 +00:00
|
|
|
}
|
2020-10-12 14:10:09 +00:00
|
|
|
}
|
2020-11-18 16:04:35 +00:00
|
|
|
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_outbox(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-11-18 16:04:35 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
2021-03-10 22:33:55 +00:00
|
|
|
let person = blocking(context.pool(), move |conn| {
|
|
|
|
Person::find_by_name(&conn, &info.user_name)
|
2020-11-18 16:04:35 +00:00
|
|
|
})
|
|
|
|
.await??;
|
2021-03-10 22:33:55 +00:00
|
|
|
// TODO: populate the person outbox
|
2020-11-18 16:04:35 +00:00
|
|
|
let mut collection = OrderedCollection::new();
|
|
|
|
collection
|
|
|
|
.set_many_items(Vec::<Url>::new())
|
2020-11-25 17:44:49 +00:00
|
|
|
.set_many_contexts(lemmy_context()?)
|
2021-03-10 22:33:55 +00:00
|
|
|
.set_id(person.get_outbox_url()?)
|
2020-11-18 16:04:35 +00:00
|
|
|
.set_total_items(0_u64);
|
|
|
|
Ok(create_apub_response(&collection))
|
|
|
|
}
|
2020-12-16 20:07:48 +00:00
|
|
|
|
2021-03-19 16:11:34 +00:00
|
|
|
pub(crate) async fn get_apub_person_inbox(
|
2021-03-10 22:33:55 +00:00
|
|
|
info: web::Path<PersonQuery>,
|
2020-12-16 20:07:48 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse<Body>, LemmyError> {
|
2021-03-10 22:33:55 +00:00
|
|
|
let person = blocking(context.pool(), move |conn| {
|
|
|
|
Person::find_by_name(&conn, &info.user_name)
|
2020-12-16 20:07:48 +00:00
|
|
|
})
|
|
|
|
.await??;
|
|
|
|
|
|
|
|
let mut collection = OrderedCollection::new();
|
|
|
|
collection
|
2021-03-19 16:11:34 +00:00
|
|
|
.set_id(person.inbox_url.into())
|
2020-12-16 20:07:48 +00:00
|
|
|
.set_many_contexts(lemmy_context()?);
|
|
|
|
Ok(create_apub_response(&collection))
|
|
|
|
}
|