Centralize MessageBus post updates

After this change, only two files directly publish to MessageBus with a
topic interpolated in the channel: Post and TopicUser.
This commit is contained in:
riking
2014-08-28 20:34:32 -07:00
parent 0a7a4eae99
commit 3396e6fea3
7 changed files with 32 additions and 54 deletions

View File

@@ -21,6 +21,7 @@ class PostRevisor
@opts = opts
@new_raw = TextCleaner.normalize_whitespaces(new_raw).strip
# TODO this is not in a transaction - dangerous!
return false unless should_revise?
@post.acting_user = @editor
revise_post
@@ -30,7 +31,7 @@ class PostRevisor
update_topic_word_counts
@post.advance_draft_sequence
PostAlerter.new.after_save_post(@post)
publish_revision
@post.publish_change_to_clients! :revised
BadgeGranter.queue_badge_grant(Badge::Trigger::PostRevision, post: @post)
true
@@ -38,17 +39,6 @@ class PostRevisor
private
def publish_revision
MessageBus.publish("/topic/#{@post.topic_id}",{
id: @post.id,
post_number: @post.post_number,
updated_at: @post.updated_at,
type: "revised"
},
group_ids: @post.topic.secure_group_ids
)
end
def should_revise?
@post.raw != @new_raw || @opts[:changed_owner]
end