Class: MongoidForums::Topic

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

Class Method Summary collapse

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

Class Method Details

.by_most_recent_postObject



50
51
52
# File 'app/models/mongoid_forums/topic.rb', line 50

def by_most_recent_post
  order_by([:last_post_at, :desc])
end

.by_pinned_or_most_recent_postObject



54
55
56
# File 'app/models/mongoid_forums/topic.rb', line 54

def by_pinned_or_most_recent_post
  order_by([:pinned, :desc], [:last_post_at, :desc])
end

Instance Method Details

#can_be_replied_to?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/mongoid_forums/topic.rb', line 28

def can_be_replied_to?
  !locked?
end

#emojified_nameObject



24
25
26
# File 'app/models/mongoid_forums/topic.rb', line 24

def emojified_name
  ApplicationController.helpers.emojify(name)
end

#toggle!(field) ⇒ Object



32
33
34
35
# File 'app/models/mongoid_forums/topic.rb', line 32

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

#unread_post_count(user) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/mongoid_forums/topic.rb', line 37

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