Class: Thredded::Post

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ContentModerationState, PostCommon
Defined in:
app/models/thredded/post.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ContentModerationState

#moderation_state_visible_to_all?, #moderation_state_visible_to_user?

Methods included from PostCommon

#avatar_url, #calculate_page, #filtered_content, #first_post_in_topic?, #mark_as_unread, #previous_post

Class Method Details

.find!(id) ⇒ Thredded::Post

Finds the post by its ID, or raises Errors::PostNotFound.

Parameters:

  • id (String, Number)

Returns:

Raises:



48
49
50
# File 'app/models/thredded/post.rb', line 48

def self.find!(id)
  find_by(id: id) || fail(Thredded::Errors::PostNotFound)
end

Instance Method Details

#page(per_page: self.class.default_per_page, user:) ⇒ Object

Parameters:

  • per_page (Integer) (defaults to: self.class.default_per_page)
  • user (Thredded.user_class)


54
55
56
57
# File 'app/models/thredded/post.rb', line 54

def page(per_page: self.class.default_per_page, user:)
  readable_posts = PostPolicy::Scope.new(user, postable.posts).resolve
  calculate_page(readable_posts, per_page)
end

#private_topic_post?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/thredded/post.rb', line 59

def private_topic_post?
  false
end

#readersActiveRecord::Relation<Thredded.user_class>

Returns users that can read this post.

Returns:



64
65
66
# File 'app/models/thredded/post.rb', line 64

def readers
  Thredded.user_class.thredded_messageboards_readers([messageboard])
end