5f7feed6c4
- Remove entropy bubble - Refresh the auto close notice https://app.box-car.com/5986089/cards/2683
44 lines
1.0 KiB
Ruby
44 lines
1.0 KiB
Ruby
module Card::Eventable
|
|
extend ActiveSupport::Concern
|
|
|
|
include ::Eventable
|
|
|
|
included do
|
|
before_create { self.last_active_at = Time.current }
|
|
|
|
after_save :track_title_change, if: :saved_change_to_title?
|
|
end
|
|
|
|
def event_was_created(event)
|
|
transaction do
|
|
create_system_comment_for(event)
|
|
touch_last_active_at
|
|
end
|
|
end
|
|
|
|
def touch_last_active_at
|
|
# Not using touch so that we can detect attribute change on callbacks
|
|
update!(last_active_at: Time.current)
|
|
broadcast_activity
|
|
end
|
|
|
|
private
|
|
def should_track_event?
|
|
published?
|
|
end
|
|
|
|
def track_title_change
|
|
if title_before_last_save.present?
|
|
track_event "title_changed", particulars: { old_title: title_before_last_save, new_title: title }
|
|
end
|
|
end
|
|
|
|
def create_system_comment_for(event)
|
|
SystemCommenter.new(self, event).comment
|
|
end
|
|
|
|
def broadcast_activity
|
|
broadcast_render_later_to self, :activity, partial: "card/display/refresh_activity", locals: { card: self }
|
|
end
|
|
end
|