Files
fizzy/app/models/comment.rb
T
David Heinemeier Hansson e4efe446e6 Simlpe callback is actually enough
Since the Comment already knows about the card.
2025-04-12 11:45:34 +02:00

35 lines
1.0 KiB
Ruby

class Comment < ApplicationRecord
include Messageable, Searchable
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :reactions, dependent: :delete_all
has_markdown :body
searchable_by :body_plain_text, using: :comments_search_index, as: :body
# FIXME: Not a fan of this. Think all references to comment should come directly from the message.
scope :belonging_to_card, ->(card) { joins(:message).where(messages: { card_id: card.id }) }
before_destroy :cleanup_events
after_create_commit :creator_watches_card, :track_commenting_on_card
def to_partial_path
"cards/#{super}"
end
private
# FIXME: This isn't right. We need to introduce an eventable polymorphic association for this.
def cleanup_events
# Delete events that reference directly in particulars
Event.where(particulars: { comment_id: id }).destroy_all
end
def creator_watches_card
card.watch_by creator
end
def track_commenting_on_card
card.track_event :commented, comment_id: id
end
end