Send the URL instead of path in notifications
This commit is contained in:
committed by
Rosa Gutierrez
parent
ade39b15ab
commit
7e0470a692
@@ -45,7 +45,7 @@ class NotificationPusher
|
|||||||
|
|
||||||
base_payload = {
|
base_payload = {
|
||||||
title: card_notification_title(card),
|
title: card_notification_title(card),
|
||||||
path: card_path(card)
|
url: card_url(card)
|
||||||
}
|
}
|
||||||
|
|
||||||
case event.action
|
case event.action
|
||||||
@@ -53,7 +53,7 @@ class NotificationPusher
|
|||||||
base_payload.merge(
|
base_payload.merge(
|
||||||
title: "RE: #{base_payload[:title]}",
|
title: "RE: #{base_payload[:title]}",
|
||||||
body: comment_notification_body(event),
|
body: comment_notification_body(event),
|
||||||
path: card_path_with_comment_anchor(event.eventable)
|
url: card_url_with_comment_anchor(event.eventable)
|
||||||
)
|
)
|
||||||
when "card_assigned"
|
when "card_assigned"
|
||||||
base_payload.merge(
|
base_payload.merge(
|
||||||
@@ -85,7 +85,7 @@ class NotificationPusher
|
|||||||
{
|
{
|
||||||
title: "#{mention.mentioner.first_name} mentioned you",
|
title: "#{mention.mentioner.first_name} mentioned you",
|
||||||
body: format_excerpt(mention.source.mentionable_content, length: 200),
|
body: format_excerpt(mention.source.mentionable_content, length: 200),
|
||||||
path: card_path(card)
|
url: card_url(card)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ class NotificationPusher
|
|||||||
{
|
{
|
||||||
title: "New notification",
|
title: "New notification",
|
||||||
body: "You have a new notification",
|
body: "You have a new notification",
|
||||||
path: notifications_path(script_name: notification.account.slug)
|
url: notifications_url(**url_options)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -114,15 +114,22 @@ class NotificationPusher
|
|||||||
format_excerpt(event.eventable.body, length: 200)
|
format_excerpt(event.eventable.body, length: 200)
|
||||||
end
|
end
|
||||||
|
|
||||||
def card_path(card)
|
def card_url(card)
|
||||||
Rails.application.routes.url_helpers.card_path(card, script_name: notification.account.slug)
|
Rails.application.routes.url_helpers.card_url(card, **url_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def card_path_with_comment_anchor(comment)
|
def card_url_with_comment_anchor(comment)
|
||||||
Rails.application.routes.url_helpers.card_path(
|
Rails.application.routes.url_helpers.card_url(
|
||||||
comment.card,
|
comment.card,
|
||||||
anchor: ActionView::RecordIdentifier.dom_id(comment),
|
anchor: ActionView::RecordIdentifier.dom_id(comment),
|
||||||
script_name: notification.account.slug
|
**url_options
|
||||||
)
|
)
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class WebPush::Notification
|
class WebPush::Notification
|
||||||
def initialize(title:, body:, path:, badge:, endpoint:, endpoint_ip:, p256dh_key:, auth_key:)
|
def initialize(title:, body:, url:, badge:, endpoint:, endpoint_ip:, p256dh_key:, auth_key:)
|
||||||
@title, @body, @path, @badge = title, body, path, badge
|
@title, @body, @url, @badge = title, body, url, badge
|
||||||
@endpoint, @endpoint_ip, @p256dh_key, @auth_key = endpoint, endpoint_ip, p256dh_key, auth_key
|
@endpoint, @endpoint_ip, @p256dh_key, @auth_key = endpoint, endpoint_ip, p256dh_key, auth_key
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ class WebPush::Notification
|
|||||||
end
|
end
|
||||||
|
|
||||||
def encoded_message
|
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
|
end
|
||||||
|
|
||||||
def icon_path
|
def icon_path
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ module NotificationPusher::Native
|
|||||||
.with_data(
|
.with_data(
|
||||||
title: payload[:title],
|
title: payload[:title],
|
||||||
body: payload[:body],
|
body: payload[:body],
|
||||||
path: payload[:path],
|
url: payload[:url],
|
||||||
account_id: notification.account.external_account_id,
|
account_id: notification.account.external_account_id,
|
||||||
avatar_url: creator_avatar_url,
|
avatar_url: creator_avatar_url,
|
||||||
card_id: card&.id,
|
card_id: card&.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user