Class: Thredded::PrivateTopic

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Includes:
TopicCommon
Defined in:
app/models/thredded/private_topic.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TopicCommon

#last_user, #private?, #user

Class Method Details

.friendly_find!(slug_or_id) ⇒ Thredded::PrivateTopic

Finds the topic by its slug or ID, or raises Thredded::Errors::PrivateTopicNotFound.

Parameters:

  • slug_or_id (String)

Returns:

Raises:



77
78
79
80
81
# File 'app/models/thredded/private_topic.rb', line 77

def self.friendly_find!(slug_or_id)
  friendly.find(slug_or_id)
rescue ActiveRecord::RecordNotFound
  raise Thredded::Errors::PrivateTopicNotFound
end

.post_classObject



111
112
113
# File 'app/models/thredded/private_topic.rb', line 111

def post_class
  Thredded::PrivatePost
end

.with_read_states(user) ⇒ Array<[PrivateTopic, PrivateUserTopicReadState]>

Parameters:

Returns:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/models/thredded/private_topic.rb', line 117

def with_read_states(user)
  if user.thredded_anonymous?
    current_scope.map do |topic|
      [topic, Thredded::NullUserTopicReadState.new(posts_count: topic.posts_count)]
    end
  else
    read_states_by_postable = read_states_by_postable_hash(user)
    current_scope.map do |topic|
      [
        topic,
        read_states_by_postable[topic] || Thredded::NullUserTopicReadState.new(posts_count: topic.posts_count)
      ]
    end
  end
end

Instance Method Details

#normalize_friendly_id(input) ⇒ Object



91
92
93
# File 'app/models/thredded/private_topic.rb', line 91

def normalize_friendly_id(input)
  Thredded.slugifier.call(input.to_s)
end

#public?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/thredded/private_topic.rb', line 83

def public?
  false
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/thredded/private_topic.rb', line 87

def should_generate_new_friendly_id?
  title_changed?
end