mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
This commit is contained in:
parent
a7c1c472fe
commit
7556f8615f
4 changed files with 24 additions and 4 deletions
1
docs/src/contributing_websocket_http_api.md
vendored
1
docs/src/contributing_websocket_http_api.md
vendored
|
@ -1149,6 +1149,7 @@ Post listing types are `All, Subscribed, Community`
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
community_id: Option<i32>,
|
community_id: Option<i32>,
|
||||||
|
community_name: Option<String>,
|
||||||
auth: Option<String>
|
auth: Option<String>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,7 @@ pub struct PostQueryBuilder<'a> {
|
||||||
my_user_id: Option<i32>,
|
my_user_id: Option<i32>,
|
||||||
for_creator_id: Option<i32>,
|
for_creator_id: Option<i32>,
|
||||||
for_community_id: Option<i32>,
|
for_community_id: Option<i32>,
|
||||||
|
for_community_name: Option<String>,
|
||||||
search_term: Option<String>,
|
search_term: Option<String>,
|
||||||
url_search: Option<String>,
|
url_search: Option<String>,
|
||||||
show_nsfw: bool,
|
show_nsfw: bool,
|
||||||
|
@ -181,6 +182,7 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
my_user_id: None,
|
my_user_id: None,
|
||||||
for_creator_id: None,
|
for_creator_id: None,
|
||||||
for_community_id: None,
|
for_community_id: None,
|
||||||
|
for_community_name: None,
|
||||||
search_term: None,
|
search_term: None,
|
||||||
url_search: None,
|
url_search: None,
|
||||||
show_nsfw: true,
|
show_nsfw: true,
|
||||||
|
@ -206,6 +208,11 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn for_community_name<T: MaybeOptional<String>>(mut self, for_community_name: T) -> Self {
|
||||||
|
self.for_community_name = for_community_name.get_optional();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn for_creator_id<T: MaybeOptional<i32>>(mut self, for_creator_id: T) -> Self {
|
pub fn for_creator_id<T: MaybeOptional<i32>>(mut self, for_creator_id: T) -> Self {
|
||||||
self.for_creator_id = for_creator_id.get_optional();
|
self.for_creator_id = for_creator_id.get_optional();
|
||||||
self
|
self
|
||||||
|
@ -265,6 +272,11 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
query = query.then_order_by(stickied.desc());
|
query = query.then_order_by(stickied.desc());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(for_community_name) = self.for_community_name {
|
||||||
|
query = query.filter(community_name.eq(for_community_name));
|
||||||
|
query = query.then_order_by(stickied.desc());
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(url_search) = self.url_search {
|
if let Some(url_search) = self.url_search {
|
||||||
query = query.filter(url.eq(url_search));
|
query = query.filter(url.eq(url_search));
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,8 +167,8 @@ mod tests {
|
||||||
use crate::{
|
use crate::{
|
||||||
is_email_regex,
|
is_email_regex,
|
||||||
is_valid_community_name,
|
is_valid_community_name,
|
||||||
is_valid_username,
|
|
||||||
is_valid_post_title,
|
is_valid_post_title,
|
||||||
|
is_valid_username,
|
||||||
remove_slurs,
|
remove_slurs,
|
||||||
scrape_text_for_mentions,
|
scrape_text_for_mentions,
|
||||||
slur_check,
|
slur_check,
|
||||||
|
@ -216,8 +216,6 @@ mod tests {
|
||||||
assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
|
assert!(!is_valid_post_title("\n \n \n \n ")); // tabs/spaces/newlines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_slur_filter() {
|
fn test_slur_filter() {
|
||||||
let test =
|
let test =
|
||||||
|
|
|
@ -28,7 +28,13 @@ use lemmy_db::{
|
||||||
Saveable,
|
Saveable,
|
||||||
SortType,
|
SortType,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{is_valid_post_title, make_apub_endpoint, slur_check, slurs_vec_to_str, EndpointType};
|
use lemmy_utils::{
|
||||||
|
is_valid_post_title,
|
||||||
|
make_apub_endpoint,
|
||||||
|
slur_check,
|
||||||
|
slurs_vec_to_str,
|
||||||
|
EndpointType,
|
||||||
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -70,6 +76,7 @@ pub struct GetPosts {
|
||||||
page: Option<i64>,
|
page: Option<i64>,
|
||||||
limit: Option<i64>,
|
limit: Option<i64>,
|
||||||
pub community_id: Option<i32>,
|
pub community_id: Option<i32>,
|
||||||
|
pub community_name: Option<String>,
|
||||||
auth: Option<String>,
|
auth: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,12 +376,14 @@ impl Perform for Oper<GetPosts> {
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
let limit = data.limit;
|
let limit = data.limit;
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
|
let community_name = data.community_name.to_owned();
|
||||||
let posts = match blocking(pool, move |conn| {
|
let posts = match blocking(pool, move |conn| {
|
||||||
PostQueryBuilder::create(conn)
|
PostQueryBuilder::create(conn)
|
||||||
.listing_type(type_)
|
.listing_type(type_)
|
||||||
.sort(&sort)
|
.sort(&sort)
|
||||||
.show_nsfw(show_nsfw)
|
.show_nsfw(show_nsfw)
|
||||||
.for_community_id(community_id)
|
.for_community_id(community_id)
|
||||||
|
.for_community_name(community_name)
|
||||||
.my_user_id(user_id)
|
.my_user_id(user_id)
|
||||||
.page(page)
|
.page(page)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
|
|
Loading…
Reference in a new issue