Module: Thredded::TopicCommon::ClassMethods
- Defined in:
- app/models/concerns/thredded/topic_common.rb
Instance Method Summary collapse
- #unread(user) ⇒ ActiveRecord::Relation
- #with_read_states(user) ⇒ Array<[TopicCommon, UserTopicReadStateCommon]>
Instance Method Details
#unread(user) ⇒ 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 |
#with_read_states(user) ⇒ Array<[TopicCommon, UserTopicReadStateCommon]>
73 74 75 76 77 78 79 80 |
# File 'app/models/concerns/thredded/topic_common.rb', line 73 def with_read_states(user) null_read_state = Thredded::NullUserTopicReadState.new return current_scope.zip([null_read_state]) if user.thredded_anonymous? read_states_by_postable = read_states_by_postable_hash(user) current_scope.map do |postable| [postable, read_states_by_postable[postable] || null_read_state] end end |