Skip to content

Commit

Permalink
Support listing type for person (fixes #4146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Mar 1, 2024
1 parent 328a48c commit bb0a39c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/apub/src/api/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub async fn search(
users = PersonQuery {
sort,
search_term: (Some(q)),
listing_type: (listing_type),
page: (page),
limit: (limit),
}
Expand Down Expand Up @@ -174,6 +175,7 @@ pub async fn search(
PersonQuery {
sort,
search_term: (Some(q)),
listing_type: (listing_type),
page: (page),
limit: (limit),
}
Expand Down
11 changes: 11 additions & 0 deletions crates/db_views_actor/src/person_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use lemmy_db_schema::{
Queries,
ReadFn,
},
ListingType,
SortType,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -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::<PersonView>(&mut conn).await
Expand All @@ -141,6 +151,7 @@ impl PersonView {
pub struct PersonQuery {
pub sort: Option<SortType>,
pub search_term: Option<String>,
pub listing_type: Option<ListingType>,
pub page: Option<i64>,
pub limit: Option<i64>,
}
Expand Down

0 comments on commit bb0a39c

Please sign in to comment.