Class: PostPresenter

Inherits:
Object
  • Object
show all
Includes:
PostsHelper
Defined in:
app/presenters/post_presenter.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from PostsHelper

#post_iframe_url, #post_page_title

Constructor Details

- (PostPresenter) initialize(post, current_user = nil)



6
7
8
9
# File 'app/presenters/post_presenter.rb', line 6

def initialize(post, current_user = nil)
  @post = post
  @current_user = current_user
end

Instance Attribute Details

- (Object) current_user

Returns the value of attribute current_user



4
5
6
# File 'app/presenters/post_presenter.rb', line 4

def current_user
  @current_user
end

- (Object) post

Returns the value of attribute post



4
5
6
# File 'app/presenters/post_presenter.rb', line 4

def post
  @post
end

Class Method Details

+ (Object) collection_json(collection, current_user)



11
12
13
# File 'app/presenters/post_presenter.rb', line 11

def self.collection_json(collection, current_user)
  collection.map {|post| PostPresenter.new(post, current_user)}
end

Instance Method Details

- (Object) as_json(options = {})



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
# File 'app/presenters/post_presenter.rb', line 15

def as_json(options={})
  {
      :id => @post.id,
      :guid => @post.guid,
      :text => @post.raw_message,
      :public => @post.public,
      :created_at => @post.created_at,
      :interacted_at => @post.interacted_at,
      :provider_display_name => @post.provider_display_name,
      :post_type => @post.post_type,
      :image_url => @post.image_url,
      :object_url => @post.object_url,
      :favorite => @post.favorite,
      :nsfw => @post.nsfw,
      :author => @post.author.as_api_response(:backbone),
      :o_embed_cache => @post.o_embed_cache.try(:as_api_response, :backbone),
      :open_graph_cache => @post.open_graph_cache.try(:as_api_response, :backbone),
      :mentioned_people => @post.mentioned_people.as_api_response(:backbone),
      :photos => @post.photos.map {|p| p.as_api_response(:backbone)},
      :root => root,
      :title => title,
      :address => @post.address,
      :poll => @post.poll(),
      :already_participated_in_poll => already_participated_in_poll,

      :interactions => {
          :likes => [user_like].compact,
          :reshares => [user_reshare].compact,
          :comments_count => @post.comments_count,
          :likes_count => @post.likes_count,
          :reshares_count => @post.reshares_count,
      }
  }
end

- (Object) root



54
55
56
# File 'app/presenters/post_presenter.rb', line 54

def root
  PostPresenter.new(@post.absolute_root, current_user).as_json if @post.respond_to?(:absolute_root) && @post.absolute_root.present?
end

- (Object) title



50
51
52
# File 'app/presenters/post_presenter.rb', line 50

def title
  @post.message.present? ? @post.message.title : I18n.t('posts.presenter.title', name: @post.author_name)
end

- (Object) user_like



58
59
60
# File 'app/presenters/post_presenter.rb', line 58

def user_like
  @post.like_for(@current_user).try(:as_api_response, :backbone)
end

- (Object) user_reshare



62
63
64
# File 'app/presenters/post_presenter.rb', line 62

def user_reshare
  @post.reshare_for(@current_user)
end