refactor forum notifications for tag changes

This commit is contained in:
r888888888
2017-03-31 17:42:14 -07:00
parent 441022960a
commit 19b8d41d09
17 changed files with 422 additions and 317 deletions

View File

@@ -0,0 +1,38 @@
class ForumUpdater
attr_reader :forum_topic, :forum_post, :expected_title
def initialize(forum_topic, options = {})
@forum_topic = forum_topic
@forum_post = options[:forum_post]
@expected_title = options[:expected_title]
end
def update(message, title_tag = nil)
return if forum_topic.nil?
CurrentUser.scoped(User.system) do
create_response(message)
update_title(title_tag) if title_tag
if forum_post
update_post(message)
end
end
end
def create_response(body)
forum_topic.posts.create(
:body => body
)
end
def update_title(title_tag)
if forum_topic.title == expected_title
forum_topic.update(:title => "[#{title_tag}] #{forum_topic.title}")
end
end
def update_post(body)
forum_post.update(:body => "#{forum_post.body}\n\n#{body}")
end
end