Class: MyForum::Topic
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MyForum::Topic
- Defined in:
- app/models/my_forum/topic.rb
Instance Method Summary collapse
- #info ⇒ Object
- #mark_as_read(current_user, last_post) ⇒ Object
- #owner ⇒ Object
- #unread?(current_user, last_post) ⇒ Boolean
Instance Method Details
#info ⇒ Object
9 10 11 12 13 14 |
# File 'app/models/my_forum/topic.rb', line 9 def info = (post = posts.first).user.login created = post.created_at { author: , created: created } end |
#mark_as_read(current_user, last_post) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/models/my_forum/topic.rb', line 30 def mark_as_read(current_user, last_post) return true unless current_user log = LogReadMark.find_or_create_by(user_id: current_user.id, topic_id: self.id) if last_post.id.to_i > log.post_id.to_i log.post_id = last_post.id log.save end end |
#owner ⇒ Object
16 17 18 |
# File 'app/models/my_forum/topic.rb', line 16 def owner posts.first.user end |
#unread?(current_user, last_post) ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'app/models/my_forum/topic.rb', line 20 def unread?(current_user, last_post) return false unless current_user return false if current_user.created_at > last_post.created_at logged_post = LogReadMark.where(user_id: current_user.id, topic_id: self.id).first return true unless logged_post last_post.id > logged_post.post_id end |