Sha256: aa825acd1dc0f976f961e64d121ca950f50e5478f6d763247a75c7385ebacee5
Contents?: true
Size: 1.02 KB
Versions: 10
Compression:
Stored size: 1.02 KB
Contents
module MyForum class Topic < ActiveRecord::Base has_many :posts, counter_cache: true, dependent: :destroy belongs_to :forum, counter_cache: true belongs_to :user default_scope { where(deleted: false) } def info author = (post = posts.first).user.login created = post.created_at { author: author, created: created } end def owner posts.first.user end 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 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 end end
Version data entries
10 entries across 10 versions & 1 rubygems