From 8a3211d07b4322366d7f2844ef32be1bcfd77bbe Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 9 Nov 2024 13:13:14 +0100 Subject: [PATCH] feat: allow to filter out replies from feeds --- upub/core/src/model/object.rs | 2 +- upub/routes/src/activitypub/application.rs | 4 +++- upub/routes/src/activitypub/mod.rs | 1 + upub/routes/src/activitypub/object/replies.rs | 5 ++++- upub/routes/src/builders.rs | 12 ++++++++++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/upub/core/src/model/object.rs b/upub/core/src/model/object.rs index e764d2e..bf5e045 100644 --- a/upub/core/src/model/object.rs +++ b/upub/core/src/model/object.rs @@ -1,4 +1,4 @@ -use apb::{BaseMut, CollectionMut, DocumentMut, Object, ObjectMut, ObjectType}; +use apb::{BaseMut, CollectionMut, DocumentMut, ObjectMut, ObjectType}; use sea_orm::{entity::prelude::*, QuerySelect, SelectColumns}; use crate::ext::JsonVec; diff --git a/upub/routes/src/activitypub/application.rs b/upub/routes/src/activitypub/application.rs index 175b2c5..9d5eb99 100644 --- a/upub/routes/src/activitypub/application.rs +++ b/upub/routes/src/activitypub/application.rs @@ -4,7 +4,7 @@ use reqwest::Method; use sea_orm::{Condition, ColumnTrait}; use upub::{traits::{Cloaker, Fetcher}, Context}; -use crate::{builders::JsonLD, ApiError, AuthIdentity, Identity}; +use crate::{builders::JsonLD, ApiError, AuthIdentity}; use super::{PaginatedSearch, Pagination}; @@ -56,9 +56,11 @@ pub async fn search( .add(upub::model::object::Column::Content.like(format!("%{}%", page.q))); // TODO lmao rethink this all + // still haven't redone this gg me let page = Pagination { offset: page.offset, batch: page.batch, + replies: Some(true), }; crate::builders::paginate_feed( diff --git a/upub/routes/src/activitypub/mod.rs b/upub/routes/src/activitypub/mod.rs index ee2cfc2..1aba26e 100644 --- a/upub/routes/src/activitypub/mod.rs +++ b/upub/routes/src/activitypub/mod.rs @@ -90,6 +90,7 @@ pub struct TryFetch { pub struct Pagination { pub offset: Option, pub batch: Option, + pub replies: Option, } #[derive(Debug, serde::Deserialize)] diff --git a/upub/routes/src/activitypub/object/replies.rs b/upub/routes/src/activitypub/object/replies.rs index cc5cb44..7a415ed 100644 --- a/upub/routes/src/activitypub/object/replies.rs +++ b/upub/routes/src/activitypub/object/replies.rs @@ -38,12 +38,15 @@ pub async fn get( pub async fn page( State(ctx): State, Path(id): Path, - Query(page): Query, + Query(mut page): Query, AuthIdentity(auth): AuthIdentity, ) -> crate::ApiResult> { let page_id = upub::url!(ctx, "/objects/{id}/replies/page"); let oid = ctx.oid(&id); + // TODO kinda weird ignoring this but its weirder to exclude replies from replies view... + page.replies = Some(true); + crate::builders::paginate_feed( page_id, Condition::all() diff --git a/upub/routes/src/builders.rs b/upub/routes/src/builders.rs index 85ffe90..51be453 100644 --- a/upub/routes/src/builders.rs +++ b/upub/routes/src/builders.rs @@ -1,5 +1,5 @@ use apb::{BaseMut, CollectionMut, CollectionPageMut, LD}; -use sea_orm::{Condition, ConnectionTrait, QueryFilter, QuerySelect, RelationTrait}; +use sea_orm::{Condition, ConnectionTrait, QueryFilter, QuerySelect, RelationTrait, ColumnTrait}; use axum::response::{IntoResponse, Response}; use upub::selector::{BatchFillable, RichActivity}; @@ -17,6 +17,14 @@ pub async fn paginate_feed( let limit = page.batch.unwrap_or(20).min(50); let offset = page.offset.unwrap_or(0); + let mut conditions = Condition::all() + .add(filter); + + // by default we want replies because servers don't know about our api and want everything + if !page.replies.unwrap_or(true) { + conditions = conditions.add(upub::model::object::Column::InReplyTo.is_null()); + } + let mut select = upub::Query::feed(my_id); if with_users { @@ -25,7 +33,7 @@ pub async fn paginate_feed( } let items = select - .filter(filter) + .filter(conditions) // TODO also limit to only local activities .limit(limit) .offset(offset)