Class: MongoidForums::Topic

Inherits:
Object
  • Object
show all
Includes:
Enableable, ManualSlug, Mongoid::Document, Mongoid::Timestamps, Concerns::Subscribable, Concerns::Viewable
Defined in:
app/models/mongoid_forums/topic.rb

Instance Method Summary collapse

Methods included from Concerns::Viewable

#register_view_by, #view_for

Methods included from Concerns::Subscribable

#alert_subscribers, #subscribe_creator, #subscribe_user, #subscriber?, #subscription_for, #unsubscribe_user

Instance Method Details

#can_be_replied_to?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/mongoid_forums/topic.rb', line 42

def can_be_replied_to?
  !locked?
end

#toggle!(field) ⇒ Object



46
47
48
49
# File 'app/models/mongoid_forums/topic.rb', line 46

def toggle!(field)
  send "#{field}=", !self.send("#{field}?")
  save :validation => false
end

#unread_post_count(user) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/mongoid_forums/topic.rb', line 51

def unread_post_count(user)
  view = View.where(:viewable_id => id, :user_id => user.id).first
  return posts.count unless view.present?
  count = 0
  posts.each do |post|
    if post.created_at > view.current_viewed_at
      count+=1
    end
  end
  return count
end