app/models/thredded/private_post.rb in thredded-0.6.1 vs app/models/thredded/private_post.rb in thredded-0.6.2
- old
+ new
@@ -13,10 +13,11 @@
belongs_to :user_detail,
inverse_of: :private_posts,
primary_key: :user_id,
foreign_key: :user_id
+ after_commit :update_parent_last_user_and_timestamp, on: [:create, :destroy]
after_commit :notify_users, on: [:create]
# @param [Integer] per_page
def page(per_page: self.class.default_per_page)
1 + postable.posts.where(postable.posts.arel_table[:id].lt(id)).count / per_page
@@ -35,10 +36,22 @@
DbTextSearch::CaseInsensitive
.new(postable.users, Thredded.user_name_column)
.in(user_names)
end
+ private
+
def notify_users
Thredded::NotifyPrivateTopicUsersJob.perform_later(id)
+ end
+
+ def update_parent_last_user_and_timestamp
+ return if postable.destroyed?
+ last_post = if destroyed?
+ postable.posts.order_oldest_first.select(:user_id, :updated_at).last
+ else
+ self
+ end
+ postable.update_columns(last_user_id: last_post.user_id, updated_at: last_post.updated_at)
end
end
end