mirror of https://github.com/LemmyNet/lemmy.git
Add listing type to list communities (#1380)
* Adding listing type to ListCommunities. Fixes #1379 * Upgrading lemmy-js-client.pull/1387/head
parent
ea59cf16e8
commit
cf911c023d
|
@ -16,7 +16,7 @@
|
||||||
"eslint": "^7.18.0",
|
"eslint": "^7.18.0",
|
||||||
"eslint-plugin-jane": "^9.0.3",
|
"eslint-plugin-jane": "^9.0.3",
|
||||||
"jest": "^26.6.3",
|
"jest": "^26.6.3",
|
||||||
"lemmy-js-client": "0.9.0-rc.12",
|
"lemmy-js-client": "0.9.1-rc.1",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
"prettier": "^2.1.2",
|
"prettier": "^2.1.2",
|
||||||
"ts-jest": "^26.4.4",
|
"ts-jest": "^26.4.4",
|
||||||
|
|
|
@ -3233,10 +3233,10 @@ language-tags@^1.0.5:
|
||||||
dependencies:
|
dependencies:
|
||||||
language-subtag-registry "~0.3.2"
|
language-subtag-registry "~0.3.2"
|
||||||
|
|
||||||
lemmy-js-client@0.9.0-rc.12:
|
lemmy-js-client@0.9.1-rc.1:
|
||||||
version "0.9.0-rc.12"
|
version "0.9.1-rc.1"
|
||||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.0-rc.12.tgz#991d31c4ef89b9bd4088a17c60b6cbaac997df41"
|
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.9.1-rc.1.tgz#afe3cb0d4852f849dd087a4756a3771bc920a907"
|
||||||
integrity sha512-SeCw9wjU89Zm4YWhr+neHC2XvqoqzJg2e42sFEgcDmnQxpPt2sND9Udu+tjGXatbz0tCu6ybGmpR5M0QT4xx9Q==
|
integrity sha512-aVvo4IeJvIPUvypipk4GnyLB6nVQVLfB0arYrMkVV4L7zrZ/0pGtpkMDLaOAj/KpA6O0u9eLmaou5RberZQolA==
|
||||||
|
|
||||||
leven@^3.1.0:
|
leven@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
|
|
|
@ -21,6 +21,7 @@ use lemmy_db_queries::{
|
||||||
Crud,
|
Crud,
|
||||||
Followable,
|
Followable,
|
||||||
Joinable,
|
Joinable,
|
||||||
|
ListingType,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
@ -447,12 +448,14 @@ impl Perform for ListCommunities {
|
||||||
None => false,
|
None => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let type_ = ListingType::from_str(&data.type_)?;
|
||||||
let sort = SortType::from_str(&data.sort)?;
|
let sort = SortType::from_str(&data.sort)?;
|
||||||
|
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let communities = blocking(context.pool(), move |conn| {
|
let communities = blocking(context.pool(), move |conn| {
|
||||||
CommunityQueryBuilder::create(conn)
|
CommunityQueryBuilder::create(conn)
|
||||||
|
.listing_type(&type_)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.show_nsfw(show_nsfw)
|
.show_nsfw(show_nsfw)
|
||||||
.my_user_id(user_id)
|
.my_user_id(user_id)
|
||||||
|
|
|
@ -5,6 +5,7 @@ use lemmy_db_queries::{
|
||||||
functions::hot_rank,
|
functions::hot_rank,
|
||||||
fuzzy_search,
|
fuzzy_search,
|
||||||
limit_and_offset,
|
limit_and_offset,
|
||||||
|
ListingType,
|
||||||
MaybeOptional,
|
MaybeOptional,
|
||||||
SortType,
|
SortType,
|
||||||
ToSafe,
|
ToSafe,
|
||||||
|
@ -97,6 +98,7 @@ impl CommunityView {
|
||||||
|
|
||||||
pub struct CommunityQueryBuilder<'a> {
|
pub struct CommunityQueryBuilder<'a> {
|
||||||
conn: &'a PgConnection,
|
conn: &'a PgConnection,
|
||||||
|
listing_type: &'a ListingType,
|
||||||
sort: &'a SortType,
|
sort: &'a SortType,
|
||||||
my_user_id: Option<i32>,
|
my_user_id: Option<i32>,
|
||||||
show_nsfw: bool,
|
show_nsfw: bool,
|
||||||
|
@ -110,6 +112,7 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
CommunityQueryBuilder {
|
CommunityQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
my_user_id: None,
|
my_user_id: None,
|
||||||
|
listing_type: &ListingType::All,
|
||||||
sort: &SortType::Hot,
|
sort: &SortType::Hot,
|
||||||
show_nsfw: true,
|
show_nsfw: true,
|
||||||
search_term: None,
|
search_term: None,
|
||||||
|
@ -118,6 +121,11 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn listing_type(mut self, listing_type: &'a ListingType) -> Self {
|
||||||
|
self.listing_type = listing_type;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn sort(mut self, sort: &'a SortType) -> Self {
|
pub fn sort(mut self, sort: &'a SortType) -> Self {
|
||||||
self.sort = sort;
|
self.sort = sort;
|
||||||
self
|
self
|
||||||
|
@ -201,6 +209,12 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
query = query.filter(community::nsfw.eq(false));
|
query = query.filter(community::nsfw.eq(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
query = match self.listing_type {
|
||||||
|
ListingType::Subscribed => query.filter(community_follower::user_id.is_not_null()), // TODO could be this: and(community_follower::user_id.eq(user_id_join)),
|
||||||
|
ListingType::Local => query.filter(community::local.eq(true)),
|
||||||
|
_ => query,
|
||||||
|
};
|
||||||
|
|
||||||
let (limit, offset) = limit_and_offset(self.page, self.limit);
|
let (limit, offset) = limit_and_offset(self.page, self.limit);
|
||||||
let res = query
|
let res = query
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
|
@ -39,6 +39,7 @@ pub struct CommunityResponse {
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
pub struct ListCommunities {
|
pub struct ListCommunities {
|
||||||
|
pub type_: String,
|
||||||
pub sort: String,
|
pub sort: String,
|
||||||
pub page: Option<i64>,
|
pub page: Option<i64>,
|
||||||
pub limit: Option<i64>,
|
pub limit: Option<i64>,
|
||||||
|
|
Loading…
Reference in New Issue