Module: Thredded::TopicCommon::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#unread(user) ⇒ ActiveRecord::Relation

Parameters:

Returns:

  • (ActiveRecord::Relation)


54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/concerns/thredded/topic_common.rb', line 54

def unread(user)
  topics = arel_table
  reads_class = reflect_on_association(:user_read_states).klass
  reads = reads_class.arel_table

  joins_reads =
    topics.outer_join(reads)
      .on(topics[:id].eq(reads[:postable_id]).and(reads[:user_id].eq(user.id))).join_sources

  unread_scope = reads_class.where(reads[:id].eq(nil).or(reads[:unread_posts_count].not_eq(0)))

  joins(joins_reads).merge(unread_scope)
end