mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 14:29:53 +01:00
30 lines
758 B
Ruby
30 lines
758 B
Ruby
class Comment < ApplicationRecord
|
|
belongs_to :user, counter_cache: :commented_count
|
|
belongs_to :answer, counter_cache: :comment_count
|
|
validates :user_id, presence: true
|
|
validates :answer_id, presence: true
|
|
has_many :smiles, class_name: "Reaction", foreign_key: :parent_id, dependent: :destroy
|
|
|
|
validates :content, length: { maximum: 512 }
|
|
|
|
after_create do
|
|
Subscription.subscribe user, answer
|
|
Subscription.notify self, answer
|
|
end
|
|
|
|
before_destroy do
|
|
rep = Report.where(target_id: self.id, type: 'Reports::Comment')
|
|
rep.each do |r|
|
|
unless r.nil?
|
|
r.deleted = true
|
|
r.save
|
|
end
|
|
end
|
|
|
|
Subscription.denotify self, answer
|
|
end
|
|
|
|
def notification_type(*_args)
|
|
Notification::Commented
|
|
end
|
|
end
|