Class: Discussion::Thread

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/discussion/thread.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.total_unread_by(user) ⇒ Object



48
49
50
51
52
# File 'app/models/discussion/thread.rb', line 48

def self.total_unread_by(user)
  Rails.cache.fetch("total_unread_thread_by_#{user.id}", expires_in: 10.minutes) do
    Thread.unread_by(user).count
  end
end

Instance Method Details

#number_of_read_comments_by(user) ⇒ Object



54
55
56
57
58
# File 'app/models/discussion/thread.rb', line 54

def number_of_read_comments_by(user)
  @number_of_unread_comments ||= {}
  @number_of_unread_comments[user.id] ||= self.comments.
      joins(:comment_reads).where('discussion_comment_reads.user_id = ? AND discussion_comment_reads.read_at IS NOT NULL', user.id).count
end

#number_of_unread_comments_by(user) ⇒ Object



60
61
62
# File 'app/models/discussion/thread.rb', line 60

def number_of_unread_comments_by(user)
  self.total_comments_post - number_of_read_comments_by(user)
end

#read_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/discussion/thread.rb', line 44

def read_by?(user)
  self.thread_reads.by(user).where(read: false).count == 0
end