From b097e4a725a8f80abadac928fb1c4b318d2ea724 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 29 May 2024 04:56:10 +0200 Subject: [PATCH] feat: outbox shows only local posts hopefully? --- src/routes/activitypub/context.rs | 1 + src/routes/activitypub/inbox.rs | 1 + src/routes/activitypub/object/replies.rs | 1 + src/routes/activitypub/outbox.rs | 6 +++++- src/routes/activitypub/user/inbox.rs | 1 + src/routes/activitypub/user/outbox.rs | 1 + src/server/builders.rs | 12 ++++++++++-- 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/routes/activitypub/context.rs b/src/routes/activitypub/context.rs index 3ffd378..360d21f 100644 --- a/src/routes/activitypub/context.rs +++ b/src/routes/activitypub/context.rs @@ -36,6 +36,7 @@ pub async fn page( ctx.db(), page, auth.my_id(), + false, ) .await } diff --git a/src/routes/activitypub/inbox.rs b/src/routes/activitypub/inbox.rs index 50d3840..adb1eb3 100644 --- a/src/routes/activitypub/inbox.rs +++ b/src/routes/activitypub/inbox.rs @@ -25,6 +25,7 @@ pub async fn page( ctx.db(), page, auth.my_id(), + false, ) .await } diff --git a/src/routes/activitypub/object/replies.rs b/src/routes/activitypub/object/replies.rs index a01ba47..b951495 100644 --- a/src/routes/activitypub/object/replies.rs +++ b/src/routes/activitypub/object/replies.rs @@ -42,6 +42,7 @@ pub async fn page( ctx.db(), page, auth.my_id(), + false, ) .await } diff --git a/src/routes/activitypub/outbox.rs b/src/routes/activitypub/outbox.rs index 1cd7e63..3abd0b3 100644 --- a/src/routes/activitypub/outbox.rs +++ b/src/routes/activitypub/outbox.rs @@ -1,4 +1,5 @@ use axum::{extract::{Query, State}, http::StatusCode, Json}; +use sea_orm::{ColumnTrait, Condition}; use crate::{errors::UpubError, routes::activitypub::{CreationResult, JsonLD, Pagination}, server::{auth::AuthIdentity, Context}, url}; @@ -13,10 +14,13 @@ pub async fn page( ) -> crate::Result> { crate::server::builders::paginate( url!(ctx, "/outbox/page"), - auth.filter_condition(), // TODO filter local only stuff + Condition::all() + .add(auth.filter_condition()) + .add(crate::model::actor::Column::Domain.eq(ctx.domain().to_string())), ctx.db(), page, auth.my_id(), + true, ) .await } diff --git a/src/routes/activitypub/user/inbox.rs b/src/routes/activitypub/user/inbox.rs index 7ccdc5c..0049e8a 100644 --- a/src/routes/activitypub/user/inbox.rs +++ b/src/routes/activitypub/user/inbox.rs @@ -42,6 +42,7 @@ pub async fn page( ctx.db(), page, auth.my_id(), + false, ) .await } diff --git a/src/routes/activitypub/user/outbox.rs b/src/routes/activitypub/user/outbox.rs index 774eb75..b88b1c9 100644 --- a/src/routes/activitypub/user/outbox.rs +++ b/src/routes/activitypub/user/outbox.rs @@ -30,6 +30,7 @@ pub async fn page( ctx.db(), page, auth.my_id(), + false, ) .await } diff --git a/src/server/builders.rs b/src/server/builders.rs index 6ca040c..0f8b641 100644 --- a/src/server/builders.rs +++ b/src/server/builders.rs @@ -1,5 +1,5 @@ use apb::{BaseMut, CollectionMut, CollectionPageMut}; -use sea_orm::{Condition, DatabaseConnection, QueryFilter, QuerySelect}; +use sea_orm::{Condition, DatabaseConnection, QueryFilter, QuerySelect, RelationTrait}; use crate::{model::{addressing::Event, attachment::BatchFillable}, routes::activitypub::{jsonld::LD, JsonLD, Pagination}}; @@ -9,11 +9,19 @@ pub async fn paginate( db: &DatabaseConnection, page: Pagination, my_id: Option, + with_users: bool, // TODO ewww too many arguments for this weird function... ) -> crate::Result> { let limit = page.batch.unwrap_or(20).min(50); let offset = page.offset.unwrap_or(0); - let items = crate::model::addressing::Entity::find_addressed(my_id) + let mut select = crate::model::addressing::Entity::find_addressed(my_id); + + if with_users { + select = select + .join(sea_orm::JoinType::InnerJoin, crate::model::activity::Relation::Actors.def()); + } + + let items = select .filter(filter) // TODO also limit to only local activities .limit(limit)