2019-09-16 16:05:00 +02:00
|
|
|
class Comment < ApplicationRecord
|
2022-07-18 10:47:54 +02:00
|
|
|
include TenantOwnable
|
|
|
|
|
|
2019-09-16 16:05:00 +02:00
|
|
|
belongs_to :user
|
|
|
|
|
belongs_to :post
|
|
|
|
|
belongs_to :parent, class_name: 'Comment', optional: true
|
|
|
|
|
has_many :children, class_name: 'Comment', foreign_key: 'parent_id', dependent: :destroy
|
|
|
|
|
|
2024-12-20 14:06:48 +01:00
|
|
|
after_create :run_webhooks
|
|
|
|
|
|
2019-09-30 18:49:15 +02:00
|
|
|
validates :body, presence: true
|
2024-12-20 14:06:48 +01:00
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def run_webhooks
|
|
|
|
|
entities = {
|
|
|
|
|
comment: self.id,
|
|
|
|
|
comment_author: self.user.id,
|
|
|
|
|
post: self.post.id,
|
|
|
|
|
board: self.post.board.id
|
|
|
|
|
}
|
|
|
|
|
entities[:post_author] = self.post.user.id if self.post.user_id
|
|
|
|
|
|
|
|
|
|
Webhook.where(trigger: :new_comment, is_enabled: true).each do |webhook|
|
|
|
|
|
RunWebhook.perform_later(
|
|
|
|
|
webhook_id: webhook.id,
|
|
|
|
|
current_tenant_id: Current.tenant.id,
|
|
|
|
|
entities: entities
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
2019-09-16 16:05:00 +02:00
|
|
|
end
|