blob: 6a290337eb4c02a061879a71bc000b40996c662c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# frozen_string_literal: true
class CommentPresenter < BasePresenter
def as_json(opts={})
{
id: id,
guid: guid,
text: message.plain_text_for_json,
author: author.as_api_response(:backbone),
created_at: created_at,
mentioned_people: mentioned_people.as_api_response(:backbone)
}
end
def as_api_response
{
guid: guid,
body: message.plain_text_for_json,
author: PersonPresenter.new(author).as_api_json,
created_at: created_at,
mentioned_people: build_mentioned_people_json,
reported: current_user.present? && reports.where(user: current_user).exists?
}
end
def build_mentioned_people_json
mentioned_people.map {|m| PersonPresenter.new(m).as_api_json }
end
end
|