FIX: Add web hook `DiscourseEvent`s in initializer.

This commit is contained in:
Guo Xiang Tan 2017-04-12 09:50:03 +08:00
parent 3a235d1241
commit 66a7b0c30b
2 changed files with 29 additions and 30 deletions

View File

@ -47,36 +47,6 @@ class WebHook < ActiveRecord::Base
def self.enqueue_post_hooks(event, post, user=nil) def self.enqueue_post_hooks(event, post, user=nil)
WebHook.enqueue_hooks(:post, post_id: post.id, category_id: post&.topic&.category_id, event_name: event.to_s) WebHook.enqueue_hooks(:post, post_id: post.id, category_id: post&.topic&.category_id, event_name: event.to_s)
end end
%i(topic_destroyed topic_recovered).each do |event|
DiscourseEvent.on(event) do |topic, user|
WebHook.enqueue_topic_hooks(event, topic, user)
end
end
DiscourseEvent.on(:topic_created) do |topic, _, user|
WebHook.enqueue_topic_hooks(:topic_created, topic, user)
end
%i(post_created
post_destroyed
post_recovered).each do |event|
DiscourseEvent.on(event) do |post, _, user|
WebHook.enqueue_post_hooks(event, post, user)
end
end
DiscourseEvent.on(:post_edited) do |post, topic_changed|
WebHook.enqueue_post_hooks(:post_edited, post)
WebHook.enqueue_topic_hooks(:topic_edited, post.topic) if post.is_first_post? && topic_changed
end
%i(user_created user_approved user_updated).each do |event|
DiscourseEvent.on(event) do |user|
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)
end
end
end end
# == Schema Information # == Schema Information

View File

@ -0,0 +1,29 @@
%i(topic_destroyed topic_recovered).each do |event|
DiscourseEvent.on(event) do |topic, user|
WebHook.enqueue_topic_hooks(event, topic, user)
end
end
DiscourseEvent.on(:topic_created) do |topic, _, user|
WebHook.enqueue_topic_hooks(:topic_created, topic, user)
end
%i(post_created
post_destroyed
post_recovered).each do |event|
DiscourseEvent.on(event) do |post, _, user|
WebHook.enqueue_post_hooks(event, post, user)
end
end
DiscourseEvent.on(:post_edited) do |post, topic_changed|
WebHook.enqueue_post_hooks(:post_edited, post)
WebHook.enqueue_topic_hooks(:topic_edited, post.topic) if post.is_first_post? && topic_changed
end
%i(user_created user_approved user_updated).each do |event|
DiscourseEvent.on(event) do |user|
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)
end
end