4f19c42958
Use polymorphism instead of case statements in Native push target: - DefaultPayload#category returns "default", #high_priority? returns false - EventPayload#category returns "assignment"/"comment"/"card" based on action - MentionPayload#category returns "mention", #high_priority? returns true This simplifies the Native push target by delegating source-specific logic to the appropriate payload classes. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
922 B
Ruby
50 lines
922 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
|
|
|
|
def title
|
|
"New notification"
|
|
end
|
|
|
|
def body
|
|
"You have a new notification"
|
|
end
|
|
|
|
def url
|
|
notifications_url
|
|
end
|
|
|
|
def category
|
|
"default"
|
|
end
|
|
|
|
def high_priority?
|
|
false
|
|
end
|
|
|
|
private
|
|
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
|