diff --git a/upub/routes/src/activitypub/object/replies.rs b/upub/routes/src/activitypub/object/replies.rs index 6740e9b4..d306c4bf 100644 --- a/upub/routes/src/activitypub/object/replies.rs +++ b/upub/routes/src/activitypub/object/replies.rs @@ -1,5 +1,6 @@ +use apb::{BaseMut, CollectionMut, LD}; use axum::extract::{Path, Query, State}; -use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter}; +use sea_orm::{ColumnTrait, Condition, QueryFilter, QuerySelect, SelectColumns}; use upub::{model, Context}; use crate::{activitypub::{Pagination, TryFetch}, builders::JsonLD, AuthIdentity}; @@ -10,20 +11,28 @@ pub async fn get( AuthIdentity(auth): AuthIdentity, Query(_q): Query, ) -> crate::ApiResult> { - let replies_id = upub::url!(ctx, "/objects/{id}/replies"); - let oid = ctx.oid(&id); - // if auth.is_local() && q.fetch { // ctx.fetch_thread(&oid).await?; // } - let count = upub::Query::objects(auth.my_id()) + let replies_ids = upub::Query::objects(auth.my_id()) + .filter(model::object::Column::InReplyTo.eq(ctx.oid(&id))) .filter(auth.filter_objects()) - .filter(model::object::Column::InReplyTo.eq(oid)) - .count(ctx.db()) + .select_only() + .select_column(model::object::Column::Id) + .into_tuple::() + .all(ctx.db()) .await?; - crate::builders::collection(&replies_id, Some(count)) + Ok(JsonLD( + apb::new() + .set_id(Some(&upub::url!(ctx, "/objects/{id}/replies"))) + .set_collection_type(Some(apb::CollectionType::Collection)) + .set_first(apb::Node::link(upub::url!(ctx, "/objects/{id}/replies/page"))) + .set_total_items(Some(replies_ids.len() as u64)) + .set_items(apb::Node::links(replies_ids)) + .ld_context() + )) } pub async fn page(