1 extern crate activitypub;
2 use self::activitypub::{context, actor::Person};
3 use crate::db::user::User_;
6 pub fn person(&self) -> Person {
7 use crate::{Settings, to_datetime_utc};
8 let base_url = &format!("{}/user/{}", Settings::get().api_endpoint(), self.name);
9 let mut person = Person::default();
10 person.object_props.set_context_object(context()).ok();
11 person.object_props.set_id_string(base_url.to_string()).ok();
12 person.object_props.set_name_string(self.name.to_owned()).ok();
13 person.object_props.set_published_utctime(to_datetime_utc(self.published)).ok();
14 if let Some(i) = self.updated {
15 person.object_props.set_updated_utctime(to_datetime_utc(i)).ok();
17 // person.object_props.summary = self.summary;
19 person.ap_actor_props.set_inbox_string(format!("{}/inbox", &base_url)).ok();
20 person.ap_actor_props.set_outbox_string(format!("{}/outbox", &base_url)).ok();
21 person.ap_actor_props.set_following_string(format!("{}/following", &base_url)).ok();
22 person.ap_actor_props.set_liked_string(format!("{}/liked", &base_url)).ok();
23 if let Some(i) = &self.preferred_username {
24 person.ap_actor_props.set_preferred_username_string(i.to_string()).ok();
38 let expected_user = User_ {
41 fedi_name: "rrf".into(),
42 preferred_username: None,
43 password_encrypted: "here".into(),
46 published: naive_now(),
53 let person = expected_user.person();
54 assert_eq!("rrr/api/v1/user/thom", person.object_props.id_string().unwrap());
55 let json = serde_json::to_string_pretty(&person).unwrap();