mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Extract callbacks and validations for Post
Move Post create callbacks to PostCreate Extract Post validations Move stripped_length_validator to lib/validators
This commit is contained in:
@@ -73,12 +73,37 @@ class PostCreator
|
||||
@post
|
||||
end
|
||||
|
||||
|
||||
# Shortcut
|
||||
def self.create(user, opts)
|
||||
PostCreator.new(user, opts).create
|
||||
end
|
||||
|
||||
def self.before_create_tasks(post)
|
||||
if post.reply_to_post_number.present?
|
||||
post.reply_to_user_id ||= Post.select(:user_id).where(topic_id: post.topic_id, post_number: post.reply_to_post_number).first.try(:user_id)
|
||||
end
|
||||
|
||||
post.post_number ||= Topic.next_post_number(post.topic_id, post.reply_to_post_number.present?)
|
||||
post.cooked ||= post.cook(post.raw, topic_id: post.topic_id)
|
||||
post.sort_order = post.post_number
|
||||
DiscourseEvent.trigger(:before_create_post, post)
|
||||
post.last_version_at ||= Time.now
|
||||
end
|
||||
|
||||
def self.after_create_tasks(post)
|
||||
Rails.logger.info (">" * 30) + "#{post.no_bump} #{post.created_at}"
|
||||
# Update attributes on the topic - featured users and last posted.
|
||||
attrs = {last_posted_at: post.created_at, last_post_user_id: post.user_id}
|
||||
attrs[:bumped_at] = post.created_at unless post.no_bump
|
||||
post.topic.update_attributes(attrs)
|
||||
|
||||
# Update topic user data
|
||||
TopicUser.change(post.user,
|
||||
post.topic.id,
|
||||
posted: true,
|
||||
last_read_post_number: post.post_number,
|
||||
seen_post_count: post.post_number)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def secure_group_ids(topic)
|
||||
|
||||
Reference in New Issue
Block a user