Files
fizzy/app/models/card/eventable.rb
T
David Heinemeier Hansson 81f431d946 Comment-specific behavior needs to live in the comment
This really is a bit of a tangled mess. Everyone knows everything about
everyone else.
2025-04-12 10:39:56 +02:00

27 lines
675 B
Ruby

module Card::Eventable
extend ActiveSupport::Concern
included do
has_many :events, dependent: :destroy
before_create { self.last_active_at = Time.current }
end
def touch_last_active_at
touch :last_active_at
end
def track_event(action, creator: Current.user, **particulars)
if published?
event = find_or_capture_event_summary.events.create! action: action, creator: creator, card: self, particulars: particulars
event.generate_notifications_later
end
end
private
def find_or_capture_event_summary
transaction do
messages.last&.event_summary || capture(EventSummary.new).event_summary
end
end
end