Welcome to mirror list, hosted at ThFree Co, Russian Federation.

notification_presenter.rb « presenters « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10b5c6a3b26599265df52d73b8a3ee4fae968380 (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
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

class NotificationPresenter < BasePresenter
  def as_api_json
    data = base_hash
    data = data.merge(target: target_json) if target
    data
  end

  private

  def base_hash
    {
      guid:           guid,
      type:           type_as_json,
      read:           !unread,
      created_at:     created_at,
      event_creators: creators_json
    }
  end

  def target_json
    json = {guid: target.guid}
    json[:author] = PersonPresenter.new(target.author).as_api_json if target.author
    json
  end

  def creators_json
    actors.map {|actor| PersonPresenter.new(actor).as_api_json }
  end

  def type_as_json
    NotificationService::NOTIFICATIONS_REVERSE_JSON_TYPES[type]
  end

  def target
    return linked_object if linked_object&.is_a?(Post)
    return linked_object.post if linked_object&.respond_to?(:post)
  end
end