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_db_queries::source::user::User;
13 use lemmy_db_schema::source::user::User_;
14 use lemmy_structs::blocking;
15 use lemmy_utils::LemmyError;
16 use lemmy_websocket::LemmyContext;
17 use serde::Deserialize;
20 #[derive(Deserialize)]
21 pub struct UserQuery {
25 /// Return the ActivityPub json representation of a local user over HTTP.
26 pub async fn get_apub_user_http(
27 info: web::Path<UserQuery>,
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 users, so that it can send tombstones
32 let user = blocking(context.pool(), move |conn| {
33 User_::find_by_email_or_username(conn, &user_name)
38 let apub = user.to_apub(context.pool()).await?;
40 Ok(create_apub_response(&apub))
42 Ok(create_apub_tombstone_response(&user.to_tombstone()?))
46 pub async fn get_apub_user_outbox(
47 info: web::Path<UserQuery>,
48 context: web::Data<LemmyContext>,
49 ) -> Result<HttpResponse<Body>, LemmyError> {
50 let user = blocking(context.pool(), move |conn| {
51 User_::read_from_name(&conn, &info.user_name)
54 // TODO: populate the user outbox
55 let mut collection = OrderedCollection::new();
57 .set_many_items(Vec::<Url>::new())
58 .set_many_contexts(lemmy_context()?)
59 .set_id(user.get_outbox_url()?)
60 .set_total_items(0_u64);
61 Ok(create_apub_response(&collection))
64 pub async fn get_apub_user_inbox(
65 info: web::Path<UserQuery>,
66 context: web::Data<LemmyContext>,
67 ) -> Result<HttpResponse<Body>, LemmyError> {
68 let user = blocking(context.pool(), move |conn| {
69 User_::read_from_name(&conn, &info.user_name)
73 let mut collection = OrderedCollection::new();
75 .set_id(format!("{}/inbox", user.actor_id.into_inner()).parse()?)
76 .set_many_contexts(lemmy_context()?);
77 Ok(create_apub_response(&collection))