Files
fizzy/app/models/notification/pushable.rb
T
Rosa Gutierrez 05819f84a2 Refactor notification push system with registry pattern
Replace NotificationPusher with a cleaner architecture:

- Add Notification::Pushable concern with push target registry
- Add Notification::Push base class with template methods
- Add Notification::Push::Web for web push (OSS)
- Add Notification::Push::Native for native push (SaaS)
- Add Notification::WebPushJob and Notification::NativePushJob

Key design:
- Registry pattern: Notification.register_push_target(:web)
- Template method: push calls should_push? then perform_push
- Subclasses override should_push? (with super) and perform_push
- Each target handles its own job enqueueing

Also:
- Add Notification#pushable? for checking push eligibility
- Add Notification#identity delegation to user
- Reorganize tests to match new class structure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Tidy up saas engine a bit more
2026-02-25 19:31:13 +01:00

37 lines
812 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?(Symbol)
"Notification::Push::#{target.to_s.classify}".constantize
else
target
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
end