Class: Discussion::Comment

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_read_by(comments, user) ⇒ Object

TODO: improve the performance for the ready by



15
16
17
18
19
# File 'app/models/discussion/comment.rb', line 15

def self.load_read_by(comments, user)
  #comment_ids = comments.collect(:id)
  #comment_ids
  #Discussion::CommentRead.where()
end

Instance Method Details

#read_by!(user) ⇒ Object



21
22
23
24
25
26
# File 'app/models/discussion/comment.rb', line 21

def read_by!(user)
  my_comment_reads = self.comment_reads.where(user_id: user.id, comment_id: self.id)
  comment_read = my_comment_reads.first || my_comment_reads.new
  comment_read.read_at ||= Time.zone.now
  comment_read.save!
end

#read_by?(user) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/discussion/comment.rb', line 28

def read_by?(user)
  @read_already ||= self.comment_reads.where('user_id = ? AND read_at IS NOT NULL', user.id).count > 0
end