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

profile_presenter.rb « presenters « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 739089abcd19a47e9abcec1392632b8f6f124a1e (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# frozen_string_literal: true

class ProfilePresenter < BasePresenter
  include PeopleHelper

  def base_hash
    {
      id:         id,
      searchable: searchable
    }
  end

  def public_hash
    base_hash.merge(
      avatar: AvatarPresenter.new(@presentable).base_hash(true),
      tags:   tags.pluck(:name)
    )
  end

  def for_hovercard
    {
      avatar: AvatarPresenter.new(@presentable).medium,
      tags:   tags.pluck(:name)
    }
  end

  def as_self_api_json
    base_api_json.merge(added_details_api_json).merge(
      searchable:        searchable,
      show_profile_info: public_details,
      nsfw:              nsfw
    )
  end

  def as_other_api_json(all_details)
    return base_api_json unless all_details

    base_api_json.merge(added_details_api_json)
  end

  def private_hash
    public_hash.merge(
      bio:      bio_message.plain_text_for_json,
      birthday: formatted_birthday,
      gender:   gender,
      location: location_message.plain_text_for_json
    )
  end

  def formatted_birthday
    birthday_format(birthday) if birthday
  end

  private

  def base_api_json
    {
      name:        [first_name, last_name].compact.join(" ").presence,
      diaspora_id: diaspora_handle,
      avatar:      AvatarPresenter.new(@presentable).base_hash,
      tags:        tags.pluck(:name)
    }.compact
  end

  def added_details_api_json
    {
      birthday: birthday.try(:iso8601),
      gender:   gender,
      location: location_message.plain_text_for_json,
      bio:      bio_message.plain_text_for_json
    }
  end
end