diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 34b628fe..ce90bee5 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -15,6 +15,7 @@ use activitystreams::{ activity::Delete as Delete07, actor::AsApActor, actor::{ApActor as ApActor07, Endpoints as Endpoints07, Person as Person07}, + base::AnyBase, collection::{ OrderedCollection as OrderedCollection07, OrderedCollectionPage as OrderedCollectionPage07, }, @@ -518,6 +519,33 @@ impl User { .set_part_of_link(Id::new(&self.outbox_url))?; Ok(coll) } + pub fn outbox_collection_page07( + &self, + conn: &Connection, + (min, max): (i32, i32), + ) -> Result { + let acts = self.get_activities_page(conn, (min, max))?; + let n_acts = self.get_activities_count(conn); + let mut coll = OrderedCollectionPage07::new(); + if n_acts - i64::from(min) >= i64::from(ITEMS_PER_PAGE) { + coll.set_next( + format!("{}?page={}", &self.outbox_url, min / ITEMS_PER_PAGE + 2) + .parse::()?, + ); + } + if min > 0 { + coll.set_prev( + format!("{}?page={}", &self.outbox_url, min / ITEMS_PER_PAGE) + .parse::()?, + ); + } + coll.set_many_items( + acts.iter() + .filter_map(|value| AnyBase::from_arbitrary_json(value).ok()), + ); + coll.set_part_of(self.outbox_url.parse::()?); + Ok(coll) + } fn fetch_outbox_page(&self, url: &str) -> Result<(Vec, Option)> { let mut res = get(url, Self::get_sender(), CONFIG.proxy().cloned())?; let text = &res.text()?;