From 4935be532dc7e7ec286ae6db5ddf4cb29582e1e2 Mon Sep 17 00:00:00 2001 From: redfast00 Date: Sun, 4 Aug 2019 20:30:45 +0200 Subject: [PATCH] Fix notifications not working for some users --- app/models/notification.rb | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index 8443e62..3ceeab2 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -25,21 +25,26 @@ class Notification < ActiveRecord::Base end def send_gcm_notification - if !Rpush::Gcm::App.find_by_name("tappb") - app = Rpush::Gcm::App.new - app.name = "tappb" - app.auth_key = Rails.application.secrets.fcm_secret - app.connections = 1 - app.save! - end + if !read + begin + if !Rpush::Gcm::App.find_by_name("tappb") + app = Rpush::Gcm::App.new + app.name = "tappb" + app.auth_key = Rails.application.secrets.fcm_secret + app.connections = 1 + app.save! + end - n = Rpush::Gcm::Notification.new - n.app = Rpush::Gcm::App.find_by_name("tappb") - n.registration_ids = user.android_device_registration_tokens.all.map{|r| r.token} - n.data = { body: message, title: "Tabbp notification" } - n.priority = 'high' - n.content_available = true - n.save! + n = Rpush::Gcm::Notification.new + n.app = Rpush::Gcm::App.find_by_name("tappb") + n.registration_ids = user.android_device_registration_tokens.all.map{|r| r.token} + n.data = { body: message, title: "Tabbp notification" } + n.priority = 'high' + n.content_available = true + n.save! + rescue + end + end end