feat: outbox with embedded objects

This commit is contained in:
əlemi 2024-03-21 01:11:08 +01:00
parent 32dbd9e9ce
commit 4f4cd5bf9b
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,9 +1,10 @@
use std::sync::Arc; use std::sync::Arc;
use crate::activitystream::prelude::*;
use axum::{extract::{Path, Query, State}, http::StatusCode, Json}; use axum::{extract::{Path, Query, State}, http::StatusCode, Json};
use sea_orm::{ColumnTrait, Condition, DatabaseConnection, EntityTrait, IntoActiveModel, Order, QueryFilter, QueryOrder, QuerySelect}; use sea_orm::{ColumnTrait, Condition, DatabaseConnection, EntityTrait, IntoActiveModel, Order, QueryFilter, QueryOrder, QuerySelect};
use crate::{activitystream::{self, object::{activity::{Activity, ActivityType}, collection::{page::CollectionPageMut, CollectionMut, CollectionType}, ObjectType}, Base, BaseMut, BaseType, Node}, model::{self, activity, object, user}, server::Context, url}; use crate::{activitystream::{self, object::{activity::ActivityType, collection::CollectionType, ObjectType}, BaseType, Node}, model::{self, activity, object, user}, server::Context, url};
pub async fn list(State(_db) : State<Arc<DatabaseConnection>>) -> Result<Json<serde_json::Value>, StatusCode> { pub async fn list(State(_db) : State<Arc<DatabaseConnection>>) -> Result<Json<serde_json::Value>, StatusCode> {
todo!() todo!()
@ -43,16 +44,17 @@ pub async fn outbox(
match activity::Entity::find() match activity::Entity::find()
.filter(Condition::all().add(activity::Column::Published.lt(before))) .filter(Condition::all().add(activity::Column::Published.lt(before)))
.find_also_related(user::Entity)
.order_by(activity::Column::Published, Order::Desc) .order_by(activity::Column::Published, Order::Desc)
.limit(20) // TODO allow customizing, with boundaries .limit(20) // TODO allow customizing, with boundaries
.all(ctx.db()).await .all(ctx.db()).await
{ {
Err(_e) => Err(StatusCode::INTERNAL_SERVER_ERROR), Err(_e) => Err(StatusCode::INTERNAL_SERVER_ERROR),
Ok(items) => { Ok(items) => {
let next = ctx.id(items.last().map(|x| x.id.as_str()).unwrap_or("").to_string()); let next = ctx.id(items.last().map(|(a, _o)| a.id.as_str()).unwrap_or("").to_string());
let items = items let items = items
.into_iter() .into_iter()
.map(|i| i.underlying_json_object()) .map(|(a, o)| a.underlying_json_object().set_object(Node::maybe_object(o)))
.collect(); .collect();
Ok(Json( Ok(Json(
activitystream::object() activitystream::object()