From bb0a39c02e37c9e1f85ae4e548a4d929993d4c6f Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 1 Mar 2024 14:57:54 +0100 Subject: [PATCH] Support listing type for person (fixes #4146) --- crates/apub/src/api/search.rs | 2 ++ crates/db_views_actor/src/person_view.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/crates/apub/src/api/search.rs b/crates/apub/src/api/search.rs index dff2dffeb..32128a3c1 100644 --- a/crates/apub/src/api/search.rs +++ b/crates/apub/src/api/search.rs @@ -104,6 +104,7 @@ pub async fn search( users = PersonQuery { sort, search_term: (Some(q)), + listing_type: (listing_type), page: (page), limit: (limit), } @@ -174,6 +175,7 @@ pub async fn search( PersonQuery { sort, search_term: (Some(q)), + listing_type: (listing_type), page: (page), limit: (limit), } diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index 08ad2880f..24b6d691f 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -23,6 +23,7 @@ use lemmy_db_schema::{ Queries, ReadFn, }, + ListingType, SortType, }; use serde::{Deserialize, Serialize}; @@ -115,6 +116,15 @@ fn queries<'a>( let (limit, offset) = limit_and_offset(options.page, options.limit)?; query = query.limit(limit).offset(offset); + + if let Some(listing_type) = options.listing_type { + query = match listing_type { + // return nothing as its not possible to follow users + ListingType::Subscribed => query.limit(0), + ListingType::Local => query.filter(person::local.eq(true)), + _ => query, + }; + } } } query.load::(&mut conn).await @@ -141,6 +151,7 @@ impl PersonView { pub struct PersonQuery { pub sort: Option, pub search_term: Option, + pub listing_type: Option, pub page: Option, pub limit: Option, }