Implement User::fetch_outbox_page07()

This commit is contained in:
Kitaiti Makoto 2022-02-14 02:38:13 +09:00
parent 6323c7aef8
commit 78b0535063

View file

@ -20,6 +20,7 @@ use activitystreams::{
OrderedCollection as OrderedCollection07, OrderedCollectionPage as OrderedCollectionPage07,
},
iri_string::types::IriString,
markers::Activity as Activity07,
object::{AsObject as _, Image as Image07, Tombstone as Tombstone07},
prelude::*,
};
@ -560,6 +561,23 @@ impl User {
let next = json.get("next").map(|x| x.as_str().unwrap().to_owned());
Ok((items, next))
}
pub fn fetch_outbox_page07<T: Activity07 + serde::de::DeserializeOwned>(
&self,
url: &str,
) -> Result<(Vec<T>, Option<String>)> {
let mut res = get(url, Self::get_sender(), CONFIG.proxy().cloned())?;
let text = &res.text()?;
let json: serde_json::Value = serde_json::from_str(text)?;
let items = json["items"]
.as_array()
.unwrap_or(&vec![])
.iter()
.filter_map(|j| serde_json::from_value(j.clone()).ok())
.collect::<Vec<T>>();
let next = json.get("next").map(|x| x.as_str().unwrap().to_owned());
Ok((items, next))
}
pub fn fetch_outbox<T: Activity>(&self) -> Result<Vec<T>> {
let mut res = get(
&self.outbox_url[..],