* Continued work on improving post view templates

* Added statistics-based estimator for related tag calculator
* Fleshed out IpBan class based on changes to Danbooru 1.xx
This commit is contained in:
albert
2010-04-29 17:32:15 -04:00
parent 3666364469
commit 23656e3fa9
39 changed files with 816 additions and 86 deletions

View File

@@ -1,4 +1,5 @@
class Comment < ActiveRecord::Base
class Comment < ActiveRecord::Base
validate :validate_creator_is_not_limited
validates_format_of :body, :with => /\S/, :message => 'has no content'
belongs_to :post
belongs_to :creator, :class_name => "User"
@@ -6,35 +7,24 @@ class Comment < ActiveRecord::Base
after_save :update_last_commented_at
after_destroy :update_last_commented_at
attr_accessible :body
attr_accessor :do_not_bump_post
scope :recent, :order => "comments.id desc", :limit => 6
scope :search_body, lambda {|query| where("body_index @@ plainto_tsquery(?)", query).order("comments.id DESC")}
scope :hidden, lambda {|user| where("score < ?", user.comment_threshold)}
def creator_name
User.find_name(creator_id)
end
def validate_creator_is_not_limited
creator.is_privileged? || Comment.where("creator_id = ? AND created_at >= ?", creator_id, 1.hour.ago).count < 5
end
def update_last_commented_at
return if do_not_bump_post
comment_count = Comment.where(["post_id = ?", post_id]).count
if comment_count <= Danbooru.config.comment_threshold
if Comment.where(["post_id = ?", post_id]).count <= Danbooru.config.comment_threshold
execute_sql("UPDATE posts SET last_commented_at = ? WHERE id = ?", created_at, post_id)
end
end
def can_be_voted_by?(user)
!votes.exists?(["user_id = ?", user.id])
end
def vote!(user, is_positive)
if can_be_voted_by?(user)
if is_positive
increment!(:score)
else
decrement!(:score)
end
votes.create(:user_id => user.id)
else
raise CommentVote::Error.new("You have already voted for this comment")
end
end
end
Comment.connection.extend(PostgresExtensions)