Skip to content
Snippets Groups Projects
Commit 766d0afd authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

Add voting

parent 6e429592
Branches
Tags
No related merge requests found
...@@ -17,7 +17,8 @@ class Vote < ApplicationRecord ...@@ -17,7 +17,8 @@ class Vote < ApplicationRecord
def self.total_rep_change(col) def self.total_rep_change(col)
col = col.includes(:post) col = col.includes(:post)
settings = SiteSetting.where(name: ['QuestionUpVoteRep', 'QuestionDownVoteRep', settings = SiteSetting.where(name: ['QuestionUpVoteRep', 'QuestionDownVoteRep',
'AnswerUpVoteRep', 'AnswerDownVoteRep']) 'AnswerUpVoteRep', 'AnswerDownVoteRep',
'ArticleUpVoteRep', 'ArticleDownVoteRep'])
.map { |ss| [ss.name, ss.value] }.to_h .map { |ss| [ss.name, ss.value] }.to_h
rep_changes = PostType.mapping.map do |k, v| rep_changes = PostType.mapping.map do |k, v|
vote_types = { 1 => 'Up', -1 => 'Down' } vote_types = { 1 => 'Up', -1 => 'Down' }
...@@ -45,7 +46,9 @@ class Vote < ApplicationRecord ...@@ -45,7 +46,9 @@ class Vote < ApplicationRecord
[post_type_ids['Question'], 1] => 'QuestionUpVoteRep', [post_type_ids['Question'], 1] => 'QuestionUpVoteRep',
[post_type_ids['Question'], -1] => 'QuestionDownVoteRep', [post_type_ids['Question'], -1] => 'QuestionDownVoteRep',
[post_type_ids['Answer'], 1] => 'AnswerUpVoteRep', [post_type_ids['Answer'], 1] => 'AnswerUpVoteRep',
[post_type_ids['Answer'], -1] => 'AnswerDownVoteRep' [post_type_ids['Answer'], -1] => 'AnswerDownVoteRep',
[post_type_ids['Article'], 1] => 'ArticleUpVoteRep',
[post_type_ids['Article'], -1] => 'ArticleDownVoteRep'
} }
rep_change = SiteSetting[setting_names[[post.post_type_id, vote_type]]] || 0 rep_change = SiteSetting[setting_names[[post.post_type_id, vote_type]]] || 0
recv_user.update!(reputation: recv_user.reputation + direction * rep_change) recv_user.update!(reputation: recv_user.reputation + direction * rep_change)
......
...@@ -54,6 +54,20 @@ ...@@ -54,6 +54,20 @@
description: > description: >
The reputation change to the post's author when an answer is downvoted. The reputation change to the post's author when an answer is downvoted.
- name: ArticleUpVoteRep
value: 10
value_type: integer
category: ReputationAndVoting
description: >
The reputation change to the post's author when an article is upvoted.
- name: ArticleDownVoteRep
value: -2
value_type: integer
category: ReputationAndVoting
description: >
The reputation change to the post's author when an article is downvoted.
- name: AllowSelfVotes - name: AllowSelfVotes
value: false value: false
value_type: boolean value_type: boolean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment