parent
b009d45729
commit
f5066b1f0b
2 changed files with 85 additions and 65 deletions
|
@ -216,7 +216,6 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.filter(post::community_id.eq(community_id));
|
query = query.filter(post::community_id.eq(community_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
|
||||||
let is_subscribed = exists(
|
let is_subscribed = exists(
|
||||||
community_follower::table.filter(
|
community_follower::table.filter(
|
||||||
post::community_id
|
post::community_id
|
||||||
|
@ -225,7 +224,7 @@ fn queries<'a>() -> Queries<
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
match listing_type {
|
match options.listing_type.unwrap_or_default() {
|
||||||
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
ListingType::Subscribed => query = query.filter(is_subscribed), /* TODO could be this: and(community_follower::person_id.eq(person_id_join)), */
|
||||||
ListingType::Local => {
|
ListingType::Local => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -243,7 +242,6 @@ fn queries<'a>() -> Queries<
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If its saved only, then filter, and order by the saved time, not the comment creation time.
|
// If its saved only, then filter, and order by the saved time, not the comment creation time.
|
||||||
if options.saved_only.unwrap_or_default() {
|
if options.saved_only.unwrap_or_default() {
|
||||||
|
|
|
@ -346,16 +346,14 @@ fn queries<'a>() -> Queries<
|
||||||
query = query.filter(post_aggregates::creator_id.eq(creator_id));
|
query = query.filter(post_aggregates::creator_id.eq(creator_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(listing_type) = options.listing_type {
|
|
||||||
if let Some(person_id) = options.local_user.person_id() {
|
|
||||||
let is_subscribed = exists(
|
let is_subscribed = exists(
|
||||||
community_follower::table.filter(
|
community_follower::table.filter(
|
||||||
post_aggregates::community_id
|
post_aggregates::community_id
|
||||||
.eq(community_follower::community_id)
|
.eq(community_follower::community_id)
|
||||||
.and(community_follower::person_id.eq(person_id)),
|
.and(community_follower::person_id.eq(person_id_join)),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
match listing_type {
|
match options.listing_type.unwrap_or_default() {
|
||||||
ListingType::Subscribed => query = query.filter(is_subscribed),
|
ListingType::Subscribed => query = query.filter(is_subscribed),
|
||||||
ListingType::Local => {
|
ListingType::Local => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -368,26 +366,11 @@ fn queries<'a>() -> Queries<
|
||||||
community_moderator::table.filter(
|
community_moderator::table.filter(
|
||||||
post::community_id
|
post::community_id
|
||||||
.eq(community_moderator::community_id)
|
.eq(community_moderator::community_id)
|
||||||
.and(community_moderator::person_id.eq(person_id)),
|
.and(community_moderator::person_id.eq(person_id_join)),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If your person_id is missing, only show local
|
|
||||||
else {
|
|
||||||
match listing_type {
|
|
||||||
ListingType::Local => {
|
|
||||||
query = query
|
|
||||||
.filter(community::local.eq(true))
|
|
||||||
.filter(community::hidden.eq(false));
|
|
||||||
}
|
|
||||||
_ => query = query.filter(community::hidden.eq(false)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
query = query.filter(community::hidden.eq(false));
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(search_term) = &options.search_term {
|
if let Some(search_term) = &options.search_term {
|
||||||
if options.url_only.unwrap_or_default() {
|
if options.url_only.unwrap_or_default() {
|
||||||
|
@ -754,6 +737,8 @@ mod tests {
|
||||||
comment::{Comment, CommentInsertForm},
|
comment::{Comment, CommentInsertForm},
|
||||||
community::{
|
community::{
|
||||||
Community,
|
Community,
|
||||||
|
CommunityFollower,
|
||||||
|
CommunityFollowerForm,
|
||||||
CommunityInsertForm,
|
CommunityInsertForm,
|
||||||
CommunityModerator,
|
CommunityModerator,
|
||||||
CommunityModeratorForm,
|
CommunityModeratorForm,
|
||||||
|
@ -782,7 +767,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
site::Site,
|
site::Site,
|
||||||
},
|
},
|
||||||
traits::{Bannable, Blockable, Crud, Joinable, Likeable, Saveable},
|
traits::{Bannable, Blockable, Crud, Followable, Joinable, Likeable, Saveable},
|
||||||
utils::{build_db_pool, build_db_pool_for_tests, DbPool, RANK_DEFAULT},
|
utils::{build_db_pool, build_db_pool_for_tests, DbPool, RANK_DEFAULT},
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
PostSortType,
|
PostSortType,
|
||||||
|
@ -1432,6 +1417,43 @@ mod tests {
|
||||||
cleanup(data, pool).await
|
cleanup(data, pool).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn post_listings_hidden_community() -> LemmyResult<()> {
|
||||||
|
let pool = &build_db_pool().await?;
|
||||||
|
let pool = &mut pool.into();
|
||||||
|
let data = init_data(pool).await?;
|
||||||
|
|
||||||
|
Community::update(
|
||||||
|
pool,
|
||||||
|
data.inserted_community.id,
|
||||||
|
&CommunityUpdateForm {
|
||||||
|
hidden: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let posts = PostQuery::default().list(&data.site, pool).await?;
|
||||||
|
assert!(posts.is_empty());
|
||||||
|
|
||||||
|
let posts = data.default_post_query().list(&data.site, pool).await?;
|
||||||
|
assert!(posts.is_empty());
|
||||||
|
|
||||||
|
// Follow the community
|
||||||
|
let form = CommunityFollowerForm {
|
||||||
|
community_id: data.inserted_community.id,
|
||||||
|
person_id: data.local_user_view.person.id,
|
||||||
|
pending: false,
|
||||||
|
};
|
||||||
|
CommunityFollower::follow(pool, &form).await?;
|
||||||
|
|
||||||
|
let posts = data.default_post_query().list(&data.site, pool).await?;
|
||||||
|
assert!(!posts.is_empty());
|
||||||
|
|
||||||
|
cleanup(data, pool).await
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial]
|
#[serial]
|
||||||
async fn post_listing_instance_block() -> LemmyResult<()> {
|
async fn post_listing_instance_block() -> LemmyResult<()> {
|
||||||
|
|
Loading…
Reference in a new issue