Class: Thredded::TopicPostsPageView

Inherits:
PostsPageView show all
Defined in:
app/view_models/thredded/topic_posts_page_view.rb

Overview

A view model for a page of PostViews of a Topic.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, topic, paginated_scope) ⇒ TopicPostsPageView

Returns a new instance of TopicPostsPageView.

Parameters:


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 12

def initialize(user, topic, paginated_scope)
  @paginated_scope = paginated_scope
  @topic = "#{paginated_scope.reflect_on_association(:postable).klass}View".constantize.from_user(topic, user)
  prev_read = false
  @post_views = paginated_scope.map.with_index do |post, i|
    post_read = @topic.post_read?(post)
    post_view = Thredded::PostView.new(
      post, Pundit.policy!(user, post),
      topic_view: @topic,
      first_in_page: i.zero?,
      first_unread_in_page: !post_read && prev_read
    )
    prev_read = post_read
    post_view
  end
end

Instance Attribute Details

#topicThredded::BaseTopicView (readonly)


7
8
9
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 7

def topic
  @topic
end