mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 04:41:19 +00:00
* Remove listing type community. Fixes #2361 * Have ListingType::All be the default
This commit is contained in:
parent
b78826c2c8
commit
3b86e15399
5 changed files with 25 additions and 50 deletions
|
@ -44,7 +44,6 @@ pub enum ListingType {
|
||||||
All,
|
All,
|
||||||
Local,
|
Local,
|
||||||
Subscribed,
|
Subscribed,
|
||||||
Community,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
#[derive(EnumString, Display, Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
use crate::structs::CommentView;
|
use crate::structs::CommentView;
|
||||||
use diesel::{
|
use diesel::{dsl::*, result::Error, *};
|
||||||
dsl::*,
|
|
||||||
result::{Error, Error::QueryBuilderError},
|
|
||||||
*,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
newtypes::{CommentId, CommunityId, DbUrl, PersonId, PostId},
|
newtypes::{CommentId, CommunityId, DbUrl, PersonId, PostId},
|
||||||
|
@ -232,7 +228,7 @@ impl<'a> CommentQueryBuilder<'a> {
|
||||||
pub fn create(conn: &'a PgConnection) -> Self {
|
pub fn create(conn: &'a PgConnection) -> Self {
|
||||||
CommentQueryBuilder {
|
CommentQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
listing_type: None,
|
listing_type: Some(ListingType::All),
|
||||||
sort: None,
|
sort: None,
|
||||||
community_id: None,
|
community_id: None,
|
||||||
community_actor_id: None,
|
community_actor_id: None,
|
||||||
|
@ -445,22 +441,17 @@ impl<'a> CommentQueryBuilder<'a> {
|
||||||
.or(community_follower::person_id.eq(person_id_join)),
|
.or(community_follower::person_id.eq(person_id_join)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ListingType::Community => {
|
|
||||||
if self.community_actor_id.is_none() && self.community_id.is_none() {
|
|
||||||
return Err(QueryBuilderError("No community actor or id given".into()));
|
|
||||||
} else {
|
|
||||||
if let Some(community_id) = self.community_id {
|
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(community_actor_id) = self.community_actor_id {
|
|
||||||
query = query.filter(community::actor_id.eq(community_actor_id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if let Some(community_id) = self.community_id {
|
||||||
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(community_actor_id) = self.community_actor_id {
|
||||||
|
query = query.filter(community::actor_id.eq(community_actor_id))
|
||||||
|
}
|
||||||
|
|
||||||
if self.saved_only.unwrap_or(false) {
|
if self.saved_only.unwrap_or(false) {
|
||||||
query = query.filter(comment_saved::id.is_not_null());
|
query = query.filter(comment_saved::id.is_not_null());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
use crate::structs::PostView;
|
use crate::structs::PostView;
|
||||||
use diesel::{
|
use diesel::{dsl::*, pg::Pg, result::Error, *};
|
||||||
dsl::*,
|
|
||||||
pg::Pg,
|
|
||||||
result::{Error, Error::QueryBuilderError},
|
|
||||||
*,
|
|
||||||
};
|
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
newtypes::{CommunityId, DbUrl, PersonId, PostId},
|
||||||
|
@ -178,7 +173,7 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
pub fn create(conn: &'a PgConnection) -> Self {
|
pub fn create(conn: &'a PgConnection) -> Self {
|
||||||
PostQueryBuilder {
|
PostQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
listing_type: None,
|
listing_type: Some(ListingType::All),
|
||||||
sort: None,
|
sort: None,
|
||||||
creator_id: None,
|
creator_id: None,
|
||||||
community_id: None,
|
community_id: None,
|
||||||
|
@ -362,26 +357,21 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
.or(community_follower::person_id.eq(person_id_join)),
|
.or(community_follower::person_id.eq(person_id_join)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
ListingType::Community => {
|
|
||||||
if self.community_actor_id.is_none() && self.community_id.is_none() {
|
|
||||||
return Err(QueryBuilderError("No community actor or id given".into()));
|
|
||||||
} else {
|
|
||||||
if let Some(community_id) = self.community_id {
|
|
||||||
query = query
|
|
||||||
.filter(post::community_id.eq(community_id))
|
|
||||||
.then_order_by(post_aggregates::stickied.desc());
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(community_actor_id) = self.community_actor_id {
|
|
||||||
query = query
|
|
||||||
.filter(community::actor_id.eq(community_actor_id))
|
|
||||||
.then_order_by(post_aggregates::stickied.desc());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(community_id) = self.community_id {
|
||||||
|
query = query
|
||||||
|
.filter(post::community_id.eq(community_id))
|
||||||
|
.then_order_by(post_aggregates::stickied.desc());
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(community_actor_id) = self.community_actor_id {
|
||||||
|
query = query
|
||||||
|
.filter(community::actor_id.eq(community_actor_id))
|
||||||
|
.then_order_by(post_aggregates::stickied.desc());
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(url_search) = self.url_search {
|
if let Some(url_search) = self.url_search {
|
||||||
query = query.filter(post::url.eq(url_search));
|
query = query.filter(post::url.eq(url_search));
|
||||||
}
|
}
|
||||||
|
@ -517,7 +507,6 @@ mod tests {
|
||||||
},
|
},
|
||||||
traits::{Blockable, Crud, Likeable},
|
traits::{Blockable, Crud, Likeable},
|
||||||
utils::establish_unpooled_connection,
|
utils::establish_unpooled_connection,
|
||||||
ListingType,
|
|
||||||
SortType,
|
SortType,
|
||||||
SubscribedType,
|
SubscribedType,
|
||||||
};
|
};
|
||||||
|
@ -621,7 +610,6 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_post_listings_with_person = PostQueryBuilder::create(&conn)
|
let read_post_listings_with_person = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(ListingType::Community)
|
|
||||||
.sort(SortType::New)
|
.sort(SortType::New)
|
||||||
.show_bot_accounts(false)
|
.show_bot_accounts(false)
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
|
@ -630,7 +618,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_post_listings_no_person = PostQueryBuilder::create(&conn)
|
let read_post_listings_no_person = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(ListingType::Community)
|
|
||||||
.sort(SortType::New)
|
.sort(SortType::New)
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
.list()
|
.list()
|
||||||
|
@ -730,7 +717,6 @@ mod tests {
|
||||||
CommunityBlock::block(&conn, &community_block).unwrap();
|
CommunityBlock::block(&conn, &community_block).unwrap();
|
||||||
|
|
||||||
let read_post_listings_with_person_after_block = PostQueryBuilder::create(&conn)
|
let read_post_listings_with_person_after_block = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(ListingType::Community)
|
|
||||||
.sort(SortType::New)
|
.sort(SortType::New)
|
||||||
.show_bot_accounts(false)
|
.show_bot_accounts(false)
|
||||||
.community_id(inserted_community.id)
|
.community_id(inserted_community.id)
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
CommunityQueryBuilder {
|
CommunityQueryBuilder {
|
||||||
conn,
|
conn,
|
||||||
my_person_id: None,
|
my_person_id: None,
|
||||||
listing_type: None,
|
listing_type: Some(ListingType::All),
|
||||||
sort: None,
|
sort: None,
|
||||||
show_nsfw: None,
|
show_nsfw: None,
|
||||||
search_term: None,
|
search_term: None,
|
||||||
|
|
|
@ -213,7 +213,6 @@ fn get_feed_community(
|
||||||
let community = Community::read_from_name(conn, community_name, false)?;
|
let community = Community::read_from_name(conn, community_name, false)?;
|
||||||
|
|
||||||
let posts = PostQueryBuilder::create(conn)
|
let posts = PostQueryBuilder::create(conn)
|
||||||
.listing_type(ListingType::Community)
|
|
||||||
.sort(*sort_type)
|
.sort(*sort_type)
|
||||||
.community_id(community.id)
|
.community_id(community.id)
|
||||||
.limit(RSS_FETCH_LIMIT)
|
.limit(RSS_FETCH_LIMIT)
|
||||||
|
|
Loading…
Reference in a new issue