about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorSorin Davidoi <sorin.davidoi@gmail.com>2017-07-19 22:37:52 +0200
committerEugen Rochko <eugen@zeonfederated.com>2017-07-19 22:37:52 +0200
commitdcb94971484c46e470b89032f174267ace86be5c (patch)
tree31e7c7cf56e540edc6963e8147a5a291be947324 /app/services
parent4f2513337f77a9f05883b82e5b6a6e3a0dc10b14 (diff)
fix(push_subscription): Guard against malformed favourite notification (#4271)
Diffstat (limited to 'app/services')
-rw-r--r--app/services/notify_service.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/app/services/notify_service.rb b/app/services/notify_service.rb
index c7d8ad50a..a44df5180 100644
--- a/app/services/notify_service.rb
+++ b/app/services/notify_service.rb
@@ -65,7 +65,12 @@ class NotifyService < BaseService
   end
 
   def send_push_notifications
-    sessions_with_subscriptions_ids = @recipient.user.session_activations.where.not(web_push_subscription: nil).pluck(:id)
+    # HACK: Can be caused by quickly unfavouriting a status, since creating
+    # a favourite and creating a notification are not wrapped in a transaction.
+    return if @notification.activity.nil?
+
+    sessions_with_subscriptions = @recipient.user.session_activations.where.not(web_push_subscription: nil)
+    sessions_with_subscriptions_ids = sessions_with_subscriptions.select { |session| session.web_push_subscription.pushable? @notification }.map(&:id)
 
     WebPushNotificationWorker.push_bulk(sessions_with_subscriptions_ids) do |session_activation_id|
       [session_activation_id, @notification.id]