From b1490ef51a99004c72247157ae6501ffa3e4e99d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 15 May 2019 09:46:39 -0700 Subject: [PATCH] Enforce -1 or 1 like scores --- server/src/api/comment.rs | 3 ++- server/src/api/post.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/api/comment.rs b/server/src/api/comment.rs index 65516aca..ffd7da2e 100644 --- a/server/src/api/comment.rs +++ b/server/src/api/comment.rs @@ -294,7 +294,8 @@ impl Perform for Oper { CommentLike::remove(&conn, &like_form)?; // Only add the like if the score isnt 0 - if &like_form.score != &0 { + let do_add = &like_form.score != &0 && (&like_form.score == &1 || &like_form.score == &-1); + if do_add { let _inserted_like = match CommentLike::like(&conn, &like_form) { Ok(like) => like, Err(_e) => { diff --git a/server/src/api/post.rs b/server/src/api/post.rs index 39df9546..a6010781 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -297,7 +297,8 @@ impl Perform for Oper { PostLike::remove(&conn, &like_form)?; // Only add the like if the score isnt 0 - if &like_form.score != &0 { + let do_add = &like_form.score != &0 && (&like_form.score == &1 || &like_form.score == &-1); + if do_add { let _inserted_like = match PostLike::like(&conn, &like_form) { Ok(like) => like, Err(_e) => { -- 2.44.1