|
|
@ -26,8 +26,6 @@ class Web::PushSubscription < ApplicationRecord |
|
|
|
before_create :send_welcome_notification |
|
|
|
before_create :send_welcome_notification |
|
|
|
|
|
|
|
|
|
|
|
def push(notification) |
|
|
|
def push(notification) |
|
|
|
return unless pushable? notification |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
name = display_name notification.from_account |
|
|
|
name = display_name notification.from_account |
|
|
|
title = title_str(name, notification) |
|
|
|
title = title_str(name, notification) |
|
|
|
body = body_str notification |
|
|
|
body = body_str notification |
|
|
@ -69,6 +67,10 @@ class Web::PushSubscription < ApplicationRecord |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pushable?(notification) |
|
|
|
|
|
|
|
data && data.key?('alerts') && data['alerts'][notification.type.to_s] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def as_payload |
|
|
|
def as_payload |
|
|
|
payload = { |
|
|
|
payload = { |
|
|
|
id: id, |
|
|
|
id: id, |
|
|
@ -148,10 +150,6 @@ class Web::PushSubscription < ApplicationRecord |
|
|
|
rtl?(body) ? 'rtl' : 'ltr' |
|
|
|
rtl?(body) ? 'rtl' : 'ltr' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def pushable?(notification) |
|
|
|
|
|
|
|
data && data.key?('alerts') && data['alerts'][notification.type.to_s] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def send_welcome_notification |
|
|
|
def send_welcome_notification |
|
|
|
Webpush.payload_send( |
|
|
|
Webpush.payload_send( |
|
|
|
message: JSON.generate( |
|
|
|
message: JSON.generate( |
|
|
|