Method: Thredded::TopicCommon::ClassMethods#unread

Defined in:
app/models/concerns/thredded/topic_common.rb

#unread(user) ⇒ ActiveRecord::Relation

Parameters:

Returns:

  • (ActiveRecord::Relation)


50
51
52
53
54
55
56
57
# File 'app/models/concerns/thredded/topic_common.rb', line 50

def unread(user)
  topics      = arel_table
  reads_class = reflect_on_association(:user_read_states).klass
  reads       = reads_class.arel_table
  joins(topics.join(reads, Arel::Nodes::OuterJoin)
          .on(topics[:id].eq(reads[:postable_id]).and(reads[:user_id].eq(user.id))).join_sources)
    .merge(reads_class.where(reads[:id].eq(nil).or(reads[:read_at].lt(topics[:last_post_at]))))
end