2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-21 16:23:09 +08:00
|
|
|
%i(
|
|
|
|
topic_recovered
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |topic, _|
|
|
|
|
WebHook.enqueue_topic_hooks(event, topic)
|
2017-04-12 09:50:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-27 11:07:37 +08:00
|
|
|
DiscourseEvent.on(:topic_status_updated) do |topic, status|
|
|
|
|
WebHook.enqueue_topic_hooks("topic_#{status}_status_updated", topic)
|
|
|
|
end
|
|
|
|
|
2018-05-21 16:23:09 +08:00
|
|
|
DiscourseEvent.on(:topic_created) do |topic, _, _|
|
|
|
|
WebHook.enqueue_topic_hooks(:topic_created, topic)
|
2017-04-12 09:50:03 +08:00
|
|
|
end
|
|
|
|
|
2018-05-21 16:23:09 +08:00
|
|
|
%i(
|
|
|
|
post_created
|
|
|
|
post_recovered
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |post, _, _|
|
|
|
|
WebHook.enqueue_post_hooks(event, post)
|
2017-04-12 09:50:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.on(:post_edited) do |post, topic_changed|
|
2020-04-21 09:50:20 +08:00
|
|
|
unless post.topic&.trashed?
|
2018-01-23 03:58:01 +08:00
|
|
|
WebHook.enqueue_post_hooks(:post_edited, post)
|
|
|
|
|
|
|
|
if post.is_first_post? && topic_changed
|
|
|
|
WebHook.enqueue_topic_hooks(:topic_edited, post.topic)
|
|
|
|
end
|
|
|
|
end
|
2017-04-12 09:50:03 +08:00
|
|
|
end
|
|
|
|
|
2017-12-20 17:47:30 +08:00
|
|
|
%i(
|
|
|
|
user_logged_out
|
|
|
|
user_created
|
|
|
|
user_logged_in
|
|
|
|
user_approved
|
|
|
|
user_updated
|
2021-04-12 10:48:42 +08:00
|
|
|
user_confirmed_email
|
2017-12-20 17:47:30 +08:00
|
|
|
).each do |event|
|
2017-04-12 09:50:03 +08:00
|
|
|
DiscourseEvent.on(event) do |user|
|
2018-05-21 16:23:09 +08:00
|
|
|
WebHook.enqueue_object_hooks(:user, user, event)
|
2017-04-12 09:50:03 +08:00
|
|
|
end
|
|
|
|
end
|
2018-03-27 14:23:35 +08:00
|
|
|
|
|
|
|
%i(
|
|
|
|
group_created
|
|
|
|
group_updated
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |group|
|
2018-05-21 16:23:09 +08:00
|
|
|
WebHook.enqueue_object_hooks(:group, group, event)
|
2018-03-27 14:23:35 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%i(
|
|
|
|
category_created
|
|
|
|
category_updated
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |category|
|
2018-05-21 16:23:09 +08:00
|
|
|
WebHook.enqueue_object_hooks(:category, category, event)
|
2018-03-27 14:23:35 +08:00
|
|
|
end
|
|
|
|
end
|
2018-04-04 20:19:20 +08:00
|
|
|
|
|
|
|
%i(
|
|
|
|
tag_created
|
|
|
|
tag_updated
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |tag|
|
2018-05-21 17:29:19 +08:00
|
|
|
WebHook.enqueue_object_hooks(:tag, tag, event, TagSerializer)
|
2018-04-04 20:19:20 +08:00
|
|
|
end
|
|
|
|
end
|
2018-04-11 22:17:05 +08:00
|
|
|
|
2020-04-09 02:34:35 +08:00
|
|
|
%i(
|
|
|
|
user_badge_granted
|
|
|
|
).each do |event|
|
|
|
|
# user_badge_revoked
|
|
|
|
DiscourseEvent.on(event) do |badge, user_id|
|
|
|
|
ub = UserBadge.find_by(badge: badge, user_id: user_id)
|
|
|
|
WebHook.enqueue_object_hooks(:user_badge, ub, event, UserBadgeSerializer)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-27 08:40:32 +08:00
|
|
|
%i(
|
|
|
|
reviewable_created
|
|
|
|
reviewable_score_updated
|
|
|
|
).each do |event|
|
|
|
|
DiscourseEvent.on(event) do |reviewable|
|
|
|
|
WebHook.enqueue_object_hooks(:reviewable, reviewable, event, reviewable.serializer)
|
|
|
|
end
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.on(:reviewable_transitioned_to) do |status, reviewable|
|
|
|
|
WebHook.enqueue_object_hooks(:reviewable, reviewable, :reviewable_transitioned_to, reviewable.serializer)
|
2018-07-26 01:54:43 +08:00
|
|
|
end
|
2019-08-16 02:45:30 +08:00
|
|
|
|
|
|
|
DiscourseEvent.on(:notification_created) do |notification|
|
|
|
|
WebHook.enqueue_object_hooks(:notification, notification, :notification_created, NotificationSerializer)
|
|
|
|
end
|
2021-04-08 23:46:34 +08:00
|
|
|
|
|
|
|
DiscourseEvent.on(:user_added_to_group) do |user, group, options|
|
|
|
|
group_user = GroupUser.find_by(user: user, group: group)
|
|
|
|
WebHook.enqueue_object_hooks(:group_user, group_user, :user_added_to_group, WebHookGroupUserSerializer)
|
|
|
|
end
|
2021-05-01 08:08:38 +08:00
|
|
|
|
|
|
|
DiscourseEvent.on(:like_created) do |post_action|
|
|
|
|
user = post_action.user
|
|
|
|
group_ids = user.groups.map(&:id)
|
|
|
|
WebHook.enqueue_object_hooks(:like, post_action, :post_liked, WebHookLikeSerializer, group_ids: group_ids)
|
|
|
|
end
|