From: Dessalines Date: Sun, 31 Jan 2021 15:29:21 +0000 (-0500) Subject: Post and comment vote views now return 0 instead of null. X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%24%7B%60data:application/static/%7B%60https:/README.ru.md?a=commitdiff_plain;h=d2ba2960dda81a985fe53f5cb99bf58ac3bf90c4;p=lemmy.git Post and comment vote views now return 0 instead of null. - Fixes #1389 --- diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 3ee3e938..111791d9 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 2f82f8fe..1d2526a0 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,