fix: pagination

how was this not broken before??? pleroma works in mysterious ways
This commit is contained in:
əlemi 2024-03-07 18:56:21 +01:00
parent 5f1fbe8422
commit 6ff112f6b6

View file

@ -83,6 +83,7 @@ impl FediClient {
async fn get_related_users(&self, user_id: &str, relation: &str) -> reqwest::Result<Vec<model::FediUser>> { async fn get_related_users(&self, user_id: &str, relation: &str) -> reqwest::Result<Vec<model::FediUser>> {
let mut out = Vec::new(); let mut out = Vec::new();
let mut max_id = String::new();
let limit = 40; // TODO make it customizable? idk let limit = 40; // TODO make it customizable? idk
loop { loop {
let mut page : Vec<model::FediUser> = self.http let mut page : Vec<model::FediUser> = self.http
@ -90,12 +91,16 @@ impl FediClient {
.headers(self.headers()) .headers(self.headers())
.query(&[("limit", limit)]) .query(&[("limit", limit)])
.query(&[("with_relationships", true)]) .query(&[("with_relationships", true)])
.query(&[("max_id", &max_id)])
.send() .send()
.await? .await?
.error_for_status()? .error_for_status()?
.json() .json()
.await?; .await?;
let count = page.len(); let count = page.len();
if let Some(u) = page.last() {
max_id = u.id.clone();
}
out.append(&mut page); // TODO can i just concat these vecs at the end? out.append(&mut page); // TODO can i just concat these vecs at the end?
if count != limit { break } // end of pages if count != limit { break } // end of pages
} }