Add upvote:/downvote: editing metatags.

This commit is contained in:
evazion
2016-10-22 02:28:35 -05:00
parent 8b5aac7808
commit 8672604ee7
3 changed files with 67 additions and 7 deletions

View File

@@ -680,7 +680,7 @@ class Post < ActiveRecord::Base
def filter_metatags(tags)
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|source|-?locked):/i}
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-favgroup|favgroup):/i}
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-favgroup|favgroup|upvote|downvote):/i}
apply_pre_metatags
return tags
end
@@ -719,6 +719,9 @@ class Post < ActiveRecord::Base
when /^-fav:(.+)$/i
remove_favorite!(CurrentUser.user)
when /^(up|down)vote:(.+)$/i
vote!($1)
when /^child:(.+)$/i
child = Post.find($1)
child.parent_id = id
@@ -1030,12 +1033,16 @@ class Post < ActiveRecord::Base
end
def vote!(score)
if can_be_voted_by?(CurrentUser.user)
vote = PostVote.create(:post_id => id, :score => score)
self.score += vote.score
else
unless CurrentUser.is_voter?
raise PostVote::Error.new("You do not have permission to vote")
end
unless can_be_voted_by?(CurrentUser.user)
raise PostVote::Error.new("You have already voted for this post")
end
PostVote.create(:post_id => id, :score => score)
reload # PostVote.create modifies our score. Reload to get the new score.
end
def unvote!