diff options
Diffstat (limited to 'server/src/db/post_view.rs')
-rw-r--r-- | server/src/db/post_view.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs index bec00b98..73686266 100644 --- a/server/src/db/post_view.rs +++ b/server/src/db/post_view.rs @@ -19,10 +19,12 @@ table! { published -> Timestamp, updated -> Nullable<Timestamp>, deleted -> Bool, + nsfw -> Bool, creator_name -> Varchar, community_name -> Varchar, community_removed -> Bool, community_deleted -> Bool, + community_nsfw -> Bool, number_of_comments -> BigInt, score -> BigInt, upvotes -> BigInt, @@ -51,10 +53,12 @@ pub struct PostView { pub published: chrono::NaiveDateTime, pub updated: Option<chrono::NaiveDateTime>, pub deleted: bool, + pub nsfw: bool, pub creator_name: String, pub community_name: String, pub community_removed: bool, pub community_deleted: bool, + pub community_nsfw: bool, pub number_of_comments: i64, pub score: i64, pub upvotes: i64, @@ -68,18 +72,20 @@ pub struct PostView { } impl PostView { - pub fn list(conn: &PgConnection, - type_: PostListingType, - sort: &SortType, - for_community_id: Option<i32>, - for_creator_id: Option<i32>, - search_term: Option<String>, - my_user_id: Option<i32>, - saved_only: bool, - unread_only: bool, - page: Option<i64>, - limit: Option<i64>, - ) -> Result<Vec<Self>, Error> { + pub fn list( + conn: &PgConnection, + type_: PostListingType, + sort: &SortType, + for_community_id: Option<i32>, + for_creator_id: Option<i32>, + search_term: Option<String>, + my_user_id: Option<i32>, + show_nsfw: bool, + saved_only: bool, + unread_only: bool, + page: Option<i64>, + limit: Option<i64>, + ) -> Result<Vec<Self>, Error> { use super::post_view::post_view::dsl::*; let (limit, offset) = limit_and_offset(page, limit); @@ -121,6 +127,12 @@ impl PostView { query = query.filter(user_id.is_null()); } + if !show_nsfw { + query = query + .filter(nsfw.eq(false)) + .filter(community_nsfw.eq(false)); + }; + query = match sort { SortType::Hot => query.order_by(hot_rank.desc()) .then_order_by(published.desc()), @@ -266,6 +278,7 @@ mod tests { community_name: community_name.to_owned(), community_removed: false, community_deleted: false, + community_nsfw: false, number_of_comments: 0, score: 1, upvotes: 1, @@ -294,6 +307,7 @@ mod tests { community_name: community_name.to_owned(), community_removed: false, community_deleted: false, + community_nsfw: false, number_of_comments: 0, score: 1, upvotes: 1, |