mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
Fix vote revertion logic
This commit is contained in:
parent
889120287d
commit
312c678665
1 changed files with 12 additions and 12 deletions
|
@ -208,16 +208,16 @@ def post_vote(post_id: int, vote_direction):
|
|||
post.score -= 2
|
||||
downvoted_class = 'voted_down'
|
||||
else: # previous vote was down
|
||||
if vote_direction == 'upvote': # new vote is upvote
|
||||
if vote_direction == 'downvote': # new vote is also down, so remove it
|
||||
db.session.delete(existing_vote)
|
||||
post.down_votes -= 1
|
||||
post.score += 1
|
||||
else: # new vote is up while previous vote was down, so reverse their previous vote
|
||||
existing_vote.effect = 1
|
||||
post.up_votes += 1
|
||||
post.down_votes -= 1
|
||||
post.score += 1
|
||||
upvoted_class = 'voted_up'
|
||||
else: # reverse a previous downvote
|
||||
db.session.delete(existing_vote)
|
||||
post.down_votes -= 1
|
||||
post.score += 2
|
||||
upvoted_class = 'voted_up'
|
||||
else:
|
||||
if vote_direction == 'upvote':
|
||||
effect = 1
|
||||
|
@ -303,16 +303,16 @@ def comment_vote(comment_id, vote_direction):
|
|||
comment.score -= 2
|
||||
downvoted_class = 'voted_down'
|
||||
else: # previous vote was down
|
||||
if vote_direction == 'upvote': # new vote is upvote
|
||||
if vote_direction == 'downvote': # new vote is also down, so remove it
|
||||
db.session.delete(existing_vote)
|
||||
comment.down_votes -= 1
|
||||
comment.score += 1
|
||||
else: # new vote is up while previous vote was down, so reverse their previous vote
|
||||
existing_vote.effect = 1
|
||||
comment.up_votes += 1
|
||||
comment.down_votes -= 1
|
||||
comment.score += 1
|
||||
upvoted_class = 'voted_up'
|
||||
else: # reverse a previous downvote
|
||||
db.session.delete(existing_vote)
|
||||
comment.down_votes -= 1
|
||||
comment.score += 2
|
||||
upvoted_class = 'voted_up'
|
||||
else:
|
||||
if vote_direction == 'upvote':
|
||||
effect = 1
|
||||
|
|
Loading…
Add table
Reference in a new issue