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>
42 lines
866 B
Ruby
42 lines
866 B
Ruby
class Notification::DefaultPayload
|
|
attr_reader :notification
|
|
|
|
delegate :card, to: :notification
|
|
|
|
def initialize(notification)
|
|
@notification = notification
|
|
end
|
|
|
|
def to_h
|
|
{ title: title, body: body, url: url }
|
|
end
|
|
|
|
private
|
|
def title
|
|
"New notification"
|
|
end
|
|
|
|
def body
|
|
"You have a new notification"
|
|
end
|
|
|
|
def url
|
|
notifications_url
|
|
end
|
|
|
|
def card_url(card)
|
|
Rails.application.routes.url_helpers.card_url(card, **url_options)
|
|
end
|
|
|
|
def notifications_url
|
|
Rails.application.routes.url_helpers.notifications_url(**url_options)
|
|
end
|
|
|
|
def url_options
|
|
base_options = Rails.application.routes.default_url_options.presence ||
|
|
Rails.application.config.action_mailer.default_url_options ||
|
|
{}
|
|
base_options.merge(script_name: notification.account.slug)
|
|
end
|
|
end
|