From d7ab85ab70478f1ec440c920d726d08b145cef5e Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 13 Aug 2019 19:52:43 -0700 Subject: Squashed commit of the following: commit ecd6c5a2f47cbbb2fc4bf482fadd78380303a904 Author: Dessalines Date: Tue Aug 13 19:49:38 2019 -0700 Adding some docs commit 3babd09affb1920da3d0a0ceb7e24c8aeeb9cf1a Author: Dessalines Date: Tue Aug 13 19:28:46 2019 -0700 Adding save user settings commit 6e8da9cc9e522d0da668bfa31944c3348cc79620 Merge: 3246d5d c148eef Author: Dessalines Date: Tue Aug 13 17:26:25 2019 -0700 Merge branch 'dev' into nsfw commit b3d4a5c4ce441bcc664704aba44cedb51d887599 Author: Dessalines Date: Sun Aug 11 20:55:09 2019 -0700 nsfw mostly done, except for settings page. --- server/src/api/community.rs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'server/src/api/community.rs') diff --git a/server/src/api/community.rs b/server/src/api/community.rs index ca73de49..74058488 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -22,7 +22,8 @@ pub struct CreateCommunity { name: String, title: String, description: Option, - category_id: i32 , + category_id: i32, + nsfw: bool, auth: String } @@ -86,6 +87,7 @@ pub struct EditCommunity { category_id: i32, removed: Option, deleted: Option, + nsfw: bool, reason: Option, expires: Option, auth: String @@ -194,6 +196,7 @@ impl Perform for Oper { creator_id: user_id, removed: None, deleted: None, + nsfw: data.nsfw, updated: None, }; @@ -291,6 +294,7 @@ impl Perform for Oper { creator_id: user_id, removed: data.removed.to_owned(), deleted: data.deleted.to_owned(), + nsfw: data.nsfw, updated: Some(naive_now()) }; @@ -333,22 +337,38 @@ impl Perform for Oper { let data: &ListCommunities = &self.data; let conn = establish_connection(); - let user_id: Option = match &data.auth { + let user_claims: Option = match &data.auth { Some(auth) => { match Claims::decode(&auth) { Ok(claims) => { - let user_id = claims.claims.id; - Some(user_id) + Some(claims.claims) } Err(_e) => None } } None => None }; + + let user_id = match &user_claims { + Some(claims) => Some(claims.id), + None => None + }; + + let show_nsfw = match &user_claims { + Some(claims) => claims.show_nsfw, + None => false + }; let sort = SortType::from_str(&data.sort)?; - let communities: Vec = CommunityView::list(&conn, &sort, user_id, None, data.page, data.limit)?; + let communities: Vec = CommunityView::list( + &conn, + &sort, + user_id, + show_nsfw, + None, + data.page, + data.limit)?; // Return the jwt Ok( -- cgit v1.2.3