Files
fizzy/app/models/notification/pushable.rb
T
Rosa Gutierrez b5205ce6b2 Rename Push to PushTarget for better readability
PushTarget#push reads more naturally than Push#push. The push target
is the thing that pushes notifications to a specific destination.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-25 19:31:13 +01:00

45 lines
1021 B
Ruby

module Notification::Pushable
extend ActiveSupport::Concern
included do
class_attribute :push_targets, default: []
after_create_commit :push_later
after_update_commit :push_later, if: :source_id_previously_changed?
end
class_methods do
def register_push_target(target)
target = resolve_push_target(target)
push_targets << target unless push_targets.include?(target)
end
private
def resolve_push_target(target)
if target.is_a?(Notification::PushTarget) then target
else
"Notification::PushTarget::#{target.to_s.classify}".constantize
end
end
end
def push_later
self.class.push_targets.each do |target|
target.push_later(self)
end
end
def pushable?
!creator.system? && user.active? && account.active?
end
def payload
"Notification::#{payload_type}Payload".constantize.new(self)
end
private
def payload_type
source_type.presence_in(%w[ Event Mention ]) || "Default"
end
end