From 920ba5fc4e705ea9418d2cab12e4d2ffd53775de Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 5 Feb 2017 19:18:11 +0100 Subject: Fix #61 - Add list of blocked users to the UI; clean up failed push notifications API Try to fix Travis CI setup --- app/services/send_push_notification_service.rb | 28 -------------------------- 1 file changed, 28 deletions(-) delete mode 100644 app/services/send_push_notification_service.rb (limited to 'app/services/send_push_notification_service.rb') diff --git a/app/services/send_push_notification_service.rb b/app/services/send_push_notification_service.rb deleted file mode 100644 index 526ae20cb..000000000 --- a/app/services/send_push_notification_service.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -class SendPushNotificationService < BaseService - def call(notification) - return if ENV['FCM_API_KEY'].blank? - - devices = Device.where(account: notification.account).pluck(:registration_id) - fcm = FCM.new(ENV['FCM_API_KEY']) - - response = fcm.send(devices, data: { notification_id: notification.id }, collapse_key: :notifications, priority: :high) - handle_response(response) - end - - private - - def handle_response(response) - update_canonical_ids(response[:canonical_ids]) if response[:canonical_ids] - remove_bad_ids(response[:not_registered_ids]) if response[:not_registered_ids] - end - - def update_canonical_ids(ids) - ids.each { |pair| Device.find_by(registration_id: pair[:old]).update(registration_id: pair[:new]) } - end - - def remove_bad_ids(bad_ids) - Device.where(registration_id: bad_ids).delete_all unless bad_ids.empty? - end -end -- cgit