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

Fix listing type default value #2796

Merged
merged 2 commits into from
Apr 12, 2023
Merged

Fix listing type default value #2796

merged 2 commits into from
Apr 12, 2023

Conversation

Nutomic
Copy link
Member

@Nutomic Nutomic commented Apr 4, 2023

The listing type parameter is only meant for the frontpage, but is
also applied inside of communities. The result is that this call
returns nothing, because it defaults to ListingType::Local:
https://fedibb.ml/api/v3/post/list?community_id=3

It needs to be called like this to get any posts:
https://fedibb.ml/api/v3/post/list?community_id=3&type_=All

This is clearly not expected behaviour, when a community is
specified, the listing type should default to All.

Also simplified the defaults for db view forms in second commit.

@Nutomic Nutomic requested a review from dessalines as a code owner April 4, 2023 21:12
let max_depth = data.max_depth;
let saved_only = data.saved_only;
let page = data.page;
let limit = data.limit;
let parent_id = data.parent_id;

// On frontpage use listing type from param or admin configured default
Copy link
Member

Choose a reason for hiding this comment

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

This is copy pasted below, might as well use a helper function.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, I didnt do that before because with community_id and community_actor_id, there would have been too many parameters and it would be awkward. Added helper now.

} else {
// inside of community show everything
ListingType::All
};
Copy link
Member

Choose a reason for hiding this comment

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

Here's the other place its pasted.

@@ -167,10 +167,9 @@ impl CommentView {
pub struct CommentQuery<'a> {
#[builder(!default)]
pool: &'a DbPool,
listing_type: Option<ListingType>,
sort: Option<CommentSortType>,
listing_type: ListingType,
Copy link
Member

Choose a reason for hiding this comment

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

Since these aren't optional anymore, you might need to add that builder !default line to these two.

edit:

To me it makes sense to leave these optional, and move the unwrap_or_default into the query impls.

@@ -220,11 +220,10 @@ impl PostView {
pub struct PostQuery<'a> {
#[builder(!default)]
pool: &'a DbPool,
listing_type: Option<ListingType>,
sort: Option<SortType>,
listing_type: ListingType,
Copy link
Member

Choose a reason for hiding this comment

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

Same

@@ -121,8 +121,8 @@ impl CommunityView {
pub struct CommunityQuery<'a> {
#[builder(!default)]
pool: &'a DbPool,
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@@ -176,7 +176,7 @@ impl<'a> CommunityQuery<'a> {
.filter(community::deleted.eq(false));
}

match self.sort.unwrap_or(SortType::Hot) {
match self.sort {
Copy link
Member

Choose a reason for hiding this comment

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

Makes more sense to me have these optional in the builder, and move the unwrap_or_default to here.

@@ -73,7 +73,7 @@ impl PersonView {
pub struct PersonQuery<'a> {
#[builder(!default)]
pool: &'a DbPool,
sort: Option<SortType>,
sort: SortType,
search_term: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

Same issue.

@Nutomic Nutomic force-pushed the fix-listing-type branch from 16053bf to e9dcd84 Compare April 6, 2023 20:22
@Nutomic
Copy link
Member Author

Nutomic commented Apr 6, 2023

I removed the second commit, apparently its not as easy as I thought.

The listing type parameter is only meant for the frontpage, but is
also applied inside of communities. The result is that this call
returns nothing, because it defaults to ListingType::Local:
https://fedibb.ml/api/v3/post/list?community_id=3

It needs to be called like this to get any posts:
https://fedibb.ml/api/v3/post/list?community_id=3&type_=All

This is clearly not expected behaviour, when a community is
specified, the listing type should default to All.
@Nutomic Nutomic force-pushed the fix-listing-type branch from e9dcd84 to 3bff89b Compare April 6, 2023 20:23
@dessalines
Copy link
Member

Feel free to merge once you get to the clippy issues.

@Nutomic Nutomic enabled auto-merge (squash) April 11, 2023 20:15
@dessalines dessalines disabled auto-merge April 12, 2023 14:40
@dessalines dessalines merged commit 9d26ac2 into main Apr 12, 2023
@dessalines
Copy link
Member

I'll see what I can do to fix this woodpecker issue on another PR.

dessalines pushed a commit that referenced this pull request Apr 26, 2023
* Fix listing type default value

The listing type parameter is only meant for the frontpage, but is
also applied inside of communities. The result is that this call
returns nothing, because it defaults to ListingType::Local:
https://fedibb.ml/api/v3/post/list?community_id=3

It needs to be called like this to get any posts:
https://fedibb.ml/api/v3/post/list?community_id=3&type_=All

This is clearly not expected behaviour, when a community is
specified, the listing type should default to All.

* fix clippy
Nutomic added a commit that referenced this pull request Apr 27, 2023
* Fix listing type default value

The listing type parameter is only meant for the frontpage, but is
also applied inside of communities. The result is that this call
returns nothing, because it defaults to ListingType::Local:
https://fedibb.ml/api/v3/post/list?community_id=3

It needs to be called like this to get any posts:
https://fedibb.ml/api/v3/post/list?community_id=3&type_=All

This is clearly not expected behaviour, when a community is
specified, the listing type should default to All.

* fix clippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants