2019-03-05 03:52:09 +00:00
|
|
|
extern crate activitypub;
|
|
|
|
use self::activitypub::{context, actor::Person};
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::db::user::User_;
|
2019-03-05 03:52:09 +00:00
|
|
|
|
|
|
|
impl User_ {
|
|
|
|
pub fn person(&self) -> Person {
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::{Settings, to_datetime_utc};
|
2019-03-05 03:52:09 +00:00
|
|
|
let base_url = &format!("{}/user/{}", Settings::get().api_endpoint(), self.name);
|
|
|
|
let mut person = Person::default();
|
|
|
|
person.object_props.set_context_object(context()).ok();
|
|
|
|
person.object_props.set_id_string(base_url.to_string()).ok();
|
|
|
|
person.object_props.set_name_string(self.name.to_owned()).ok();
|
|
|
|
person.object_props.set_published_utctime(to_datetime_utc(self.published)).ok();
|
|
|
|
if let Some(i) = self.updated {
|
|
|
|
person.object_props.set_updated_utctime(to_datetime_utc(i)).ok();
|
|
|
|
}
|
|
|
|
// person.object_props.summary = self.summary;
|
|
|
|
|
|
|
|
person.ap_actor_props.set_inbox_string(format!("{}/inbox", &base_url)).ok();
|
|
|
|
person.ap_actor_props.set_outbox_string(format!("{}/outbox", &base_url)).ok();
|
|
|
|
person.ap_actor_props.set_following_string(format!("{}/following", &base_url)).ok();
|
|
|
|
person.ap_actor_props.set_liked_string(format!("{}/liked", &base_url)).ok();
|
|
|
|
if let Some(i) = &self.preferred_username {
|
|
|
|
person.ap_actor_props.set_preferred_username_string(i.to_string()).ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
person
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::User_;
|
2019-06-03 17:47:12 +00:00
|
|
|
use crate::naive_now;
|
2019-03-05 03:52:09 +00:00
|
|
|
|
2019-03-21 01:22:31 +00:00
|
|
|
#[test]
|
2019-03-05 03:52:09 +00:00
|
|
|
fn test_person() {
|
|
|
|
let expected_user = User_ {
|
|
|
|
id: 52,
|
|
|
|
name: "thom".into(),
|
2019-04-03 06:49:32 +00:00
|
|
|
fedi_name: "rrf".into(),
|
2019-03-05 03:52:09 +00:00
|
|
|
preferred_username: None,
|
|
|
|
password_encrypted: "here".into(),
|
|
|
|
email: None,
|
|
|
|
icon: None,
|
|
|
|
published: naive_now(),
|
2019-04-16 23:04:23 +00:00
|
|
|
admin: false,
|
|
|
|
banned: false,
|
2019-08-14 03:15:52 +00:00
|
|
|
updated: None,
|
|
|
|
show_nsfw: false,
|
2019-03-05 03:52:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let person = expected_user.person();
|
2019-05-02 16:55:29 +00:00
|
|
|
assert_eq!("rrr/api/v1/user/thom", person.object_props.id_string().unwrap());
|
2019-03-06 01:00:01 +00:00
|
|
|
let json = serde_json::to_string_pretty(&person).unwrap();
|
|
|
|
println!("{}", json);
|
2019-03-05 03:52:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|