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