diff --git a/app/models/comment.rb b/app/models/comment.rb index 776368b..6844118 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -22,6 +22,8 @@ class Comment < ActiveRecord::Base :log_to_countinual after_destroy :unassign_votes + scope :active, -> { where(:is_deleted => false, :is_moderated => false) } + DOWNVOTABLE_DAYS = 7 # after this many minutes old, a comment cannot be edited @@ -209,6 +211,7 @@ class Comment < ActiveRecord::Base Comment.record_timestamps = true self.story.update_comments_count! + self.user.update_comments_posted_count! end def deliver_mention_notifications @@ -456,5 +459,6 @@ class Comment < ActiveRecord::Base Comment.record_timestamps = true self.story.update_comments_count! + self.user.update_comments_posted_count! end end diff --git a/app/models/user.rb b/app/models/user.rb index 60878b3..366db85 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -219,6 +219,10 @@ class User < ActiveRecord::Base Keystore.value_for("user:#{self.id}:comments_posted").to_i end + def update_comments_posted_count! + Keystore.put("user:#{self.id}:comments_posted", self.comments.active.count) + end + def delete! User.transaction do self.comments.each{|c| c.delete_for_user(self) }