1d2ed91e89
Separates notification payload construction from push delivery by introducing DefaultPayload, EventPayload, and MentionPayload classes that encapsulate the title, body, and URL generation for each notification type. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
36 lines
669 B
Ruby
36 lines
669 B
Ruby
class Notification::Push
|
|
attr_reader :notification
|
|
|
|
delegate :card, to: :notification
|
|
|
|
def initialize(notification)
|
|
@notification = notification
|
|
end
|
|
|
|
def push
|
|
return unless should_push?
|
|
|
|
perform_push
|
|
end
|
|
|
|
private
|
|
def should_push?
|
|
notification.pushable?
|
|
end
|
|
|
|
def perform_push
|
|
raise NotImplementedError
|
|
end
|
|
|
|
def build_payload
|
|
case notification.source_type
|
|
when "Event"
|
|
Notification::EventPayload.new(notification).to_h
|
|
when "Mention"
|
|
Notification::MentionPayload.new(notification).to_h
|
|
else
|
|
Notification::DefaultPayload.new(notification).to_h
|
|
end
|
|
end
|
|
end
|