Simlpe callback is actually enough
Since the Comment already knows about the card.
This commit is contained in:
@@ -11,12 +11,7 @@ class Comment < ApplicationRecord
|
||||
scope :belonging_to_card, ->(card) { joins(:message).where(messages: { card_id: card.id }) }
|
||||
|
||||
before_destroy :cleanup_events
|
||||
|
||||
# Called when a new comment is captured as a message during creation
|
||||
def created_via_message
|
||||
card.watch_by creator
|
||||
card.track_event :commented, comment_id: id
|
||||
end
|
||||
after_create_commit :creator_watches_card, :track_commenting_on_card
|
||||
|
||||
def to_partial_path
|
||||
"cards/#{super}"
|
||||
@@ -28,4 +23,12 @@ class Comment < ApplicationRecord
|
||||
# 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
|
||||
|
||||
@@ -7,8 +7,4 @@ module Messageable
|
||||
has_one :message, as: :messageable, touch: true, dependent: :destroy
|
||||
has_one :card, through: :message
|
||||
end
|
||||
|
||||
def created_via_message
|
||||
# Overwrite in Messageable class
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,5 @@ class Message < ApplicationRecord
|
||||
|
||||
delegated_type :messageable, types: Messageable::TYPES, inverse_of: :message, dependent: :destroy
|
||||
|
||||
after_create -> { messageable.created_via_message }
|
||||
|
||||
scope :chronologically, -> { order created_at: :asc, id: :desc }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user