Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "show_nsfw" to the Community API. #3363

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/api_common/src/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct CommunityResponse {
pub struct ListCommunities {
pub type_: Option<ListingType>,
pub sort: Option<SortType>,
pub show_nsfw: Option<bool>,
pub page: Option<i64>,
pub limit: Option<i64>,
pub auth: Option<Sensitive<String>>,
Expand Down
2 changes: 2 additions & 0 deletions crates/api_crud/src/community/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ impl PerformCrud for ListCommunities {

let sort = data.sort;
let listing_type = data.type_;
let show_nsfw = data.show_nsfw;
let page = data.page;
let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
let communities = CommunityQuery::builder()
.pool(context.pool())
.listing_type(listing_type)
.show_nsfw(show_nsfw)
.sort(sort)
.local_user(local_user.as_ref())
.page(page)
Expand Down
5 changes: 3 additions & 2 deletions crates/db_views_actor/src/community_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub struct CommunityQuery<'a> {
local_user: Option<&'a LocalUser>,
search_term: Option<String>,
is_mod_or_admin: Option<bool>,
show_nsfw: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
}
Expand Down Expand Up @@ -203,8 +204,8 @@ impl<'a> CommunityQuery<'a> {
query = query.filter(community_block::person_id.is_null());
query = query.filter(community::nsfw.eq(false).or(local_user::show_nsfw.eq(true)));
} else {
// No person in request, only show nsfw communities if show_nsfw passed into request
if !self.local_user.map(|l| l.show_nsfw).unwrap_or(false) {
// No person in request, only show nsfw communities if show_nsfw is passed into request
if !self.show_nsfw.unwrap_or(false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you replaced should be illuminating.

You are overriding / ignoring the users show_nsfw preference. Why?

Copy link
Contributor Author

@tgxn tgxn Jun 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
Does not the first part of this condition check where there IS a local user?
The else path looks like it should only execute when there is no local user.

I'm not full bottle on the syntax in rust, though. I tested this using docker-compose and it still appears to respect my users' show_nsfw preference when logged in. (and the show_nsfw query param worked on /community/list)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this looks correct, it makes no sense to check for local user in else branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh okay I see that now, sry.

query = query.filter(community::nsfw.eq(false));
}
}
Expand Down