Sha256: 0dcfdff0d2a452cd8a65f27c05a37596720e1ad49e02fa504de1b378743f2d3f

Contents?: true

Size: 947 Bytes

Versions: 39

Compression:

Stored size: 947 Bytes

Contents

# frozen_string_literal: true

module Thredded
  # A view model for a page of BaseTopicViews.
  class PrivateTopicsPageView
    delegate :to_a,
             :to_ary,
             :blank?,
             :empty?,
             to: :@topic_views
    delegate :total_pages,
             :current_page,
             :limit_value,
             to: :@topics_page_scope

    # @param user [Thredded.user_class] the user who is viewing the posts page
    # @param topics_page_scope [ActiveRecord::Relation<Thredded::Topic>]
    def initialize(user, topics_page_scope)
      @topics_page_scope = refine_scope(topics_page_scope)
      @topic_views = @topics_page_scope.with_read_states(user).map do |(topic, read_state)|
        Thredded::PrivateTopicView.new(topic, read_state, Pundit.policy!(user, topic))
      end
    end

    protected

    def refine_scope(topics_page_scope)
      topics_page_scope.includes(:user, :last_user, :users)
    end
  end
end

Version data entries

39 entries across 39 versions & 2 rubygems

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