Fix notifications not working for some users

This commit is contained in:
redfast00 2019-08-04 20:30:45 +02:00
parent 942d23c040
commit 4935be532d
No known key found for this signature in database
GPG Key ID: 5946E0E34FD0553C
1 changed files with 19 additions and 14 deletions

View File

@ -25,21 +25,26 @@ class Notification < ActiveRecord::Base
end end
def send_gcm_notification def send_gcm_notification
if !Rpush::Gcm::App.find_by_name("tappb") if !read
app = Rpush::Gcm::App.new begin
app.name = "tappb" if !Rpush::Gcm::App.find_by_name("tappb")
app.auth_key = Rails.application.secrets.fcm_secret app = Rpush::Gcm::App.new
app.connections = 1 app.name = "tappb"
app.save! app.auth_key = Rails.application.secrets.fcm_secret
end app.connections = 1
app.save!
end
n = Rpush::Gcm::Notification.new n = Rpush::Gcm::Notification.new
n.app = Rpush::Gcm::App.find_by_name("tappb") n.app = Rpush::Gcm::App.find_by_name("tappb")
n.registration_ids = user.android_device_registration_tokens.all.map{|r| r.token} n.registration_ids = user.android_device_registration_tokens.all.map{|r| r.token}
n.data = { body: message, title: "Tabbp notification" } n.data = { body: message, title: "Tabbp notification" }
n.priority = 'high' n.priority = 'high'
n.content_available = true n.content_available = true
n.save! n.save!
rescue
end
end
end end