diaspora/app/services/comment_service.rb
Benjamin Neff d94eae0d45 refactoring PostService
* move presenters back to controllers, this is view-logic
* use PostService in CommentService
* remove iframe route, this is not used anymore
* id/guid limit at 16 chars, hex(8) is 16 chars long
2016-03-07 05:52:54 +01:00

32 lines
566 B
Ruby

class CommentService
def initialize(user=nil)
@user = user
end
def create(post_id, text)
post = post_service.find(post_id)
user.comment!(post, text)
end
def destroy(comment_id)
comment = Comment.find(comment_id)
if user.owns?(comment) || user.owns?(comment.parent)
user.retract(comment)
true
else
false
end
end
def find_for_post(post_id)
post_service.find(post_id).comments.for_a_stream
end
private
attr_reader :user
def post_service
@post_service ||= PostService.new(user)
end
end