1 use crate::apub::make_apub_endpoint;
2 use crate::db::establish_unpooled_connection;
3 use crate::db::user::User_;
4 use crate::to_datetime_utc;
5 use activitypub::{actor::Person, context};
6 use actix_web::body::Body;
7 use actix_web::web::Path;
8 use actix_web::HttpResponse;
9 use serde::Deserialize;
12 pub fn as_person(&self) -> Person {
13 let base_url = make_apub_endpoint("u", &self.name);
14 let mut person = Person::default();
15 person.object_props.set_context_object(context()).ok();
16 person.object_props.set_id_string(base_url.to_string()).ok();
19 .set_name_string(self.name.to_owned())
23 .set_published_utctime(to_datetime_utc(self.published))
25 if let Some(updated) = self.updated {
28 .set_updated_utctime(to_datetime_utc(updated))
34 .set_inbox_string(format!("{}/inbox", &base_url))
38 .set_outbox_string(format!("{}/outbox", &base_url))
42 .set_following_string(format!("{}/following", &base_url))
46 .set_liked_string(format!("{}/liked", &base_url))
48 if let Some(i) = &self.preferred_username {
51 .set_preferred_username_string(i.to_string())
59 #[derive(Deserialize)]
60 pub struct UserQuery {
64 pub async fn get_apub_user(info: Path<UserQuery>) -> HttpResponse<Body> {
65 let connection = establish_unpooled_connection();
67 if let Ok(user) = User_::find_by_email_or_username(&connection, &info.user_name) {
69 .content_type("application/activity+json")
70 .body(serde_json::to_string(&user.as_person()).unwrap())
72 HttpResponse::NotFound().finish()