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