fix: replies collection shows all replies

still keep paginated view, to get embedded objects rather than ids
This commit is contained in:
əlemi 2024-06-08 05:06:33 +02:00
parent ca83b17681
commit 453fb2a031
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,5 +1,6 @@
use apb::{BaseMut, CollectionMut, LD};
use axum::extract::{Path, Query, State}; 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 upub::{model, Context};
use crate::{activitypub::{Pagination, TryFetch}, builders::JsonLD, AuthIdentity}; use crate::{activitypub::{Pagination, TryFetch}, builders::JsonLD, AuthIdentity};
@ -10,20 +11,28 @@ pub async fn get(
AuthIdentity(auth): AuthIdentity, AuthIdentity(auth): AuthIdentity,
Query(_q): Query<TryFetch>, Query(_q): Query<TryFetch>,
) -> crate::ApiResult<JsonLD<serde_json::Value>> { ) -> crate::ApiResult<JsonLD<serde_json::Value>> {
let replies_id = upub::url!(ctx, "/objects/{id}/replies");
let oid = ctx.oid(&id);
// if auth.is_local() && q.fetch { // if auth.is_local() && q.fetch {
// ctx.fetch_thread(&oid).await?; // 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(auth.filter_objects())
.filter(model::object::Column::InReplyTo.eq(oid)) .select_only()
.count(ctx.db()) .select_column(model::object::Column::Id)
.into_tuple::<String>()
.all(ctx.db())
.await?; .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( pub async fn page(