2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-21 04:23:09 -04:00
|
|
|
%i[topic_recovered].each do |event|
|
|
|
|
DiscourseEvent.on(event) { |topic, _| WebHook.enqueue_topic_hooks(event, topic) }
|
2017-04-11 21:50:03 -04:00
|
|
|
end
|
|
|
|
|
2018-02-26 22:07:37 -05:00
|
|
|
DiscourseEvent.on(:topic_status_updated) do |topic, status|
|
|
|
|
WebHook.enqueue_topic_hooks("topic_#{status}_status_updated", topic)
|
|
|
|
end
|
|
|
|
|
2018-05-21 04:23:09 -04:00
|
|
|
DiscourseEvent.on(:topic_created) do |topic, _, _|
|
|
|
|
WebHook.enqueue_topic_hooks(:topic_created, topic)
|
2017-04-11 21:50:03 -04:00
|
|
|
end
|
|
|
|
|
2018-05-21 04:23:09 -04:00
|
|
|
%i[post_created post_recovered].each do |event|
|
|
|
|
DiscourseEvent.on(event) { |post, _, _| WebHook.enqueue_post_hooks(event, post) }
|
2017-04-11 21:50:03 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.on(:post_edited) do |post, topic_changed|
|
2020-04-20 21:50:20 -04:00
|
|
|
unless post.topic&.trashed?
|
2021-05-23 19:10:22 -04:00
|
|
|
# if we are editing the OP and the topic is changed, do not send
|
|
|
|
# the post_edited event -- this event is sent separately because
|
|
|
|
# when we update the OP in the UI we send two API calls in this order:
|
|
|
|
#
|
|
|
|
# PUT /t/topic-name
|
|
|
|
# PUT /post/243552
|
2018-01-22 14:58:01 -05:00
|
|
|
if post.is_first_post? && topic_changed
|
|
|
|
WebHook.enqueue_topic_hooks(:topic_edited, post.topic)
|
2021-05-23 19:10:22 -04:00
|
|
|
else
|
|
|
|
WebHook.enqueue_post_hooks(:post_edited, post)
|
2018-01-22 14:58:01 -05:00
|
|
|
end
|
|
|
|
end
|
2017-04-11 21:50:03 -04:00
|
|
|
end
|
|
|
|
|
2017-12-20 04:47:30 -05:00
|
|
|
%i[
|
|
|
|
user_logged_out
|
|
|
|
user_created
|
|
|
|
user_logged_in
|
|
|
|
user_approved
|
|
|
|
user_updated
|
2021-04-11 22:48:42 -04:00
|
|
|
user_confirmed_email
|
2017-12-20 04:47:30 -05:00
|
|
|
].each do |event|
|
2018-05-21 04:23:09 -04:00
|
|
|
DiscourseEvent.on(event) { |user| WebHook.enqueue_object_hooks(:user, user, event) }
|
2017-04-11 21:50:03 -04:00
|
|
|
end
|
2018-03-27 02:23:35 -04:00
|
|
|
|
2023-09-28 04:51:05 -04:00
|
|
|
%i[user_suspended user_unsuspended].each do |event|
|
|
|
|
DiscourseEvent.on(event) { |args| WebHook.enqueue_object_hooks(:user, args[:user], event) }
|
|
|
|
end
|
|
|
|
|
2018-03-27 02:23:35 -04:00
|
|
|
%i[group_created group_updated].each do |event|
|
2018-05-21 04:23:09 -04:00
|
|
|
DiscourseEvent.on(event) { |group| WebHook.enqueue_object_hooks(:group, group, event) }
|
2018-03-27 02:23:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
%i[category_created category_updated].each do |event|
|
2018-05-21 04:23:09 -04:00
|
|
|
DiscourseEvent.on(event) { |category| WebHook.enqueue_object_hooks(:category, category, event) }
|
2018-03-27 02:23:35 -04:00
|
|
|
end
|
2018-04-04 08:19:20 -04:00
|
|
|
|
|
|
|
%i[tag_created tag_updated].each do |event|
|
2018-05-21 05:29:19 -04:00
|
|
|
DiscourseEvent.on(event) { |tag| WebHook.enqueue_object_hooks(:tag, tag, event, TagSerializer) }
|
2018-04-04 08:19:20 -04:00
|
|
|
end
|
2018-04-11 10:17:05 -04:00
|
|
|
|
2023-04-24 16:36:40 -04:00
|
|
|
DiscourseEvent.on(:user_badge_granted) do |badge_id, user_id|
|
|
|
|
ub = UserBadge.find_by(badge_id: badge_id, user_id: user_id)
|
|
|
|
WebHook.enqueue_object_hooks(:user_badge, ub, :user_badge_granted, UserBadgeSerializer)
|
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.on(:user_badge_revoked) do |args|
|
|
|
|
WebHook.enqueue_object_hooks(
|
|
|
|
:user_badge,
|
|
|
|
args[:user_badge],
|
|
|
|
:user_badge_revoked,
|
|
|
|
UserBadgeSerializer,
|
|
|
|
)
|
2020-04-08 14:34:35 -04:00
|
|
|
end
|
|
|
|
|
2021-04-26 20:40:32 -04: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-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
DiscourseEvent.on(:reviewable_transitioned_to) do |status, reviewable|
|
|
|
|
WebHook.enqueue_object_hooks(
|
|
|
|
:reviewable,
|
|
|
|
reviewable,
|
|
|
|
:reviewable_transitioned_to,
|
|
|
|
reviewable.serializer,
|
|
|
|
)
|
2018-07-25 13:54:43 -04:00
|
|
|
end
|
2019-08-15 14:45:30 -04:00
|
|
|
|
|
|
|
DiscourseEvent.on(:notification_created) do |notification|
|
|
|
|
WebHook.enqueue_object_hooks(
|
|
|
|
:notification,
|
|
|
|
notification,
|
|
|
|
:notification_created,
|
|
|
|
NotificationSerializer,
|
|
|
|
)
|
|
|
|
end
|
2021-04-08 11:46:34 -04: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,
|
2023-04-26 18:38:28 -04:00
|
|
|
group_ids: [group.id],
|
2021-04-08 11:46:34 -04:00
|
|
|
)
|
|
|
|
end
|
2021-04-30 20:08:38 -04:00
|
|
|
|
2022-02-22 04:57:18 -05:00
|
|
|
DiscourseEvent.on(:user_promoted) do |payload|
|
|
|
|
user_id, new_trust_level, old_trust_level =
|
|
|
|
payload.values_at(:user_id, :new_trust_level, :old_trust_level)
|
|
|
|
|
|
|
|
next if new_trust_level < old_trust_level
|
|
|
|
|
|
|
|
user = User.find(user_id)
|
|
|
|
WebHook.enqueue_object_hooks(:user_promoted, user, :user_promoted, UserSerializer)
|
|
|
|
end
|
|
|
|
|
2021-04-30 20:08:38 -04:00
|
|
|
DiscourseEvent.on(:like_created) do |post_action|
|
|
|
|
user = post_action.user
|
|
|
|
group_ids = user.groups.map(&:id)
|
2022-01-14 09:17:38 -05:00
|
|
|
topic = Topic.includes(:tags).joins(:posts).find_by(posts: { id: post_action.post_id })
|
|
|
|
category_id = topic&.category_id
|
|
|
|
tag_ids = topic&.tag_ids
|
|
|
|
|
|
|
|
WebHook.enqueue_object_hooks(
|
|
|
|
:like,
|
|
|
|
post_action,
|
|
|
|
:post_liked,
|
|
|
|
WebHookLikeSerializer,
|
|
|
|
group_ids: group_ids,
|
|
|
|
category_id: category_id,
|
|
|
|
tag_ids: tag_ids,
|
|
|
|
)
|
2021-04-30 20:08:38 -04:00
|
|
|
end
|