Files
fizzy/app/models/bubble/eventable.rb
T
Jorge Manrubia 08cb69aca5 Replace auto_pop_at with generic last_activity column
so that we can use it in other scenarios
2025-04-04 09:45:56 +02:00

27 lines
691 B
Ruby

module Bubble::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
private
def track_event(action, creator: Current.user, **particulars)
if published?
event = find_or_capture_event_summary.events.create! action: action, creator: creator, bubble: self, particulars: particulars
event.generate_notifications_later
end
end
def find_or_capture_event_summary
transaction do
messages.last&.event_summary || capture(EventSummary.new).event_summary
end
end
end