Commit 25eb96ad by Rocky Duan

delete invalid subscriptions & add id field for user to return

parent 77bfef7a
......@@ -55,6 +55,8 @@ class CommentThread < Content
before_create :set_last_activity_at
before_update :set_last_activity_at
before_destroy :destroy_subscriptions
scope :active_since, ->(from_time) { where(:last_activity_at => {:$gte => from_time}) }
def self.new_dumb_thread(options={})
......@@ -174,4 +176,8 @@ private
def set_last_activity_at
self.last_activity_at = Time.now.utc unless last_activity_at_changed?
end
def destroy_subscriptions
subscriptions.delete_all
end
end
......@@ -53,17 +53,14 @@ class User
subscribed_user_ids.map {|id| User.find(id)}
end
def to_hash(params={})
hash = as_document.slice(*%w[_id username external_id])
hash = as_document.slice(*%w[username external_id])
if params[:complete]
hash = hash.merge("subscribed_thread_ids" => subscribed_thread_ids,
"subscribed_commentable_ids" => subscribed_commentable_ids,
"subscribed_user_ids" => subscribed_user_ids,
"follower_ids" => subscriptions_as_source.map(&:subscriber_id),
"id" => id,
"upvoted_ids" => upvoted_ids,
"downvoted_ids" => downvoted_ids)
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment