Merge pull request #1401 from LemmyNet/non_null_post_view_vote

Post and comment vote views now return 0 instead of null.
This commit is contained in:
Dessalines 2021-02-01 10:43:34 -05:00 committed by GitHub
commit f4d33389a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View 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,

View 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,