Class: Thredded::PrivatePost

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

Class Method Summary collapse

Instance Method Summary collapse

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::PrivatePost

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

Parameters:

  • id (String, Number)

Returns:

Raises:



28
29
30
# File 'app/models/thredded/private_post.rb', line 28

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

Instance Method Details

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

Parameters:

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


33
34
35
# File 'app/models/thredded/private_post.rb', line 33

def page(per_page: self.class.default_per_page)
  calculate_page(postable.posts, per_page)
end

#private_topic_post?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/thredded/private_post.rb', line 37

def private_topic_post?
  true
end

#readersActiveRecord::Relation<Thredded.user_class>

Returns users that can read this post.

Returns:



42
43
44
45
46
47
48
49
# File 'app/models/thredded/private_post.rb', line 42

def readers
  collection_proxy = postable.users
  if persisted?
    collection_proxy.scope
  else
    Thredded.user_class.where(id: collection_proxy.to_a.map(&:id))
  end
end