Sha256: 73a788cf7fe54eb8ae72a14e04a0851241799dd61419217d4c22bce5bacc6486

Contents?: true

Size: 1.09 KB

Versions: 18

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

module Thredded
  # A view model for TopicCommon.
  class BaseTopicView
    delegate :title,
             :last_post_at,
             :created_at,
             :user,
             :last_user,
             :to_model,
             to: :@topic

    delegate :read?, :post_read?, :posts_count,
             to: :@read_state

    # @param [TopicCommon] topic
    # @param [UserTopicReadStateCommon, NullUserTopicReadState, nil] read_state
    # @param [#destroy?] policy
    def initialize(topic, read_state, policy)
      @topic = topic
      @read_state = read_state || Thredded::NullUserTopicReadState.new(posts_count: @topic.posts_count)
      @policy = policy
    end

    def states
      [@read_state.read? ? :read : :unread]
    end

    def can_update?
      @policy.update?
    end

    def can_destroy?
      @policy.destroy?
    end

    def path
      Thredded::UrlsHelper.topic_path(
        @topic,
        page: @read_state.first_unread_post_page || @read_state.last_read_post_page,
        anchor: ('unread' if @read_state.first_unread_post_page)
      )
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
thredded-1.1.0 app/view_models/thredded/base_topic_view.rb
thredded-1.0.1 app/view_models/thredded/base_topic_view.rb
thredded-1.0.0 app/view_models/thredded/base_topic_view.rb
thredded-0.16.16 app/view_models/thredded/base_topic_view.rb
thredded-0.16.15 app/view_models/thredded/base_topic_view.rb
thredded-0.16.14 app/view_models/thredded/base_topic_view.rb
thredded-0.16.13 app/view_models/thredded/base_topic_view.rb
thredded-0.16.12 app/view_models/thredded/base_topic_view.rb
thredded-0.16.11 app/view_models/thredded/base_topic_view.rb
thredded-0.16.10 app/view_models/thredded/base_topic_view.rb
thredded-0.16.9 app/view_models/thredded/base_topic_view.rb
thredded-0.16.8 app/view_models/thredded/base_topic_view.rb
thredded-0.16.7 app/view_models/thredded/base_topic_view.rb
thredded-0.16.6 app/view_models/thredded/base_topic_view.rb
thredded-0.16.5 app/view_models/thredded/base_topic_view.rb
thredded-0.16.4 app/view_models/thredded/base_topic_view.rb
thredded-0.16.3 app/view_models/thredded/base_topic_view.rb
thredded-0.16.1 app/view_models/thredded/base_topic_view.rb