Module: Thredded::UserTopicReadStateCommon
- Extended by:
- ActiveSupport::Concern
- Included in:
- UserPrivateTopicReadState, UserTopicReadState
- Defined in:
- app/models/concerns/thredded/user_topic_read_state_common.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#calculate_post_counts ⇒ Object
29 30 31 32 33 34 |
# File 'app/models/concerns/thredded/user_topic_read_state_common.rb', line 29 def calculate_post_counts relation = self.class.visible_posts_scope(user).where(postable_id: postable_id) unread_posts_count, read_posts_count = relation.pluck(*self.class.post_counts_arel(read_at))[0] { unread_posts_count: unread_posts_count || 0, read_posts_count: read_posts_count || 0 } end |
#post_read?(post) ⇒ Boolean
20 21 22 |
# File 'app/models/concerns/thredded/user_topic_read_state_common.rb', line 20 def post_read?(post) post.created_at <= read_at end |
#posts_count ⇒ Number
25 26 27 |
# File 'app/models/concerns/thredded/user_topic_read_state_common.rb', line 25 def posts_count read_posts_count + unread_posts_count end |
#read? ⇒ Boolean
14 15 16 |
# File 'app/models/concerns/thredded/user_topic_read_state_common.rb', line 14 def read? postable.last_post_at <= read_at end |