Better use of the activitypub crate in User::into_activity

This commit is contained in:
Bat 2018-06-21 16:14:26 +01:00
parent 5457a80eec
commit 2621c0304e

View File

@ -1,8 +1,7 @@
use activitypub::{ use activitypub::{
Actor, Object, Actor, Object, Endpoint,
actor::{Person, properties::ApActorProperties}, actor::Person,
collection::OrderedCollection, collection::OrderedCollection
object::properties::ObjectProperties
}; };
use bcrypt; use bcrypt;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
@ -306,27 +305,19 @@ impl User {
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap() PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
} }
pub fn into_activity(&self, conn: &PgConnection) -> Person { pub fn into_activity(&self, _conn: &PgConnection) -> Person {
let mut actor = Person::default(); let mut actor = Person::default();
actor.object_props = ObjectProperties { actor.object_props.set_id_string(self.ap_url.clone()).expect("User::into_activity: id error");
id: Some(serde_json::to_value(self.ap_url.clone()).unwrap()), actor.object_props.set_name_string(self.get_display_name()).expect("User::into_activity: name error");
name: Some(serde_json::to_value(self.get_display_name()).unwrap()), actor.object_props.set_summary_string(self.get_summary()).expect("User::into_activity: summary error");
summary: Some(serde_json::to_value(self.get_summary()).unwrap()), actor.object_props.set_url_string(self.ap_url.clone()).expect("User::into_activity: url error");
url: Some(serde_json::to_value(self.ap_url.clone()).unwrap()), actor.ap_actor_props.set_inbox_string(self.inbox_url.clone()).expect("User::into_activity: inbox error");
..ObjectProperties::default() actor.ap_actor_props.set_outbox_string(self.outbox_url.clone()).expect("User::into_activity: outbox error");
}; actor.ap_actor_props.set_preferred_username_string(self.get_actor_id()).expect("User::into_activity: preferredUsername error");
actor.ap_actor_props = ApActorProperties {
inbox: serde_json::to_value(self.compute_inbox(conn)).unwrap(), let mut endpoints = Endpoint::default();
outbox: serde_json::to_value(self.compute_outbox(conn)).unwrap(), endpoints.set_shared_inbox_string(ap_url(format!("{}/inbox/", BASE_URL.as_str()))).expect("User::into_activity: endpoints.sharedInbox error");
preferred_username: Some(serde_json::to_value(self.get_actor_id()).unwrap()), actor.ap_actor_props.set_endpoints_endpoint(endpoints).expect("User::into_activity: endpoints error");
endpoints: Some(json!({
"sharedInbox": ap_url(format!("{}/inbox", BASE_URL.as_str()))
})),
followers: None,
following: None,
liked: None,
streams: None
};
actor actor
} }