1 use crate::apub::{create_apub_response, make_apub_endpoint, EndpointType};
2 use crate::convert_datetime;
3 use crate::db::user::User_;
5 actor::{properties::ApActorProperties, Person},
8 object::properties::ObjectProperties,
10 use actix_web::body::Body;
11 use actix_web::web::Path;
12 use actix_web::HttpResponse;
13 use actix_web::{web, Result};
14 use diesel::r2d2::{ConnectionManager, Pool};
15 use diesel::PgConnection;
17 use serde::Deserialize;
19 #[derive(Deserialize)]
20 pub struct UserQuery {
24 pub async fn get_apub_user(
25 info: Path<UserQuery>,
26 db: web::Data<Pool<ConnectionManager<PgConnection>>>,
27 ) -> Result<HttpResponse<Body>, Error> {
28 let user = User_::find_by_email_or_username(&&db.get()?, &info.user_name)?;
29 let base_url = make_apub_endpoint(EndpointType::User, &user.name);
31 let mut person = Person::default();
32 let oprops: &mut ObjectProperties = person.as_mut();
34 .set_context_xsd_any_uri(context())?
35 .set_id(base_url.to_string())?
36 .set_published(convert_datetime(user.published))?;
38 if let Some(u) = user.updated {
39 oprops.set_updated(convert_datetime(u))?;
42 if let Some(i) = &user.preferred_username {
43 oprops.set_name_xsd_string(i.to_owned())?;
46 let mut actor_props = ApActorProperties::default();
49 .set_inbox(format!("{}/inbox", &base_url))?
50 .set_outbox(format!("{}/outbox", &base_url))?
51 .set_following(format!("{}/following", &base_url))?
52 .set_liked(format!("{}/liked", &base_url))?;
54 Ok(create_apub_response(&person.extend(actor_props)))