Class: Thredded::TopicPostsPageView

Inherits:
Object
  • Object
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:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 25

def initialize(user, topic, paginated_scope)
  @posts_paginator = 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)



20
21
22
# File 'app/view_models/thredded/topic_posts_page_view.rb', line 20

def topic
  @topic
end