Send the URL instead of path in notifications

This commit is contained in:
Fernando Olivares
2026-01-20 23:59:15 -06:00
committed by Rosa Gutierrez
parent ade39b15ab
commit 7e0470a692
3 changed files with 20 additions and 13 deletions
+16 -9
View File
@@ -45,7 +45,7 @@ class NotificationPusher
base_payload = {
title: card_notification_title(card),
path: card_path(card)
url: card_url(card)
}
case event.action
@@ -53,7 +53,7 @@ class NotificationPusher
base_payload.merge(
title: "RE: #{base_payload[:title]}",
body: comment_notification_body(event),
path: card_path_with_comment_anchor(event.eventable)
url: card_url_with_comment_anchor(event.eventable)
)
when "card_assigned"
base_payload.merge(
@@ -85,7 +85,7 @@ class NotificationPusher
{
title: "#{mention.mentioner.first_name} mentioned you",
body: format_excerpt(mention.source.mentionable_content, length: 200),
path: card_path(card)
url: card_url(card)
}
end
@@ -93,7 +93,7 @@ class NotificationPusher
{
title: "New notification",
body: "You have a new notification",
path: notifications_path(script_name: notification.account.slug)
url: notifications_url(**url_options)
}
end
@@ -114,15 +114,22 @@ class NotificationPusher
format_excerpt(event.eventable.body, length: 200)
end
def card_path(card)
Rails.application.routes.url_helpers.card_path(card, script_name: notification.account.slug)
def card_url(card)
Rails.application.routes.url_helpers.card_url(card, **url_options)
end
def card_path_with_comment_anchor(comment)
Rails.application.routes.url_helpers.card_path(
def card_url_with_comment_anchor(comment)
Rails.application.routes.url_helpers.card_url(
comment.card,
anchor: ActionView::RecordIdentifier.dom_id(comment),
script_name: notification.account.slug
**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
+3 -3
View File
@@ -1,6 +1,6 @@
class WebPush::Notification
def initialize(title:, body:, path:, badge:, endpoint:, endpoint_ip:, p256dh_key:, auth_key:)
@title, @body, @path, @badge = title, body, path, badge
def initialize(title:, body:, url:, badge:, endpoint:, endpoint_ip:, p256dh_key:, auth_key:)
@title, @body, @url, @badge = title, body, url, badge
@endpoint, @endpoint_ip, @p256dh_key, @auth_key = endpoint, endpoint_ip, p256dh_key, auth_key
end
@@ -20,7 +20,7 @@ class WebPush::Notification
end
def encoded_message
JSON.generate title: @title, options: { body: @body, icon: icon_path, data: { path: @path, badge: @badge } }
JSON.generate title: @title, options: { body: @body, icon: icon_path, data: { url: @url, badge: @badge } }
end
def icon_path
@@ -37,7 +37,7 @@ module NotificationPusher::Native
.with_data(
title: payload[:title],
body: payload[:body],
path: payload[:path],
url: payload[:url],
account_id: notification.account.external_account_id,
avatar_url: creator_avatar_url,
card_id: card&.id,