]> Untitled Git - lemmy.git/commitdiff
Post and comment vote views now return 0 instead of null.
authorDessalines <tyhou13@gmx.com>
Sun, 31 Jan 2021 15:29:21 +0000 (10:29 -0500)
committerDessalines <tyhou13@gmx.com>
Sun, 31 Jan 2021 15:29:21 +0000 (10:29 -0500)
- Fixes #1389

crates/db_views/src/comment_view.rs
crates/db_views/src/post_view.rs

index 3ee3e938417180f23f4e60555092a5deef9e6da7..111791d93b4a0d896bd52ef235f2df5cae15efdb 100644 (file)
@@ -81,7 +81,7 @@ impl CommentView {
       creator_banned_from_community,
       subscribed,
       saved,
-      my_vote,
+      comment_like,
     ) = comment::table
       .find(comment_id)
       .inner_join(user_::table)
@@ -134,6 +134,14 @@ impl CommentView {
       ))
       .first::<CommentViewTuple>(conn)?;
 
+    // If a user is given, then my_vote, if None, should be 0, not null
+    // Necessary to differentiate between other user's votes
+    let my_vote = if my_user_id.is_some() && comment_like.is_none() {
+      Some(0)
+    } else {
+      comment_like
+    };
+
     Ok(CommentView {
       comment,
       recipient,
index 2f82f8fe04fac9642ca8d8f63af3076aa46f19a4..1d2526a0f29bc17f0bbe650452796543813d24de 100644 (file)
@@ -70,7 +70,7 @@ impl PostView {
       follower,
       saved,
       read,
-      my_vote,
+      post_like,
     ) = post::table
       .find(post_id)
       .inner_join(user_::table)
@@ -124,6 +124,14 @@ impl PostView {
       ))
       .first::<PostViewTuple>(conn)?;
 
+    // If a user is given, then my_vote, if None, should be 0, not null
+    // Necessary to differentiate between other user's votes
+    let my_vote = if my_user_id.is_some() && post_like.is_none() {
+      Some(0)
+    } else {
+      post_like
+    };
+
     Ok(PostView {
       post,
       creator,