mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-14 00:37:07 +00:00
Filter comment listing by language
This commit is contained in:
parent
d74b7c04ff
commit
9d66314c32
3 changed files with 17 additions and 3 deletions
|
@ -21,6 +21,9 @@ impl PerformCrud for GetComments {
|
|||
let show_bot_accounts = local_user_view
|
||||
.as_ref()
|
||||
.map(|t| t.local_user.show_bot_accounts);
|
||||
let languages = local_user_view
|
||||
.as_ref()
|
||||
.map(|l| l.local_user.discussion_languages.clone());
|
||||
let person_id = local_user_view.map(|u| u.person.id);
|
||||
|
||||
let sort: Option<SortType> = from_opt_str_to_opt_enum(&data.sort);
|
||||
|
@ -40,6 +43,7 @@ impl PerformCrud for GetComments {
|
|||
.community_name(community_name)
|
||||
.my_person_id(person_id)
|
||||
.show_bot_accounts(show_bot_accounts)
|
||||
.languages(languages)
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
.list()
|
||||
|
|
|
@ -113,9 +113,7 @@ impl PerformCrud for GetPosts {
|
|||
let community_id = data.community_id;
|
||||
let community_name = data.community_name.to_owned();
|
||||
let saved_only = data.saved_only;
|
||||
let languages = local_user_view
|
||||
.map(|l| l.local_user.discussion_languages)
|
||||
.unwrap_or_default();
|
||||
let languages = local_user_view.map(|l| l.local_user.discussion_languages);
|
||||
|
||||
let posts = blocking(context.pool(), move |conn| {
|
||||
PostQueryBuilder::create(conn)
|
||||
|
|
|
@ -34,6 +34,7 @@ use lemmy_db_schema::{
|
|||
CommunityId,
|
||||
PersonId,
|
||||
PostId,
|
||||
PrimaryLanguageTag,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
||||
|
@ -184,6 +185,7 @@ pub struct CommentQueryBuilder<'a> {
|
|||
saved_only: Option<bool>,
|
||||
unread_only: Option<bool>,
|
||||
show_bot_accounts: Option<bool>,
|
||||
languages: Option<Vec<PrimaryLanguageTag>>,
|
||||
page: Option<i64>,
|
||||
limit: Option<i64>,
|
||||
}
|
||||
|
@ -204,6 +206,7 @@ impl<'a> CommentQueryBuilder<'a> {
|
|||
saved_only: None,
|
||||
unread_only: None,
|
||||
show_bot_accounts: None,
|
||||
languages: None,
|
||||
page: None,
|
||||
limit: None,
|
||||
}
|
||||
|
@ -269,6 +272,11 @@ impl<'a> CommentQueryBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn languages<T: MaybeOptional<Vec<PrimaryLanguageTag>>>(mut self, languages: T) -> Self {
|
||||
self.languages = languages.get_optional();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn page<T: MaybeOptional<i64>>(mut self, page: T) -> Self {
|
||||
self.page = page.get_optional();
|
||||
self
|
||||
|
@ -392,6 +400,10 @@ impl<'a> CommentQueryBuilder<'a> {
|
|||
query = query.filter(person::bot_account.eq(false));
|
||||
};
|
||||
|
||||
if let Some(languages) = self.languages {
|
||||
query = query.filter(comment::language.eq(any(languages)))
|
||||
}
|
||||
|
||||
query = match self.sort.unwrap_or(SortType::New) {
|
||||
SortType::Hot | SortType::Active => query
|
||||
.order_by(hot_rank(comment_aggregates::score, comment_aggregates::published).desc())
|
||||
|
|
Loading…
Reference in a new issue