mirror of
https://github.com/discourse/discourse.git
synced 2026-08-13 14:35:08 -05:00
push some work out of AR callbacks into PostCreator, add a couple of helpers for post and topic creation in test
fix it so the auto_track false marks topics as new
This commit is contained in:
+14
-13
@@ -66,6 +66,7 @@ class PostCreator
|
||||
store_unique_post_key
|
||||
send_notifications_for_private_message
|
||||
track_topic
|
||||
update_topic_stats
|
||||
update_user_counts
|
||||
publish
|
||||
@post.advance_draft_sequence
|
||||
@@ -100,19 +101,6 @@ class PostCreator
|
||||
post.last_version_at ||= Time.now
|
||||
end
|
||||
|
||||
def self.after_create_tasks(post)
|
||||
# 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.id,
|
||||
post.topic.id,
|
||||
posted: true,
|
||||
last_read_post_number: post.post_number,
|
||||
seen_post_count: post.post_number)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@@ -184,6 +172,13 @@ class PostCreator
|
||||
@topic = topic
|
||||
end
|
||||
|
||||
def update_topic_stats
|
||||
# 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
|
||||
@topic.update_attributes(attrs)
|
||||
end
|
||||
|
||||
def setup_post
|
||||
post = @topic.posts.new(raw: @opts[:raw],
|
||||
user: @user,
|
||||
@@ -267,6 +262,12 @@ class PostCreator
|
||||
def track_topic
|
||||
unless @opts[:auto_track] == false
|
||||
TopicUser.auto_track(@user.id, @topic.id, TopicUser.notification_reasons[:created_post])
|
||||
# Update topic user data
|
||||
TopicUser.change(@post.user.id,
|
||||
@post.topic.id,
|
||||
posted: true,
|
||||
last_read_post_number: @post.post_number,
|
||||
seen_post_count: @post.post_number)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user