Sha256: 25d67a2363cc7ba0914f428b01c2fa79a8c9074b76061cbd8de661bc7f388130

Contents?: true

Size: 1.02 KB

Versions: 21

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Thredded
  # A view model for a page of PostViews of a Topic.
  class TopicPostsPageView < Thredded::PostsPageView
    # @return [Thredded::BaseTopicView]
    attr_reader :topic

    # @param user [Thredded.user_class] the user who is viewing the posts page
    # @param topic [Thredded::TopicCommon]
    # @param paginated_scope [ActiveRecord::Relation<Thredded::PostCommon>]
    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
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
thredded-0.16.16 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.15 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.14 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.13 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.12 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.11 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.10 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.9 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.8 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.7 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.6 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.5 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.4 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.3 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.1 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.16.0 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.15.5 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.15.4 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.15.3 app/view_models/thredded/topic_posts_page_view.rb
thredded-0.15.2 app/view_models/thredded/topic_posts_page_view.rb