fix: include replies choice in next page urls

This commit is contained in:
əlemi 2024-11-09 13:18:19 +01:00
parent baaaa55e9d
commit aaed94d2f8
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -21,7 +21,9 @@ pub async fn paginate_feed(
.add(filter);
// by default we want replies because servers don't know about our api and want everything
if !page.replies.unwrap_or(true) {
let replies = page.replies.unwrap_or(true);
if !replies {
conditions = conditions.add(upub::model::object::Column::InReplyTo.is_null());
}
@ -52,18 +54,19 @@ pub async fn paginate_feed(
.map(|item| item.ap())
.collect();
collection_page(&id, offset, limit, items)
collection_page(&id, offset, limit, items, replies)
}
pub fn collection_page(id: &str, offset: u64, limit: u64, items: Vec<serde_json::Value>) -> crate::ApiResult<JsonLD<serde_json::Value>> {
pub fn collection_page(id: &str, offset: u64, limit: u64, items: Vec<serde_json::Value>, replies: bool) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let replies = if replies { "" } else { "&replies=false" };
let next = if items.len() < limit as usize {
apb::Node::Empty
} else {
apb::Node::link(format!("{id}?offset={}", offset+limit))
apb::Node::link(format!("{id}?offset={}{replies}", offset+limit))
};
Ok(JsonLD(
apb::new()
.set_id(Some(&format!("{id}?offset={offset}")))
.set_id(Some(&format!("{id}?offset={offset}{replies}")))
.set_collection_type(Some(apb::CollectionType::OrderedCollectionPage))
.set_part_of(apb::Node::link(id.replace("/page", "")))
.set_ordered_items(apb::Node::array(items))