mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 05:33:47 +08:00
18 lines
657 B
Ruby
18 lines
657 B
Ruby
require_dependency 'webpush'
|
|
|
|
if SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_private_key.blank? || SiteSetting.vapid_public_key_bytes.blank?
|
|
vapid_key = Webpush.generate_key
|
|
SiteSetting.vapid_public_key = vapid_key.public_key
|
|
SiteSetting.vapid_private_key = vapid_key.private_key
|
|
end
|
|
|
|
SiteSetting.vapid_public_key_bytes = Base64.urlsafe_decode64(SiteSetting.vapid_public_key).bytes.join("|")
|
|
|
|
DiscourseEvent.on(:post_notification_alert) do |user, payload|
|
|
Jobs.enqueue(:send_push_notification, user_id: user.id, payload: payload)
|
|
end
|
|
|
|
DiscourseEvent.on(:user_logged_out) do |user|
|
|
PushNotificationPusher.clear_subscriptions(user)
|
|
end
|