diff --git a/app/services/post_alerter.rb b/app/services/post_alerter.rb index d5539e34c6f..240d817c590 100644 --- a/app/services/post_alerter.rb +++ b/app/services/post_alerter.rb @@ -415,6 +415,10 @@ class PostAlerter end def push_notification(user, payload) + if user.push_subscriptions.exists? + Jobs.enqueue(:send_push_notification, user_id: user.id, payload: payload) + end + if SiteSetting.allow_user_api_key_scopes.split("|").include?("push") && SiteSetting.allowed_user_api_push_urls.present? clients = user.user_api_keys .where("('push' = ANY(scopes) OR 'notifications' = ANY(scopes)) AND push_url IS NOT NULL AND position(push_url in ?) > 0 AND revoked_at IS NULL", diff --git a/config/initializers/100-push-notifications.rb b/config/initializers/100-push-notifications.rb index 8cb0542cab8..50f580c3883 100644 --- a/config/initializers/100-push-notifications.rb +++ b/config/initializers/100-push-notifications.rb @@ -8,10 +8,6 @@ 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