-
-
Notifications
You must be signed in to change notification settings - Fork 886
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
Adding saved_only, liked_only, and disliked_only filters to search. #5034
Changes from 2 commits
601a0da
d2995d4
57045bb
7e07ea9
5ee6893
67f4d1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -999,6 +999,18 @@ fn limit_expire_time(expires: DateTime<Utc>) -> LemmyResult<Option<DateTime<Utc> | |
} | ||
} | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub fn check_conflicting_like_filters( | ||
liked_only: Option<bool>, | ||
disliked_only: Option<bool>, | ||
) -> LemmyResult<()> { | ||
if liked_only.unwrap_or_default() && disliked_only.unwrap_or_default() { | ||
Err(LemmyErrorType::ContradictingFilters)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the question mark needed since we're returning an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked, and its necessary to convert from the LemmyErrorType to a LemmyError.
|
||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub async fn process_markdown( | ||
text: &str, | ||
slur_regex: &Option<Regex>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ use actix_web::web::{Json, Query}; | |
use lemmy_api_common::{ | ||
context::LemmyContext, | ||
site::{Search, SearchResponse}, | ||
utils::{check_private_instance, is_admin}, | ||
utils::{check_conflicting_like_filters, check_private_instance, is_admin}, | ||
}; | ||
use lemmy_db_schema::{source::community::Community, utils::post_to_comment_sort_type, SearchType}; | ||
use lemmy_db_views::{ | ||
|
@@ -55,49 +55,62 @@ pub async fn search( | |
let creator_id = data.creator_id; | ||
let local_user = local_user_view.as_ref().map(|l| &l.local_user); | ||
let post_title_only = data.post_title_only; | ||
let post_url_only = data.post_url_only; | ||
let saved_only = data.saved_only; | ||
|
||
let liked_only = data.liked_only; | ||
let disliked_only = data.disliked_only; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With how many variables that are just let Query(Search {
q,
community_id,
community_name,
creator_id,
type_,
sort,
listing_type,
page,
limit,
post_title_only,
post_url_only,
saved_only,
liked_only,
disliked_only
}) = data; Then, everywhere that follows the pattern I mentioned above will become redundant. Places like line 40 will just be like Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya, I can do this, at least for the ones that don't need any manipulation. |
||
check_conflicting_like_filters(liked_only, disliked_only)?; | ||
|
||
let posts_query = PostQuery { | ||
sort: (sort), | ||
listing_type: (listing_type), | ||
community_id: (community_id), | ||
creator_id: (creator_id), | ||
sort, | ||
listing_type, | ||
community_id, | ||
creator_id, | ||
local_user, | ||
search_term: (Some(q.clone())), | ||
page: (page), | ||
limit: (limit), | ||
title_only: (post_title_only), | ||
search_term: Some(q.clone()), | ||
page, | ||
limit, | ||
title_only: post_title_only, | ||
url_only: post_url_only, | ||
liked_only, | ||
disliked_only, | ||
saved_only, | ||
..Default::default() | ||
}; | ||
|
||
let comment_query = CommentQuery { | ||
sort: (sort.map(post_to_comment_sort_type)), | ||
listing_type: (listing_type), | ||
search_term: (Some(q.clone())), | ||
community_id: (community_id), | ||
creator_id: (creator_id), | ||
sort: sort.map(post_to_comment_sort_type), | ||
listing_type, | ||
search_term: Some(q.clone()), | ||
community_id, | ||
creator_id, | ||
local_user, | ||
page: (page), | ||
limit: (limit), | ||
page, | ||
limit, | ||
liked_only, | ||
disliked_only, | ||
saved_only, | ||
..Default::default() | ||
}; | ||
|
||
let community_query = CommunityQuery { | ||
sort: (sort), | ||
listing_type: (listing_type), | ||
search_term: (Some(q.clone())), | ||
sort, | ||
listing_type, | ||
search_term: Some(q.clone()), | ||
local_user, | ||
is_mod_or_admin: (is_admin), | ||
page: (page), | ||
limit: (limit), | ||
is_mod_or_admin: is_admin, | ||
page, | ||
limit, | ||
..Default::default() | ||
}; | ||
|
||
let person_query = PersonQuery { | ||
sort, | ||
search_term: (Some(q.clone())), | ||
listing_type: (listing_type), | ||
page: (page), | ||
limit: (limit), | ||
search_term: Some(q.clone()), | ||
listing_type, | ||
page, | ||
limit, | ||
}; | ||
|
||
match search_type { | ||
|
@@ -142,21 +155,6 @@ pub async fn search( | |
person_query.list(&mut context.pool()).await? | ||
}; | ||
} | ||
SearchType::Url => { | ||
posts = PostQuery { | ||
sort: (sort), | ||
listing_type: (listing_type), | ||
community_id: (community_id), | ||
creator_id: (creator_id), | ||
url_search: (Some(q)), | ||
local_user, | ||
page: (page), | ||
limit: (limit), | ||
..Default::default() | ||
} | ||
.list(&local_site.site, &mut context.pool()) | ||
.await?; | ||
} | ||
}; | ||
|
||
// Return the jwt | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disliked_only wasnt requested and I doubt that anyone would use it.