summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorDessalines <happydooby@gmail.com>2019-08-13 19:52:43 -0700
committerDessalines <happydooby@gmail.com>2019-08-13 19:52:43 -0700
commit70628d89c0b0e0fb4694b57a3657d49eb26abb54 (patch)
tree37fd5d0f5117cb5cf07ba7e233f3734d65deadd6 /server/src
parentc148eefc1df3eda124246691f62cc7ecfe2d3558 (diff)
Squashed commit of the following:
commit 309d3ec01fb2372e67920cdd7b028c0b80c4ebe6 Author: Dessalines <happydooby@gmail.com> Date: Tue Aug 13 19:49:38 2019 -0700 Adding some docs commit da18d304377c96e31a511b11b1a4cf1d0b0f0ab7 Author: Dessalines <happydooby@gmail.com> Date: Tue Aug 13 19:28:46 2019 -0700 Adding save user settings commit 0cd84440f4b35dbc7d7fa825291c783114b327c9 Merge: 3246d5d c148eef Author: Dessalines <happydooby@gmail.com> Date: Tue Aug 13 17:26:25 2019 -0700 Merge branch 'dev' into nsfw commit 3246d5d670d0d5e10310a90c6fd81a7dc9e97e54 Author: Dessalines <happydooby@gmail.com> Date: Sun Aug 11 20:55:09 2019 -0700 nsfw mostly done, except for settings page.
Diffstat (limited to 'server/src')
-rw-r--r--server/src/api/community.rs30
-rw-r--r--server/src/api/mod.rs2
-rw-r--r--server/src/api/post.rs44
-rw-r--r--server/src/api/site.rs6
-rw-r--r--server/src/api/user.rs156
-rw-r--r--server/src/db/community.rs4
-rw-r--r--server/src/db/community_view.rs22
-rw-r--r--server/src/db/post.rs4
-rw-r--r--server/src/db/post_view.rs38
-rw-r--r--server/src/db/user.rs14
-rw-r--r--server/src/lib.rs1
-rw-r--r--server/src/schema.rs3
-rw-r--r--server/src/websocket/server.rs29
13 files changed, 255 insertions, 98 deletions
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<String>,
- category_id: i32 ,
+ category_id: i32,
+ nsfw: bool,
auth: String
}
@@ -86,6 +87,7 @@ pub struct EditCommunity {
category_id: i32,
removed: Option<bool>,
deleted: Option<bool>,
+ nsfw: bool,
reason: Option<String>,
expires: Option<i64>,
auth: String
@@ -194,6 +196,7 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
creator_id: user_id,
removed: None,
deleted: None,
+ nsfw: data.nsfw,
updated: None,
};
@@ -291,6 +294,7 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
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<ListCommunitiesResponse> for Oper<ListCommunities> {
let data: &ListCommunities = &self.data;
let conn = establish_connection();
- let user_id: Option<i32> = match &data.auth {
+ let user_claims: Option<Claims> = 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> = CommunityView::list(&conn, &sort, user_id, None, data.page, data.limit)?;
+ let communities: Vec<CommunityView> = CommunityView::list(
+ &conn,
+ &sort,
+ user_id,
+ show_nsfw,
+ None,
+ data.page,
+ data.limit)?;
// Return the jwt
Ok(
diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs
index e10770b4..3a4a0865 100644
--- a/server/src/api/mod.rs
+++ b/server/src/api/mod.rs
@@ -22,7 +22,7 @@ pub mod site;
#[derive(EnumString,ToString,Debug)]
pub enum UserOperation {
- Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead
+ Login, Register, CreateCommunity, CreatePost, ListCommunities, ListCategories, GetPost, GetCommunity, CreateComment, EditComment, SaveComment, CreateCommentLike, GetPosts, CreatePostLike, EditPost, SavePost, EditCommunity, FollowCommunity, GetFollowedCommunities, GetUserDetails, GetReplies, GetModlog, BanFromCommunity, AddModToCommunity, CreateSite, EditSite, GetSite, AddAdmin, BanUser, Search, MarkAllAsRead, SaveUserSettings
}
#[derive(Fail, Debug)]
diff --git a/server/src/api/post.rs b/server/src/api/post.rs
index df6ea852..35363a17 100644
--- a/server/src/api/post.rs
+++ b/server/src/api/post.rs
@@ -6,6 +6,7 @@ pub struct CreatePost {
name: String,
url: Option<String>,
body: Option<String>,
+ nsfw: bool,
community_id: i32,
auth: String
}
@@ -73,6 +74,7 @@ pub struct EditPost {
body: Option<String>,
removed: Option<bool>,
deleted: Option<bool>,
+ nsfw: bool,
locked: Option<bool>,
reason: Option<String>,
auth: String
@@ -123,6 +125,7 @@ impl Perform<PostResponse> for Oper<CreatePost> {
creator_id: user_id,
removed: None,
deleted: None,
+ nsfw: data.nsfw,
locked: None,
updated: None
};
@@ -219,40 +222,50 @@ impl Perform<GetPostsResponse> for Oper<GetPosts> {
let data: &GetPosts = &self.data;
let conn = establish_connection();
- let user_id: Option<i32> = match &data.auth {
+ let user_claims: Option<Claims> = 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 type_ = PostListingType::from_str(&data.type_)?;
let sort = SortType::from_str(&data.sort)?;
- let posts = match PostView::list(&conn,
- type_,
- &sort,
- data.community_id,
- None,
- None,
- user_id,
- false,
- false,
- data.page,
- data.limit) {
+ let posts = match PostView::list(
+ &conn,
+ type_,
+ &sort,
+ data.community_id,
+ None,
+ None,
+ user_id,
+ show_nsfw,
+ false,
+ false,
+ data.page,
+ data.limit) {
Ok(posts) => posts,
Err(_e) => {
return Err(APIError::err(&self.op, "couldnt_get_posts"))?
}
};
- // Return the jwt
Ok(
GetPostsResponse {
op: self.op.to_string(),
@@ -381,6 +394,7 @@ impl Perform<PostResponse> for Oper<EditPost> {
community_id: data.community_id,
removed: data.removed.to_owned(),
deleted: data.deleted.to_owned(),
+ nsfw: data.nsfw,
locked: data.locked.to_owned(),
updated: Some(naive_now())
};
diff --git a/server/src/api/site.rs b/server/src/api/site.rs
index 09af742f..8f094aac 100644
--- a/server/src/api/site.rs
+++ b/server/src/api/site.rs
@@ -277,6 +277,8 @@ impl Perform<SearchResponse> for Oper<Search> {
let mut communities = Vec::new();
let mut users = Vec::new();
+ // TODO no clean / non-nsfw searching rn
+
match type_ {
SearchType::Posts => {
posts = PostView::list(
@@ -287,6 +289,7 @@ impl Perform<SearchResponse> for Oper<Search> {
None,
Some(data.q.to_owned()),
None,
+ true,
false,
false,
data.page,
@@ -309,6 +312,7 @@ impl Perform<SearchResponse> for Oper<Search> {
&conn,
&sort,
None,
+ true,
Some(data.q.to_owned()),
data.page,
data.limit)?;
@@ -330,6 +334,7 @@ impl Perform<SearchResponse> for Oper<Search> {
None,
Some(data.q.to_owned()),
None,
+ true,
false,
false,
data.page,
@@ -348,6 +353,7 @@ impl Perform<SearchResponse> for Oper<Search> {
&conn,
&sort,
None,
+ true,
Some(data.q.to_owned()),
data.page,
data.limit)?;
diff --git a/server/src/api/user.rs b/server/src/api/user.rs
index 5d5f1a6b..2a6c214a 100644
--- a/server/src/api/user.rs
+++ b/server/src/api/user.rs
@@ -15,6 +15,13 @@ pub struct Register {
password: String,
password_verify: String,
admin: bool,
+ show_nsfw: bool,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct SaveUserSettings {
+ show_nsfw: bool,
+ auth: String,
}
#[derive(Serialize, Deserialize)]
@@ -151,6 +158,7 @@ impl Perform<LoginResponse> for Oper<Register> {
updated: None,
admin: data.admin,
banned: false,
+ show_nsfw: data.show_nsfw,
};
// Create the user
@@ -170,6 +178,7 @@ impl Perform<LoginResponse> for Oper<Register> {
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
category_id: 1,
+ nsfw: false,
creator_id: inserted_user.id,
removed: None,
deleted: None,
@@ -218,24 +227,77 @@ impl Perform<LoginResponse> for Oper<Register> {
}
}
+impl Perform<LoginResponse> for Oper<SaveUserSettings> {
+ fn perform(&self) -> Result<LoginResponse, Error> {
+ let data: &SaveUserSettings = &self.data;
+ let conn = establish_connection();
+
+ let claims = match Claims::decode(&data.auth) {
+ Ok(claims) => claims.claims,
+ Err(_e) => {
+ return Err(APIError::err(&self.op, "not_logged_in"))?
+ }
+ };
+
+ let user_id = claims.id;
+
+ let read_user = User_::read(&conn, user_id)?;
+
+ let user_form = UserForm {
+ name: read_user.name,
+ fedi_name: read_user.fedi_name,
+ email: read_user.email,
+ password_encrypted: read_user.password_encrypted,
+ preferred_username: read_user.preferred_username,
+ updated: Some(naive_now()),
+ admin: read_user.admin,
+ banned: read_user.banned,
+ show_nsfw: data.show_nsfw,
+ };
+
+ let updated_user = match User_::update(&conn, user_id, &user_form) {
+ Ok(user) => user,
+ Err(_e) => {
+ return Err(APIError::err(&self.op, "couldnt_update_user"))?
+ }
+ };
+
+ // Return the jwt
+ Ok(
+ LoginResponse {
+ op: self.op.to_string(),
+ jwt: updated_user.jwt()
+ }
+ )
+ }
+}
impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
fn perform(&self) -> Result<GetUserDetailsResponse, Error> {
let data: &GetUserDetails = &self.data;
let conn = establish_connection();
- let user_id: Option<i32> = match &data.auth {
+ let user_claims: Option<Claims> = 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
+ };
//TODO add save
let sort = SortType::from_str(&data.sort)?;
@@ -249,50 +311,56 @@ impl Perform<GetUserDetailsResponse> for Oper<GetUserDetails> {
// If its saved only, you don't care what creator it was
let posts = if data.saved_only {
- PostView::list(&conn,
- PostListingType::All,
- &sort,
- data.community_id,
- None,
- None,
- Some(user_details_id),
- data.saved_only,
- false,
- data.page,
- data.limit)?
+ PostView::list(
+ &conn,
+ PostListingType::All,
+ &sort,
+ data.community_id,
+ None,
+ None,
+ Some(user_details_id),
+ show_nsfw,
+ data.saved_only,
+ false,
+ data.page,
+ data.limit)?
} else {
- PostView::list(&conn,
- PostListingType::All,
- &sort,
- data.community_id,
- Some(user_details_id),
- None,
- user_id,
- data.saved_only,
- false,
- data.page,
- data.limit)?
+ PostView::list(
+ &conn,
+ PostListingType::All,
+ &sort,
+ data.community_id,
+ Some(user_details_id),
+ None,
+ user_id,
+ show_nsfw,
+ data.saved_only,
+ false,
+ data.page,
+ data.limit)?
};
let comments = if data.saved_only {
- CommentView::list(&conn,
- &sort,
- None,
- None,
- None,
- Some(user_details_id),
- data.saved_only,
- data.page,
- data.limit)?
+ CommentView::list(
+ &conn,
+ &sort,
+ None,
+ None,
+ None,
+ Some(user_details_id),
+ data.saved_only,
+ data.page,
+ data.limit)?
} else {
- CommentView::list(&conn,
- &sort,
- None,
- Some(user_details_id),
- None,
- user_id,
- data.saved_only,
- data.page,
- data.limit)?
+ CommentView::list(
+ &conn,
+ &sort,
+ None,
+ Some(user_details_id),
+ None,
+ user_id,
+ data.saved_only,
+ data.page,
+ data.limit)?
};
let follows = CommunityFollowerView::for_user(&conn, user_details_id)?;
@@ -343,6 +411,7 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
updated: Some(naive_now()),
admin: data.added,
banned: read_user.banned,
+ show_nsfw: read_user.show_nsfw,
};
match User_::update(&conn, data.user_id, &user_form) {
@@ -402,6 +471,7 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
updated: Some(naive_now()),
admin: read_user.admin,
banned: data.ban,
+ show_nsfw: read_user.show_nsfw,
};
match User_::update(&conn, data.user_id, &user_form) {
diff --git a/server/src/db/community.rs b/server/src/db/community.rs
index b32230b9..aa28c9c7 100644
--- a/server/src/db/community.rs
+++ b/server/src/db/community.rs
@@ -14,6 +14,7 @@ pub struct Community {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
@@ -27,6 +28,7 @@ pub struct CommunityForm {
pub removed: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
+ pub nsfw: bool,
}
impl Crud<CommunityForm> for Community {
@@ -240,6 +242,7 @@ mod tests {
title: "nada".to_owned(),
description: None,
category_id: 1,
+ nsfw: false,
removed: None,
deleted: None,
updated: None,
@@ -254,6 +257,7 @@ mod tests {
title: "nada".to_owned(),
description: None,
category_id: 1,
+ nsfw: false,
removed: false,
deleted: false,
published: inserted_community.published,
diff --git a/server/src/db/community_view.rs b/server/src/db/community_view.rs
index 6249090d..88ab10af 100644
--- a/server/src/db/community_view.rs
+++ b/server/src/db/community_view.rs
@@ -12,6 +12,7 @@ table! {
published -> Timestamp,
updated -> Nullable<Timestamp>,
deleted -> Bool,
+ nsfw -> Bool,
creator_name -> Varchar,
category_name -> Varchar,
number_of_subscribers -> BigInt,
@@ -84,6 +85,7 @@ pub struct CommunityView {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
pub creator_name: String,
pub category_name: String,
pub number_of_subscribers: i64,
@@ -112,13 +114,15 @@ impl CommunityView {
query.first::<Self>(conn)
}
- pub fn list(conn: &PgConnection,
- sort: &SortType,
- from_user_id: Option<i32>,
- search_term: Option<String>,
- page: Option<i64>,
- limit: Option<i64>,
- ) -> Result<Vec<Self>, Error> {
+ pub fn list(
+ conn: &PgConnection,
+ sort: &SortType,
+ from_user_id: Option<i32>,
+ show_nsfw: bool,
+ search_term: Option<String>,
+ page: Option<i64>,
+ limit: Option<i64>,
+ ) -> Result<Vec<Self>, Error> {
use super::community_view::community_view::dsl::*;
let mut query = community_view.into_boxed();
@@ -143,6 +147,10 @@ impl CommunityView {
_ => ()
};
+ if !show_nsfw {
+ query = query.filter(nsfw.eq(false));
+ };
+
query
.limit(limit)
.offset(offset)
diff --git a/server/src/db/post.rs b/server/src/db/post.rs
index d8fd27b0..6a8bf26d 100644
--- a/server/src/db/post.rs
+++ b/server/src/db/post.rs
@@ -15,6 +15,7 @@ pub struct Post {
pub published: chrono::NaiveDateTime,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
+ pub nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone)]
@@ -29,6 +30,7 @@ pub struct PostForm {
pub locked: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
+ pub nsfw: bool,
}
impl Crud<PostForm> for Post {
@@ -210,6 +212,7 @@ mod tests {
removed: None,
deleted: None,
locked: None,
+ nsfw: false,
updated: None
};
@@ -225,6 +228,7 @@ mod tests {
published: inserted_post.published,
removed: false,
locked: false,
+ nsfw: false,
deleted: false,
updated: None
};
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,
diff --git a/server/src/db/user.rs b/server/src/db/user.rs
index aed5e890..b794524c 100644
--- a/server/src/db/user.rs
+++ b/server/src/db/user.rs
@@ -18,7 +18,8 @@ pub struct User_ {
pub admin: bool,
pub banned: bool,
pub published: chrono::NaiveDateTime,
- pub updated: Option<chrono::NaiveDateTime>
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
}
#[derive(Insertable, AsChangeset, Clone)]
@@ -31,7 +32,8 @@ pub struct UserForm {
pub admin: bool,
pub banned: bool,
pub email: Option<String>,
- pub updated: Option<chrono::NaiveDateTime>
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub show_nsfw: bool,
}
impl Crud<UserForm> for User_ {
@@ -77,6 +79,7 @@ pub struct Claims {
pub id: i32,
pub username: String,
pub iss: String,
+ pub show_nsfw: bool,
}
impl Claims {
@@ -96,6 +99,7 @@ impl User_ {
id: self.id,
username: self.name.to_owned(),
iss: self.fedi_name.to_owned(),
+ show_nsfw: self.show_nsfw,
};
encode(&Header::default(), &my_claims, Settings::get().jwt_secret.as_ref()).unwrap()
}
@@ -133,7 +137,8 @@ mod tests {
email: None,
admin: false,
banned: false,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -149,7 +154,8 @@ mod tests {
admin: false,
banned: false,
published: inserted_user.published,
- updated: None
+ updated: None,
+ show_nsfw: false,
};
let read_user = User_::read(&conn, inserted_user.id).unwrap();
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 143be36e..04076771 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -1,3 +1,4 @@
+#![recursion_limit = "512"]
#[macro_use] pub extern crate strum_macros;
#[macro_use] pub extern crate lazy_static;
#[macro_use] pub extern crate failure;
diff --git a/server/src/schema.rs b/server/src/schema.rs
index 27bc3f94..635c8c46 100644
--- a/server/src/schema.rs
+++ b/server/src/schema.rs
@@ -52,6 +52,7 @@ table! {
published -> Timestamp,
updated -> Nullable<Timestamp>,
deleted -> Bool,
+ nsfw -> Bool,
}
}
@@ -185,6 +186,7 @@ table! {
published -> Timestamp,
updated -> Nullable<Timestamp>,
deleted -> Bool,
+ nsfw -> Bool,
}
}
@@ -240,6 +242,7 @@ table! {
banned -> Bool,
published -> Timestamp,
updated -> Nullable<Timestamp>,
+ show_nsfw -> Bool,
}
}
diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs
index 7088f3d5..64f94f4c 100644
--- a/server/src/websocket/server.rs
+++ b/server/src/websocket/server.rs
@@ -134,17 +134,19 @@ impl ChatServer {
use crate::db::*;
use crate::db::post_view::*;
let conn = establish_connection();
- let posts = PostView::list(&conn,
- PostListingType::Community,
- &SortType::New,
- Some(*community_id),
- None,
- None,
- None,
- false,
- false,
- None,
- Some(9999))?;
+ let posts = PostView::list(
+ &conn,
+ PostListingType::Community,
+ &SortType::New,
+ Some(*community_id),
+ None,
+ None,
+ None,
+ false,
+ false,
+ false,
+ None,
+ Some(9999))?;
for post in posts {
self.send_room_message(&post.id, message, skip_id);
}
@@ -303,6 +305,11 @@ fn parse_json_message(chat: &mut ChatServer, msg: StandardMessage) -> Result<Str
let res = Oper::new(user_operation, get_user_details).perform()?;
Ok(serde_json::to_string(&res)?)
},
+ UserOperation::SaveUserSettings => {
+ let save_user_settings: SaveUserSettings = serde_json::from_str(data)?;
+ let res = Oper::new(user_operation, save_user_settings).perform()?;
+ Ok(serde_json::to_string(&res)?)
+ },
UserOperation::AddAdmin => {
let add_admin: AddAdmin = serde_json::from_str(data)?;
let res = Oper::new(user_operation, add_admin).perform()?;