From 8f4dd8a57b621d2d0b5874d0746522b82bfecafe Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Mon, 14 Feb 2022 02:38:22 +0900 Subject: [PATCH] Implement User::fetch_outbox07() --- plume-models/src/users.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 04241cd4..616b1beb 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -614,6 +614,42 @@ impl User { } } + pub fn fetch_outbox07(&self) -> Result> { + let mut res = get( + &self.outbox_url[..], + Self::get_sender(), + CONFIG.proxy().cloned(), + )?; + let text = &res.text()?; + let json: serde_json::Value = serde_json::from_str(text)?; + if let Some(first) = json.get("first") { + let mut items: Vec = Vec::new(); + let mut next = first.as_str().unwrap().to_owned(); + while let Ok((mut page, nxt)) = self.fetch_outbox_page07(&next) { + if page.is_empty() { + break; + } + items.append(&mut page); + if let Some(n) = nxt { + if n == next { + break; + } + next = n; + } else { + break; + } + } + Ok(items) + } else { + Ok(json["items"] + .as_array() + .unwrap_or(&vec![]) + .iter() + .filter_map(|j| serde_json::from_value(j.clone()).ok()) + .collect::>()) + } + } + pub fn fetch_followers_ids(&self) -> Result> { let mut res = get( &self.followers_endpoint[..],