FCM could return canonical_ids with a successful response. This means rescue_from ... wouldn't be helpful when having to capture them and update registration tokens. User should be able to update registration tokens using an observer:
# app/observers/fcm_token_handler.rb
class FcmTokenHandler
# Using an instance method allows for injecting dependencies if needed later.
def delivered_notification(payload, fcm_response)
# Make sure the response ojbect contains `canonical_ids`
return if !fcm_response.respond_to?(:json)
canonical_ids = fcm_response.json[:canonical_ids] || []
canonical_ids.each do |canonical_id|
# Update registration tokens accordingly
end
end
end
# app/notifiers/application_notifier.rb
class ApplicationNotifier < Fourseam::Base
register_observer FcmTokenHandler.new
...
end
FCM could return
canonical_ids
with a successful response. This meansrescue_from ...
wouldn't be helpful when having to capture them and update registration tokens. User should be able to update registration tokens using an observer: