lib/socialcastr/comment.rb in socialcastr-0.2.7 vs lib/socialcastr/comment.rb in socialcastr-0.2.8

- old
+ new

@@ -1,17 +1,16 @@ module Socialcastr class Comment < Base def like! - self.likes ||= [] - likes << Like.parse(api.post(element_path(:message_id => self.message_id) + "/likes")) + api.post(element_path(:message_id => message_id) + "/likes") + refresh return self end def unlike! - self.likes.reject! do |l| - l.unlikable_by?(self.user_id) && api.delete(element_path(:message_id => self.mesage_id) + "/likes/#{l.id}") - end + api.delete(element_path(:message_id => message_id) + "/likes/#{like_id}") + refresh return self end def unlikable_by?(api_id) self.likes.map{|l| l.unlikable_by?(api_id)}.any? @@ -19,10 +18,10 @@ def likable_by?(api_id) self.user_id != api_id end - def like_id(api_id) - self.likes.select { |like| like.unlikable_by?(api_id) }.first.id + def like_id + self.likes.select { |like| like.unlikable_by?(api.profile.id) }.first.id end end end