This commit is contained in:
r888888888
2014-08-07 17:43:28 -07:00
parent 424eb40c9d
commit 2b96040a30
12 changed files with 210 additions and 1 deletions

View File

@@ -11,6 +11,7 @@ class ForumTopic < ActiveRecord::Base
belongs_to :updater, :class_name => "User"
has_many :posts, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id", :dependent => :destroy
has_one :original_post, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id"
has_many :subscriptions, :class_name => "ForumSubscription"
before_validation :initialize_creator, :on => :create
before_validation :initialize_updater
before_validation :initialize_is_deleted, :on => :create
@@ -99,6 +100,24 @@ class ForumTopic < ActiveRecord::Base
end
end
module SubscriptionMethods
def update_subscription!(user)
user_subscription = subscriptions.where(:user_id => user.id).first
if user_subscription
user_subscription.update_attribute(:last_read_at, updated_at)
else
subscriptions.create(:user_id => user.id, :last_read_at => updated_at, :delete_key => SecureRandom.urlsafe_base64(10))
end
end
def notify_subscriptions!
ForumSubscription.where(:forum_topic_id => id).where("last_read_at < ?", updated_at).find_each do |subscription|
end
end
end
extend SearchMethods
include CategoryMethods
include VisitMethods