Try to fetch remote articles

This commit is contained in:
Bat
2018-07-26 22:23:53 +02:00
parent 5583029b07
commit bd259891f3
3 changed files with 47 additions and 6 deletions
+23 -1
View File
@@ -1,5 +1,5 @@
use activitypub::{
Actor, Object, Endpoint, CustomObject,
Activity, Actor, Object, Endpoint, CustomObject,
actor::Person,
collection::OrderedCollection
};
@@ -251,6 +251,28 @@ impl User {
ActivityStream::new(coll)
}
pub fn fetch_outbox<T: Activity>(&self) -> Vec<T> {
let req = Client::new()
.get(&self.outbox_url[..])
.header(Accept(ap_accept_header().into_iter().map(|h| qitem(h.parse::<Mime>().expect("Invalid Content-Type"))).collect()))
.send();
match req {
Ok(mut res) => {
let text = &res.text().unwrap();
let json: serde_json::Value = serde_json::from_str(text).unwrap();
json["items"].as_array()
.expect("Outbox.items is not an array")
.into_iter()
.filter_map(|j| serde_json::from_value(j.clone()).ok())
.collect::<Vec<T>>()
},
Err(e) => {
println!("User outbox fetch error: {:?}", e);
vec![]
}
}
}
fn get_activities(&self, conn: &PgConnection) -> Vec<serde_json::Value> {
use schema::posts;
use schema::post_authors;