8 // Turn a Lemmy user into an ActivityPub person and return it as json.
9 pub async fn get_apub_user(
10 info: Path<UserQuery>,
12 chat_server: ChatServerParam,
13 ) -> Result<HttpResponse<Body>, Error> {
14 let user = User_::find_by_email_or_username(&&db.get()?, &info.user_name)?;
16 let mut person = Person::default();
17 let oprops: &mut ObjectProperties = person.as_mut();
19 .set_context_xsd_any_uri(context())?
20 .set_id(user.actor_id.to_string())?
21 .set_name_xsd_string(user.name.to_owned())?
22 .set_published(convert_datetime(user.published))?;
24 if let Some(u) = user.updated {
25 oprops.set_updated(convert_datetime(u))?;
28 if let Some(i) = &user.preferred_username {
29 oprops.set_name_xsd_string(i.to_owned())?;
32 let mut actor_props = ApActorProperties::default();
35 .set_inbox(format!("{}/inbox", &user.actor_id))?
36 .set_outbox(format!("{}/outbox", &user.actor_id))?
37 .set_following(format!("{}/following", &user.actor_id))?
38 .set_liked(format!("{}/liked", &user.actor_id))?;
40 let public_key = PublicKey {
41 id: format!("{}#main-key", user.actor_id),
42 owner: user.actor_id.to_owned(),
43 public_key_pem: user.public_key.unwrap(),
46 Ok(create_apub_response(
47 &person.extend(actor_props).extend(public_key.to_ext()),
52 /// Parse an ActivityPub person received from another instance into a Lemmy user.
53 pub fn from_person(person: &PersonExt) -> Result<Self, Error> {
54 let oprops = &person.base.base.object_props;
55 let aprops = &person.base.extension;
56 let public_key: &PublicKey = &person.extension.public_key;
59 name: oprops.get_name_xsd_string().unwrap().to_string(),
60 preferred_username: aprops.get_preferred_username().map(|u| u.to_string()),
61 password_encrypted: "".to_string(),
65 avatar: None, // -> icon, image
68 .map(|u| u.as_ref().to_owned().naive_local()),
70 theme: "".to_string(),
72 default_listing_type: 0,
75 send_notifications_to_email: false,
77 actor_id: oprops.get_id().unwrap().to_string(),
78 bio: oprops.get_summary_xsd_string().map(|s| s.to_string()),
81 public_key: Some(public_key.to_owned().public_key_pem),
82 last_refreshed_at: Some(naive_now()),