2024-04-19 03:32:21 +02:00
|
|
|
use axum::extract::{Path, Query, State};
|
2024-04-24 02:31:35 +02:00
|
|
|
use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter};
|
2024-04-19 03:32:21 +02:00
|
|
|
|
2024-05-03 04:43:25 +02:00
|
|
|
use crate::{model, routes::activitypub::{JsonLD, Pagination, TryFetch}, server::{auth::AuthIdentity, fetcher::Fetcher, Context}, url};
|
2024-04-19 03:32:21 +02:00
|
|
|
|
|
|
|
pub async fn get(
|
|
|
|
State(ctx): State<Context>,
|
|
|
|
Path(id): Path<String>,
|
|
|
|
AuthIdentity(auth): AuthIdentity,
|
2024-05-03 04:43:25 +02:00
|
|
|
Query(q): Query<TryFetch>,
|
2024-04-19 03:32:21 +02:00
|
|
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
2024-04-30 01:48:30 +02:00
|
|
|
let replies_id = url!(ctx, "/objects/{id}/replies");
|
2024-05-20 06:25:47 +02:00
|
|
|
let oid = ctx.oid(&id);
|
2024-04-19 03:32:21 +02:00
|
|
|
|
2024-05-03 04:43:25 +02:00
|
|
|
if auth.is_local() && q.fetch {
|
|
|
|
ctx.fetch_thread(&oid).await?;
|
|
|
|
}
|
|
|
|
|
2024-04-30 01:50:25 +02:00
|
|
|
let count = model::addressing::Entity::find_addressed(auth.my_id())
|
2024-04-19 03:32:21 +02:00
|
|
|
.filter(auth.filter_condition())
|
|
|
|
.filter(model::object::Column::InReplyTo.eq(oid))
|
|
|
|
.count(ctx.db())
|
|
|
|
.await?;
|
|
|
|
|
2024-04-30 01:48:30 +02:00
|
|
|
crate::server::builders::collection(&replies_id, Some(count))
|
2024-04-19 03:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn page(
|
|
|
|
State(ctx): State<Context>,
|
|
|
|
Path(id): Path<String>,
|
|
|
|
Query(page): Query<Pagination>,
|
|
|
|
AuthIdentity(auth): AuthIdentity,
|
|
|
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
2024-04-30 01:48:30 +02:00
|
|
|
let page_id = url!(ctx, "/objects/{id}/replies/page");
|
2024-05-20 06:25:47 +02:00
|
|
|
let oid = ctx.oid(&id);
|
2024-04-19 03:32:21 +02:00
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
crate::server::builders::paginate(
|
2024-04-30 01:48:30 +02:00
|
|
|
page_id,
|
2024-04-24 02:31:35 +02:00
|
|
|
Condition::all()
|
|
|
|
.add(auth.filter_condition())
|
|
|
|
.add(model::object::Column::InReplyTo.eq(oid)),
|
|
|
|
ctx.db(),
|
2024-04-30 01:50:25 +02:00
|
|
|
page,
|
|
|
|
auth.my_id(),
|
2024-05-29 04:56:10 +02:00
|
|
|
false,
|
2024-04-24 02:31:35 +02:00
|
|
|
)
|
|
|
|
.await
|
2024-04-19 03:32:21 +02:00
|
|
|
}
|