diff --git a/upub/routes/src/activitypub/actor/following.rs b/upub/routes/src/activitypub/actor/following.rs index 794f330..8de5ab9 100644 --- a/upub/routes/src/activitypub/actor/following.rs +++ b/upub/routes/src/activitypub/actor/following.rs @@ -59,8 +59,7 @@ pub async fn page( use upub::model::relation::Column::{Follower, Following, FollowerInstance, FollowingInstance}; let follow___ = if OUTGOING { "following" } else { "followers" }; - let limit = page.batch.unwrap_or(100).min(500); - let offset = page.offset.unwrap_or(0); + let (limit, offset) = page.pagination(); let (user, config) = model::actor::Entity::find_by_ap_id(&ctx.uid(&id)) .find_also_related(model::config::Entity) diff --git a/upub/routes/src/activitypub/actor/notifications.rs b/upub/routes/src/activitypub/actor/notifications.rs index 4a52c0e..f541d6a 100644 --- a/upub/routes/src/activitypub/actor/notifications.rs +++ b/upub/routes/src/activitypub/actor/notifications.rs @@ -39,8 +39,7 @@ pub async fn page( return Err(crate::ApiError::forbidden()); } - let limit = page.batch.unwrap_or(20).min(50); - let offset = page.offset.unwrap_or(0); + let (limit, offset) = page.pagination(); let activities = upub::Query::notifications(*internal, true) .limit(limit) diff --git a/upub/routes/src/activitypub/mod.rs b/upub/routes/src/activitypub/mod.rs index e649a1a..d50e0c0 100644 --- a/upub/routes/src/activitypub/mod.rs +++ b/upub/routes/src/activitypub/mod.rs @@ -94,6 +94,14 @@ pub struct Pagination { pub replies: Option, } +impl Pagination { + pub fn pagination(&self) -> (u64, u64) { + let limit = self.batch.unwrap_or(20).min(50); + let offset = self.offset.unwrap_or(0); + (limit, offset) + } +} + #[derive(Debug, serde::Deserialize)] // TODO i don't really like how pleroma/mastodon do it actually, maybe change this? pub struct PaginatedSearch { diff --git a/upub/routes/src/activitypub/object/context.rs b/upub/routes/src/activitypub/object/context.rs index de4a875..a0dea51 100644 --- a/upub/routes/src/activitypub/object/context.rs +++ b/upub/routes/src/activitypub/object/context.rs @@ -27,8 +27,7 @@ pub async fn page( AuthIdentity(auth): AuthIdentity, ) -> crate::ApiResult> { let context = ctx.oid(&id); - let limit = page.batch.unwrap_or(50).min(50); - let offset = page.offset.unwrap_or(0); + let (limit, offset) = page.pagination(); let items = upub::Query::objects(auth.my_id()) .filter(auth.filter_objects()) diff --git a/upub/routes/src/activitypub/tags.rs b/upub/routes/src/activitypub/tags.rs index 7974dde..dfbb6c2 100644 --- a/upub/routes/src/activitypub/tags.rs +++ b/upub/routes/src/activitypub/tags.rs @@ -21,8 +21,7 @@ pub async fn page( AuthIdentity(auth): AuthIdentity, Query(page): Query, ) -> crate::ApiResult> { - let limit = page.batch.unwrap_or(20).min(50); - let offset = page.offset.unwrap_or(0); + let (limit, offset) = page.pagination(); let objects = upub::Query::hashtags() .filter(auth.filter_objects()) diff --git a/upub/routes/src/builders.rs b/upub/routes/src/builders.rs index 022f8d0..ae084a7 100644 --- a/upub/routes/src/builders.rs +++ b/upub/routes/src/builders.rs @@ -14,8 +14,7 @@ pub async fn paginate_feed( my_id: Option, with_users: bool, // TODO ewww too many arguments for this weird function... ) -> crate::ApiResult> { - let limit = page.batch.unwrap_or(20).min(50); - let offset = page.offset.unwrap_or(0); + let (limit, offset) = page.pagination(); let mut conditions = Condition::all() .add(filter);