2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-06-13 10:58:27 +08:00
|
|
|
return if GlobalSetting.skip_db?
|
|
|
|
|
2018-05-05 06:31:48 +08:00
|
|
|
require_dependency 'webpush'
|
|
|
|
|
2018-05-08 08:00:40 +08:00
|
|
|
if SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_private_key.blank? || SiteSetting.vapid_public_key_bytes.blank?
|
2018-05-05 06:31:48 +08:00
|
|
|
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(:user_logged_out) do |user|
|
|
|
|
PushNotificationPusher.clear_subscriptions(user)
|
|
|
|
end
|