8 impl ToApub<PersonExt> for User_ {
9 // Turn a Lemmy Community into an ActivityPub group that can be sent out over the network.
10 fn to_apub(&self, _conn: &PgConnection) -> Result<PersonExt, Error> {
11 // TODO go through all these to_string and to_owned()
12 let mut person = Person::default();
13 let oprops: &mut ObjectProperties = person.as_mut();
15 .set_context_xsd_any_uri(context())?
16 .set_id(self.actor_id.to_string())?
17 .set_name_xsd_string(self.name.to_owned())?
18 .set_published(convert_datetime(self.published))?;
20 if let Some(u) = self.updated {
21 oprops.set_updated(convert_datetime(u))?;
24 if let Some(i) = &self.preferred_username {
25 oprops.set_name_xsd_string(i.to_owned())?;
28 let mut actor_props = ApActorProperties::default();
31 .set_inbox(self.get_inbox_url())?
32 .set_outbox(self.get_outbox_url())?
33 .set_followers(self.get_followers_url())?
34 .set_following(self.get_following_url())?
35 .set_liked(self.get_liked_url())?;
37 let public_key = PublicKey {
38 id: format!("{}#main-key", self.actor_id),
39 owner: self.actor_id.to_owned(),
40 public_key_pem: self.public_key.to_owned().unwrap(),
43 Ok(person.extend(actor_props).extend(public_key.to_ext()))
47 impl ActorType for User_ {
48 fn actor_id(&self) -> String {
49 self.actor_id.to_owned()
53 impl FromApub<PersonExt> for UserForm {
54 /// Parse an ActivityPub person received from another instance into a Lemmy user.
55 fn from_apub(person: &PersonExt, _conn: &PgConnection) -> Result<Self, Error> {
56 let oprops = &person.base.base.object_props;
57 let aprops = &person.base.extension;
58 let public_key: &PublicKey = &person.extension.public_key;
61 name: oprops.get_name_xsd_string().unwrap().to_string(),
62 preferred_username: aprops.get_preferred_username().map(|u| u.to_string()),
63 password_encrypted: "".to_string(),
67 avatar: None, // -> icon, image
70 .map(|u| u.as_ref().to_owned().naive_local()),
72 theme: "".to_string(),
74 default_listing_type: 0,
77 send_notifications_to_email: false,
79 actor_id: oprops.get_id().unwrap().to_string(),
80 bio: oprops.get_summary_xsd_string().map(|s| s.to_string()),
83 public_key: Some(public_key.to_owned().public_key_pem),
84 last_refreshed_at: Some(naive_now()),
89 /// Return the user json over HTTP.
90 pub async fn get_apub_user_http(
91 info: Path<UserQuery>,
93 ) -> Result<HttpResponse<Body>, Error> {
94 let user = User_::find_by_email_or_username(&&db.get()?, &info.user_name)?;
95 let u = user.to_apub(&db.get().unwrap())?;
96 Ok(create_apub_response(&u))