summaryrefslogtreecommitdiffstats
path: root/server/src/api/post.rs
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-04-27 22:46:09 -0400
committerDessalines <tyhou13@gmx.com>2020-04-27 22:47:26 -0400
commit9721b773179ad05714bff6f5ea5f87f3841723dc (patch)
tree7a60d648f8afd5d1a648b3678b10bdd874e59862 /server/src/api/post.rs
parent70060c27b2f40ef2de0c0ea37d3d69e202ab8c02 (diff)
1/3rd done with post likes
Diffstat (limited to 'server/src/api/post.rs')
-rw-r--r--server/src/api/post.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/server/src/api/post.rs b/server/src/api/post.rs
index 5be227d8..306365fa 100644
--- a/server/src/api/post.rs
+++ b/server/src/api/post.rs
@@ -169,12 +169,13 @@ impl Perform for Oper<CreatePost> {
score: 1,
};
- // Only add the like if the score isnt 0
let _inserted_like = match PostLike::like(&conn, &like_form) {
Ok(like) => like,
Err(_e) => return Err(APIError::err("couldnt_like_post").into()),
};
+ updated_post.send_like(&user, &conn)?;
+
// Refetch the view
let post_view = match PostView::read(&conn, inserted_post.id, Some(user_id)) {
Ok(post) => post,
@@ -368,7 +369,8 @@ impl Perform for Oper<CreatePostLike> {
}
// Check for a site ban
- if UserView::read(&conn, user_id)?.banned {
+ let user = User_::read(&conn, user_id)?;
+ if user.banned {
return Err(APIError::err("site_ban").into());
}
@@ -388,6 +390,14 @@ impl Perform for Oper<CreatePostLike> {
Ok(like) => like,
Err(_e) => return Err(APIError::err("couldnt_like_post").into()),
};
+
+ if like_form.score == 1 {
+ post.send_like(&user, &conn)?;
+ } else if like_form.score == -1 {
+ post.send_dislike(&user, &conn)?;
+ }
+ } else {
+ // TODO tombstone the post like
}
let post_view = match PostView::read(&conn, data.post_id, Some(user_id)) {