From cc090ccb193e0e23030c4d06b5bc9484b4a88f70 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 26 Dec 2024 16:13:23 +0100 Subject: [PATCH] chore: refactor and deprecate pagination builder --- upub/routes/src/activitypub/actor/following.rs | 2 +- upub/routes/src/activitypub/actor/notifications.rs | 2 +- upub/routes/src/activitypub/object/context.rs | 2 +- upub/routes/src/activitypub/tags.rs | 2 +- upub/routes/src/builders.rs | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/upub/routes/src/activitypub/actor/following.rs b/upub/routes/src/activitypub/actor/following.rs index 8de5ab9..707bb70 100644 --- a/upub/routes/src/activitypub/actor/following.rs +++ b/upub/routes/src/activitypub/actor/following.rs @@ -118,6 +118,6 @@ pub async fn page( crate::builders::collection_page( &upub::url!(ctx, "/actors/{id}/{follow___}/page"), offset, limit, - following.into_iter().map(serde_json::Value::String).collect(), + apb::Node::links(following), ) } diff --git a/upub/routes/src/activitypub/actor/notifications.rs b/upub/routes/src/activitypub/actor/notifications.rs index f541d6a..30ac8c0 100644 --- a/upub/routes/src/activitypub/actor/notifications.rs +++ b/upub/routes/src/activitypub/actor/notifications.rs @@ -51,6 +51,6 @@ pub async fn page( .map(|x| ctx.ap(x)) .collect(); - crate::builders::collection_page(&upub::url!(ctx, "/actors/{id}/notifications/page"), offset, limit, activities) + crate::builders::collection_page(&upub::url!(ctx, "/actors/{id}/notifications/page"), offset, limit, apb::Node::array(activities)) } diff --git a/upub/routes/src/activitypub/object/context.rs b/upub/routes/src/activitypub/object/context.rs index a0dea51..8e15367 100644 --- a/upub/routes/src/activitypub/object/context.rs +++ b/upub/routes/src/activitypub/object/context.rs @@ -51,5 +51,5 @@ pub async fn page( .map(|item| ctx.ap(item)) .collect(); - crate::builders::collection_page(&upub::url!(ctx, "/objects/{id}/context/page"), offset, limit, items) + crate::builders::collection_page(&upub::url!(ctx, "/objects/{id}/context/page"), offset, limit, apb::Node::array(items)) } diff --git a/upub/routes/src/activitypub/tags.rs b/upub/routes/src/activitypub/tags.rs index dfbb6c2..ff6082b 100644 --- a/upub/routes/src/activitypub/tags.rs +++ b/upub/routes/src/activitypub/tags.rs @@ -45,7 +45,7 @@ pub async fn page( &upub::url!(ctx, "/tags/{id}/page"), offset, limit, - objects, + apb::Node::array(objects), ) } diff --git a/upub/routes/src/builders.rs b/upub/routes/src/builders.rs index ae084a7..6892b5c 100644 --- a/upub/routes/src/builders.rs +++ b/upub/routes/src/builders.rs @@ -5,7 +5,7 @@ use upub::selector::{BatchFillable, RichActivity}; use crate::activitypub::Pagination; -//#[deprecated = "use upub::Query directly"] +#[deprecated = "use upub::Query directly"] pub async fn paginate_feed( id: String, filter: Condition, @@ -52,10 +52,10 @@ pub async fn paginate_feed( .map(|item| ctx.ap(item)) .collect(); - collection_page(&id, offset, limit, items) + collection_page(&id, offset, limit, apb::Node::array(items)) } -pub fn collection_page(id: &str, offset: u64, limit: u64, items: Vec) -> crate::ApiResult> { +pub fn collection_page(id: &str, offset: u64, limit: u64, items: apb::Node) -> crate::ApiResult> { let next = if items.len() < limit as usize { apb::Node::Empty } else { @@ -66,7 +66,7 @@ pub fn collection_page(id: &str, offset: u64, limit: u64, items: Vec