|
|
@ -2,13 +2,13 @@ |
|
|
|
|
|
|
|
|
|
|
|
class SendPushNotificationService < BaseService |
|
|
|
class SendPushNotificationService < BaseService |
|
|
|
def call(notification) |
|
|
|
def call(notification) |
|
|
|
return if ENV['FCM_API_KEY'].blank? |
|
|
|
return if ENV['FCM_API_KEY'].blank? |
|
|
|
|
|
|
|
|
|
|
|
devices = Device.where(account: notification.account).pluck(:registration_id) |
|
|
|
devices = Device.where(account: notification.account).pluck(:registration_id) |
|
|
|
fcm = FCM.new(ENV['FCM_API_KEY']) |
|
|
|
fcm = FCM.new(ENV['FCM_API_KEY']) |
|
|
|
|
|
|
|
|
|
|
|
response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) |
|
|
|
response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) |
|
|
|
handle_response(response) |
|
|
|
handle_response(response) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
@ -19,10 +19,10 @@ class SendPushNotificationService < BaseService |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def update_canonical_ids(ids) |
|
|
|
def update_canonical_ids(ids) |
|
|
|
ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } |
|
|
|
ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def remove_bad_ids(bad_ids) |
|
|
|
def remove_bad_ids(bad_ids) |
|
|
|
Device.where(registration_id: bad_ids).delete_all |
|
|
|
Device.where(registration_id: bad_ids).delete_all unless bad_ids.empty? |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|