From d2ba2960dda81a985fe53f5cb99bf58ac3bf90c4 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 31 Jan 2021 10:29:21 -0500 Subject: [PATCH] Post and comment vote views now return 0 instead of null. - Fixes #1389 --- crates/db_views/src/comment_view.rs | 10 +++++++++- crates/db_views/src/post_view.rs | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 3ee3e9384..111791d93 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -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::(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, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 2f82f8fe0..1d2526a0f 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -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::(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,