Merge branch 'master' of github.com:r888888888/danbooru

This commit is contained in:
albert
2013-04-05 14:40:24 -04:00

View File

@@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base class Comment < ActiveRecord::Base
validate :validate_creator_is_not_limited validate :validate_creator_is_not_limited, :on => :create
validates_format_of :body, :with => /\S/, :message => 'has no content' validates_format_of :body, :with => /\S/, :message => 'has no content'
belongs_to :post belongs_to :post
belongs_to :creator, :class_name => "User" belongs_to :creator, :class_name => "User"
@@ -101,16 +101,19 @@ class Comment < ActiveRecord::Base
end end
end end
def update_last_commented_at_on_destroy def update_last_commented_at_on_create
if Comment.where("post_id = ? and id <> ?", post_id, id).count == 0 if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post?
Post.update_all("last_commented_at = NULL", ["id = ?", post_id]) Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id])
end end
true true
end end
def update_last_commented_at_on_create def update_last_commented_at_on_destroy
if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post? other_comments = Comment.where("post_id = ? and id <> ?", post_id, id).order("id DESC")
Post.update_all(["last_commented_at = ?", created_at], ["id = ?", post_id]) if other_comments.count == 0
Post.update_all("last_commented_at = NULL", ["id = ?", post_id])
else
Post.update_all(["last_commented_at = ?", other_comments.first.created_at], ["id = ?", post_id])
end end
true true
end end