app/models/inkwell/comment.rb in inkwell-0.0.3 vs app/models/inkwell/comment.rb in inkwell-0.1.1
- old
+ new
@@ -15,11 +15,16 @@
before_destroy :destroy_comment_processing
belongs_to ::Inkwell::Engine::config.user_table.to_s.singularize
belongs_to ::Inkwell::Engine::config.post_table.to_s.singularize
- def commentline(last_shown_comment_id = nil, limit = 10, for_user = nil)
+ def commentline(options = {})
+ options.symbolize_keys!
+ last_shown_comment_id = options[:last_shown_comment_id]
+ limit = options[:limit] || 10
+ for_user = options[:for_user]
+
if for_user
user_class = Object.const_get ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize
raise "for_user param should be a #{user_class.to_s} but it is #{for_user.class.to_s}" unless for_user.class == user_class
end
users_ids_who_comment_it = ActiveSupport::JSON.decode self.users_ids_who_comment_it
@@ -30,15 +35,30 @@
result_comments_info = users_ids_who_comment_it.last(limit)
result = []
result_comments_info.each do |comment_info|
comment = ::Inkwell::Comment.find comment_info["comment_id"]
if for_user
- comment.is_reblogged = (for_user.reblog? comment) ? true : false
- comment.is_favorited = (for_user.favorite? comment) ? true : false
+ comment.is_reblogged = for_user.reblog? comment
+ comment.is_favorited = for_user.favorite? comment
end
result << comment
end
result
+ end
+
+ def comment_count
+ users_ids_who_comment_it = ActiveSupport::JSON.decode self.users_ids_who_comment_it
+ users_ids_who_comment_it.size
+ end
+
+ def favorite_count
+ users_ids_who_favorite_it = ActiveSupport::JSON.decode self.users_ids_who_favorite_it
+ users_ids_who_favorite_it.size
+ end
+
+ def reblog_count
+ users_ids_who_reblog_it = ActiveSupport::JSON.decode self.users_ids_who_reblog_it
+ users_ids_who_reblog_it.size
end
protected
def remove_info_from_upper_comments(comments_info)