feat: allow to filter out replies from feeds

This commit is contained in:
əlemi 2024-11-09 13:13:14 +01:00
parent f5d794824e
commit 8a3211d07b
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 19 additions and 5 deletions

View file

@ -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;

View file

@ -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(

View file

@ -90,6 +90,7 @@ pub struct TryFetch {
pub struct Pagination {
pub offset: Option<u64>,
pub batch: Option<u64>,
pub replies: Option<bool>,
}
#[derive(Debug, serde::Deserialize)]

View file

@ -38,12 +38,15 @@ pub async fn get(
pub async fn page(
State(ctx): State<Context>,
Path(id): Path<String>,
Query(page): Query<Pagination>,
Query(mut page): Query<Pagination>,
AuthIdentity(auth): AuthIdentity,
) -> crate::ApiResult<JsonLD<serde_json::Value>> {
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()

View file

@ -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)