mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Move a bunch of callbacks into PostCreator
This commit is contained in:
@@ -4,13 +4,13 @@ require_dependency 'rate_limiter'
|
||||
|
||||
class PostCreator
|
||||
|
||||
# Errors when creating the post
|
||||
attr_reader :errors
|
||||
attr_reader :errors, :opts
|
||||
|
||||
# Acceptable options:
|
||||
#
|
||||
# raw - raw text of post
|
||||
# image_sizes - We can pass a list of the sizes of images in the post as a shortcut.
|
||||
# invalidate_oneboxes - Whether to force invalidation of oneboxes in this post
|
||||
#
|
||||
# When replying to a topic:
|
||||
# topic_id - topic we're replying to
|
||||
@@ -78,6 +78,7 @@ class PostCreator
|
||||
user: @user,
|
||||
reply_to_post_number: @opts[:reply_to_post_number])
|
||||
post.image_sizes = @opts[:image_sizes] if @opts[:image_sizes].present?
|
||||
post.invalidate_oneboxes = @opts[:invalidate_oneboxes] if @opts[:invalidate_oneboxes].present?
|
||||
unless post.save
|
||||
@errors = post.errors
|
||||
raise ActiveRecord::Rollback.new
|
||||
@@ -85,6 +86,30 @@ class PostCreator
|
||||
|
||||
# Extract links
|
||||
TopicLink.extract_from(post)
|
||||
|
||||
# Enqueue a job to feature the users in the topic
|
||||
Jobs.enqueue(:feature_topic_users, topic_id: topic.id)
|
||||
|
||||
# Trigger post processing
|
||||
post.trigger_post_process
|
||||
|
||||
# Store unique post key
|
||||
if SiteSetting.unique_posts_mins > 0
|
||||
$redis.setex(post.unique_post_key, SiteSetting.unique_posts_mins.minutes.to_i, "1")
|
||||
end
|
||||
|
||||
# send a mail to notify users in case of a private message
|
||||
if topic.private_message?
|
||||
topic.allowed_users.where(["users.email_private_messages = true and users.id != ?", @user.id]).each do |u|
|
||||
Jobs.enqueue_in(SiteSetting.email_time_window_mins.minutes, :user_email, type: :private_message, user_id: u.id, post_id: post.id)
|
||||
end
|
||||
end
|
||||
|
||||
# Track the topic
|
||||
TopicUser.auto_track(@user.id, topic.id, TopicUser.notification_reasons[:created_post])
|
||||
|
||||
# Update `last_posted_at` to match the post's created_at
|
||||
@user.update_column(:last_posted_at, post.created_at)
|
||||
end
|
||||
|
||||
post
|
||||
|
||||
Reference in New Issue
Block a user